2
0

Archive and initial cross-compile support.

This commit is contained in:
Maarten Billemont 2018-05-26 01:22:41 -04:00
parent 3b24e1d1b8
commit 0b044ab9a4
2 changed files with 54 additions and 17 deletions

View File

@ -3,29 +3,49 @@ import org.gradle.internal.jvm.Jvm
plugins { plugins {
id 'cpp-library' id 'cpp-library'
id 'xcode' id 'base'
id 'visual-studio'
} }
description = 'Master Password Algorithm Implementation' description = 'Master Password Algorithm Implementation'
task archive( type: Zip ) {
dependsOn assemble
components.withType( ComponentWithRuntimeFile ) {
if (isOptimized()) {
from getRuntimeFile()
into standardOperatingSystem( linkTask.get().targetPlatform.get() ) + '/' +
standardArchitecture( linkTask.get().targetPlatform.get() )
}
}
}
library { library {
linkage.set( [Linkage.STATIC, Linkage.SHARED] ) linkage.set( [Linkage.STATIC, Linkage.SHARED] )
binaries.configureEach {
// Reconfigure the toolchain from C++ to C. // Reconfigure the toolchain from C++ to C.
compileTask.get().source.setFrom( fileTree( dir: "src", include: "**/*.c" ) ) toolChains {
if (toolChain instanceof VisualCpp) { withType( GccCompatibleToolChain ) {
compileTask.get().compilerArgs = ["/TC"] //TODO: Cross-compiling, blocked by: https://github.com/gradle/gradle-native/issues/169
} else if (toolChain instanceof GccCompatibleToolChain) { //setTargets( "arm", "arm64", "x86-64", "x86" )
compileTask.get().compilerArgs = ["-x", "c", "-std=c11"] eachPlatform {
//linkTask.get().linkerArgs = ["-nodefaultlibs", "-lc"] cppCompiler.withArguments { addAll( ["-x", "c", "-std=c11", "-DMPW_SODIUM=1"] ) }
}
}
}
components.withType( CppComponent ) {
// Reconfigure the toolchain from C++ to C.
cppSource.from fileTree( dir: "src", include: "**/*.c" )
} }
// Resolve our standard naming for OS platforms. // Cross-compile for these host platforms.
def platform = System.getProperty( "os.name" ).toLowerCase( Locale.ROOT ) operatingSystems.set( [objects.named( OperatingSystemFamily, OperatingSystemFamily.WINDOWS ),
if (platform.startsWith( "mac" )) objects.named( OperatingSystemFamily, OperatingSystemFamily.LINUX ),
platform = "macos" objects.named( OperatingSystemFamily, OperatingSystemFamily.MAC_OS )] )
binaries.configureEach {
// Resolve a standard name for the platform.
def platform = standardOperatingSystem( targetPlatform )
project.dependencies { project.dependencies {
// Depend on JDK for JNI support. // Depend on JDK for JNI support.
@ -38,7 +58,23 @@ library {
add( linkLibraries.name, add( linkLibraries.name,
fileTree( "../../lib/libsodium/build-${platform}~/out/lib" ) ) fileTree( "../../lib/libsodium/build-${platform}~/out/lib" ) )
} }
compileTask.get().compilerArgs.add "-DMPW_SODIUM=1"
} }
} }
static String standardOperatingSystem(NativePlatform platform) {
OperatingSystem os = platform.getOperatingSystem()
if (os.isWindows()) {
return OperatingSystemFamily.WINDOWS
} else if (os.isLinux()) {
return OperatingSystemFamily.LINUX
} else if (os.isMacOsX()) {
return OperatingSystemFamily.MAC_OS
}
return os.name.toLowerCase()
}
static String standardArchitecture(NativePlatform platform) {
Architecture arch = platform.getArchitecture()
return arch.name.toLowerCase().replaceAll( "-", "_" )
}

View File

@ -16,7 +16,8 @@ dependencies {
api group: 'org.jetbrains', name: 'annotations', version: '13.0' api group: 'org.jetbrains', name: 'annotations', version: '13.0'
api group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' api group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
resource project( path: ':masterpassword-core', configuration: 'releaseSharedRuntimeElements' ) // TODO: pending cross-compilation support
//resource project( path: ':masterpassword-core', configuration: 'releaseSharedRuntimeElements' )
} }
jar { jar {