From 1c0104e584ed60d221413462342c4ecd5cc3bc71 Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Tue, 7 Apr 2026 18:16:49 +0900 Subject: [PATCH 1/2] Allow configuring the library name to be loaded in swift-java.config --- Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift | 2 +- .../JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift | 4 ++-- Sources/SwiftJavaConfigurationShared/Configuration.swift | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift b/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift index 6f5f1b8c..41c06304 100644 --- a/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift +++ b/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift @@ -505,7 +505,7 @@ extension FFMSwift2JavaGenerator { func printClassConstants(printer: inout CodePrinter) { printer.print( """ - static final String LIB_NAME = "\(swiftModuleName)"; + static final String LIB_NAME = "\(config.nativeLibraryName ?? swiftModuleName)"; static final Arena LIBRARY_ARENA = Arena.ofAuto(); """ ) diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift index 8f6d97a6..e6b3c71b 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift @@ -100,7 +100,7 @@ extension JNISwift2JavaGenerator { printModuleClass(&printer) { printer in printer.print( """ - static final String LIB_NAME = "\(swiftModuleName)"; + static final String LIB_NAME = "\(config.nativeLibraryName ?? swiftModuleName)"; static { System.loadLibrary(SwiftLibraries.LIB_NAME_SWIFT_JAVA); @@ -189,7 +189,7 @@ extension JNISwift2JavaGenerator { printNominal(&printer, decl) { printer in printer.print( """ - static final String LIB_NAME = "\(swiftModuleName)"; + static final String LIB_NAME = "\(config.nativeLibraryName ?? swiftModuleName)"; @SuppressWarnings("unused") private static final boolean INITIALIZED_LIBS = initializeLibs(); diff --git a/Sources/SwiftJavaConfigurationShared/Configuration.swift b/Sources/SwiftJavaConfigurationShared/Configuration.swift index 502996c4..fafb4c4f 100644 --- a/Sources/SwiftJavaConfigurationShared/Configuration.swift +++ b/Sources/SwiftJavaConfigurationShared/Configuration.swift @@ -32,6 +32,12 @@ public struct Configuration: Codable { public var swiftModule: String? + /// The name of the native library to load at runtime via `System.loadLibrary()`. + /// Defaults to the Swift module name when not set. Use this when the dynamic + /// library product has a different name than the module being exported + /// (e.g. the module is `MyLibrary` bht the dylib is `MyLibrarySwiftJava` or something else). + public var nativeLibraryName: String? + public var inputSwiftDirectory: String? public var outputSwiftDirectory: String? From 579a2325f5a95aad94ac4308909bdde28c033ff1 Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Tue, 7 Apr 2026 19:00:45 +0900 Subject: [PATCH 2/2] typo fix --- Sources/SwiftJavaConfigurationShared/Configuration.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftJavaConfigurationShared/Configuration.swift b/Sources/SwiftJavaConfigurationShared/Configuration.swift index fafb4c4f..bd67665f 100644 --- a/Sources/SwiftJavaConfigurationShared/Configuration.swift +++ b/Sources/SwiftJavaConfigurationShared/Configuration.swift @@ -35,7 +35,7 @@ public struct Configuration: Codable { /// The name of the native library to load at runtime via `System.loadLibrary()`. /// Defaults to the Swift module name when not set. Use this when the dynamic /// library product has a different name than the module being exported - /// (e.g. the module is `MyLibrary` bht the dylib is `MyLibrarySwiftJava` or something else). + /// (e.g. the module is `MyLibrary` but the dylib is `MyLibrarySwiftJava` or something else). public var nativeLibraryName: String? public var inputSwiftDirectory: String?