diff --git a/native-lib/build.gradle b/native-lib/build.gradle index 0a448df..d7bbe10 100644 --- a/native-lib/build.gradle +++ b/native-lib/build.gradle @@ -63,10 +63,60 @@ graalvmNative { } } +// On Linux/macOS, create libdwlib.so symlink for standard -ldwlib linking +tasks.named('nativeCompile').configure { + doLast { + if (!System.getProperty('os.name').toLowerCase().contains('windows')) { + def nativeDir = file("${buildDir}/native/nativeCompile") + def dwlibFile = fileTree(nativeDir).matching { include 'dwlib.so', 'dwlib.dylib' }.singleFile + if (dwlibFile?.exists()) { + def ext = dwlibFile.name.endsWith('.dylib') ? '.dylib' : '.so' + def symlinkTarget = new File(nativeDir, "lib${dwlibFile.name}") + if (!symlinkTarget.exists() || symlinkTarget.canonicalFile != dwlibFile.canonicalFile) { + ant.symlink(link: symlinkTarget, resource: dwlibFile.name, overwrite: true) + } + } + } + } +} + +// Strip debug symbols from native library to reduce artifact size (only on CI or when skipStripDebug is not set) +tasks.register('stripNativeLibrary', Exec) { + dependsOn tasks.named('nativeCompile') + + onlyIf { + // Skip stripping if explicitly disabled (for local development with debugging) + project.findProperty('skipStripDebug')?.toString()?.toBoolean() != true + } + + def nativeDir = file("${buildDir}/native/nativeCompile") + + if (System.getProperty('os.name').toLowerCase().contains('windows')) { + // Windows: Use strip from mingw-w64 or MSYS2 if available + workingDir(nativeDir) + commandLine('cmd', '/c', 'where strip >nul 2>&1 && strip --strip-debug dwlib.dll || echo Strip not available on Windows, skipping') + ignoreExitValue = true // Don't fail if strip is not available on Windows + } else if (System.getProperty('os.name').toLowerCase().contains('mac')) { + // macOS: Use strip -S to remove debug symbols + workingDir(nativeDir) + commandLine('strip', '-S', 'dwlib.dylib') + } else { + // Linux: Use strip --strip-debug + workingDir(nativeDir) + commandLine('strip', '--strip-debug', 'dwlib.so') + } + + doLast { + if (executionResult.get().exitValue == 0) { + println("✓ Stripped debug symbols from native library") + } + } +} + def pythonExe = (project.findProperty('pythonExe') ?: 'python3') as String tasks.register('stagePythonNativeLib', Copy) { - dependsOn tasks.named('nativeCompile') + dependsOn tasks.named('stripNativeLibrary') from("${buildDir}/native/nativeCompile") { include('dwlib.*') } @@ -107,7 +157,7 @@ tasks.register('pythonTest', Exec) { // --- Node.js native package tasks --- tasks.register('stageNodeNativeLib', Copy) { - dependsOn tasks.named('nativeCompile') + dependsOn tasks.named('stripNativeLibrary') from("${buildDir}/native/nativeCompile") { include('dwlib.*') }