2
0

Linux build fixes.

This commit is contained in:
Maarten Billemont 2019-09-25 15:27:04 -04:00
parent bf5e30c2c7
commit 87913326a5
4 changed files with 38 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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 ) );
}