Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions native-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.*')
}
Expand Down Expand Up @@ -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.*')
}
Expand Down
Loading