diff --git a/platform-independent/c/core/Dockerfile.x86 b/platform-independent/c/core/Dockerfile.x86 new file mode 100644 index 00000000..c07c9c30 --- /dev/null +++ b/platform-independent/c/core/Dockerfile.x86 @@ -0,0 +1,9 @@ +FROM i386/debian:stable-slim +ENTRYPOINT ["linux32", "--"] + +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199 +RUN mkdir -p /usr/share/man/man1 + +RUN apt-get update && apt-get install -y default-jdk-headless git-core bash libtool automake autoconf make g++ +RUN git clone --depth=3 $(: --shallow-submodules) --recurse-submodules --branch rewrite https://gitlab.com/MasterPassword/MasterPassword.git /mpw +RUN cd /mpw && git log -1 && ./gradlew -i clean build diff --git a/Dockerfile b/platform-independent/c/core/Dockerfile.x86_64 similarity index 61% rename from Dockerfile rename to platform-independent/c/core/Dockerfile.x86_64 index 89bb6a0c..31ec5f6e 100644 --- a/Dockerfile +++ b/platform-independent/c/core/Dockerfile.x86_64 @@ -1,12 +1,8 @@ FROM debian:stable-slim -# For i386 -#FROM i386/debian:stable-slim -#ENTRYPOINT ["linux32", "--"] - # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199 RUN mkdir -p /usr/share/man/man1 RUN apt-get update && apt-get install -y default-jdk-headless git-core bash libtool automake autoconf make g++ -RUN git clone --depth=3 $(: --shallow-submodules) --recurse-submodules https://gitlab.com/MasterPassword/MasterPassword.git /mpw -RUN cd /mpw/gradle && ./gradlew -i clean build +RUN git clone --depth=3 $(: --shallow-submodules) --recurse-submodules --branch rewrite https://gitlab.com/MasterPassword/MasterPassword.git /mpw +RUN cd /mpw && git log -1 && ./gradlew -i clean build diff --git a/platform-independent/c/core/build.gradle b/platform-independent/c/core/build.gradle index 99dc6ed5..4dd47136 100644 --- a/platform-independent/c/core/build.gradle +++ b/platform-independent/c/core/build.gradle @@ -25,37 +25,36 @@ artifacts { library { baseName.set( 'mpw' ) linkage.set( [Linkage.SHARED] ) - source.from fileTree( 'src' ) + source.from files( 'src' ) - // Reconfigure the toolchain from C++ to C. - toolChains { - withType( VisualCpp ) { - eachPlatform { - cppCompiler.withArguments { addAll( ['/TC', '/MT', '/Ox', '/DMPW_SODIUM=1', '/DSODIUM_STATIC', '/DSODIUM_EXPORT=', '/DMPW_LOG=mpw_log_app'] ) } - } - } - withType( GccCompatibleToolChain ) { - eachPlatform { - cppCompiler.withArguments { addAll( ['-x', 'c', '-O3', '-Werror', '-DMPW_SODIUM=1', '-DMPW_LOG=mpw_log_app'] ) } - } - } - } + // JDK for JNI support. + privateHeaders.from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } } - // Cross-compile for these host platforms. - // TODO: Cross-compiling, blocked by: https://github.com/gradle/gradle-native/issues/169 - CppLibraryPlugin.java:163 -// operatingSystems.set( [objects.named( OperatingSystemFamily, OperatingSystemFamily.LINUX ), -// objects.named( OperatingSystemFamily, OperatingSystemFamily.MAC_OS ), -// objects.named( OperatingSystemFamily, OperatingSystemFamily.WINDOWS )] ) + // Cross-compile for these target platforms. + // TODO: Cross-compiling, blocked by: https://github.com/gradle/gradle-native/issues/1031 targetMachines.set( [ - machines.linux.x86_64, + machines.linux.x86, machines.linux.x86_64, machines.windows.x86, machines.windows.x86_64, machines.macOS.x86_64 ] ) - components.withType( CppComponent ) { - // JDK for JNI support. - privateHeaders.from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } } + tasks.withType(CppCompile).configureEach { + // Define a preprocessor macro for every binary + macros.put("MPW_SODIUM", "1") + macros.put("MPW_LOG", "mpw_log_app") + // Reconfigure the toolchain from C++ to C. + compilerArgs.addAll toolChain.map { toolChain -> + if (toolChain in GccCompatibleToolChain) { + return ['-x', 'c', '-O3', '-Werror'] + } else if (toolChain in VisualCpp) { + return ['/TC', '/MT', '/Ox', '/DSODIUM_STATIC', '/DSODIUM_EXPORT='] + } + return [] + } + } + + components.withType( CppComponent ) { binaries.whenElementFinalized { project.dependencies { def system = targetMachine.getOperatingSystemFamily().getName() diff --git a/platform-independent/c/core/src/mpw-jni.c b/platform-independent/c/core/src/mpw-jni.c index 0f9e28e6..f3a6798d 100644 --- a/platform-independent/c/core/src/mpw-jni.c +++ b/platform-independent/c/core/src/mpw-jni.c @@ -29,10 +29,11 @@ void mpw_log_app(LogLevel level, const char *format, ...) { else if (level <= LogLevelError) method = (*env)->GetMethodID( env, class, "error", "(Ljava/lang/String;)V" ); - char *message = NULL; - int length = vasprintf( &message, format, args ); - if (message) { - (*env)->CallVoidMethod( env, logger, method, (*env)->NewStringUTF( env, message ) ); + int length = vsnprintf( NULL, 0, format, args ); + if (length > 0) { + char *message = malloc( length + 1 ); + if (message && (length = vsnprintf( message, length, format, args )) > 0); + (*env)->CallVoidMethod( env, logger, method, (*env)->NewStringUTF( env, message ) ); mpw_free( &message, (size_t)max( 0, length ) ); }