diff --git a/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift b/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift index c66b0029..9c9154a4 100644 --- a/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift +++ b/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift @@ -194,8 +194,8 @@ extension FFMSwift2JavaGenerator { @SuppressWarnings("unused") private static final boolean INITIALIZED_LIBS = initializeLibs(); static boolean initializeLibs() { - System.loadLibrary(SwiftLibraries.STDLIB_DYLIB_NAME); - System.loadLibrary("SwiftKitSwift"); + System.loadLibrary(SwiftLibraries.LIB_NAME_SWIFT_CORE); + System.loadLibrary(SwiftLibraries.LIB_NAME_SWIFTKITSWIFT); System.loadLibrary(LIB_NAME); return true; } @@ -343,10 +343,11 @@ extension FFMSwift2JavaGenerator { """ static final SymbolLookup SYMBOL_LOOKUP = getSymbolLookup(); private static SymbolLookup getSymbolLookup() { - // Ensure Swift and our Lib are loaded during static initialization of the class. - SwiftLibraries.loadLibrary("swiftCore"); - SwiftLibraries.loadLibrary("SwiftKitSwift"); - SwiftLibraries.loadLibrary(LIB_NAME); + if (SwiftLibraries.AUTO_LOAD_LIBS) { + System.loadLibrary(SwiftLibraries.LIB_NAME_SWIFT_CORE); + System.loadLibrary(SwiftLibraries.LIB_NAME_SWIFTKITSWIFT); + System.loadLibrary(LIB_NAME); + } if (PlatformUtils.isMacOS()) { return SymbolLookup.libraryLookup(System.mapLibraryName(LIB_NAME), LIBRARY_ARENA) diff --git a/SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftLibraries.java b/SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftLibraries.java index 3230e52a..a093cc50 100644 --- a/SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftLibraries.java +++ b/SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftLibraries.java @@ -24,18 +24,28 @@ public final class SwiftLibraries { - public static final String STDLIB_DYLIB_NAME = "swiftCore"; - public static final String SWIFTKITSWIFT_DYLIB_NAME = "SwiftKitSwift"; + // Library names of core Swift and SwiftKit + public static final String LIB_NAME_SWIFT_CORE = "swiftCore"; + public static final String LIB_NAME_SWIFT_CONCURRENCY = "swift_Concurrency"; + public static final String LIB_NAME_SWIFTKITSWIFT = "SwiftKitSwift"; - private static final String STDLIB_MACOS_DYLIB_PATH = "/usr/lib/swift/libswiftCore.dylib"; + /** + * Allows for configuration if jextracted types should automatically attempt to load swiftCore and the library type is from. + *

+ * If all libraries you need to load are available in paths passed to {@code -Djava.library.path} this should work correctly, + * however if attempting to load libraries from e.g. the jar as a resource, you may want to disable this. + */ + public static final boolean AUTO_LOAD_LIBS = System.getProperty("swift-java.auto-load-libraries") == null ? + true + : Boolean.getBoolean("swiftkit.auto-load-libraries"); @SuppressWarnings("unused") private static final boolean INITIALIZED_LIBS = loadLibraries(false); public static boolean loadLibraries(boolean loadSwiftKit) { - System.loadLibrary(STDLIB_DYLIB_NAME); + System.loadLibrary(LIB_NAME_SWIFTKITSWIFT); if (loadSwiftKit) { - System.loadLibrary(SWIFTKITSWIFT_DYLIB_NAME); + System.loadLibrary(LIB_NAME_SWIFTKITSWIFT); } return true; } @@ -43,17 +53,6 @@ public static boolean loadLibraries(boolean loadSwiftKit) { // ==== ------------------------------------------------------------------------------------------------------------ // Loading libraries - public static void loadLibrary(String libname) { - // TODO: avoid concurrent loadResource calls; one load is enough esp since we cause File IO when we do that - try { - // try to load a dylib from our classpath, e.g. when we included it in our jar - loadResourceLibrary(libname); - } catch (UnsatisfiedLinkError | RuntimeException e) { - // fallback to plain system path loading - System.loadLibrary(libname); - } - } - public static void loadResourceLibrary(String libname) { String resourceName = PlatformUtils.dynamicLibraryName(libname); if (CallTraces.TRACE_DOWNCALLS) {