|
24 | 24 |
|
25 | 25 | public final class SwiftLibraries {
|
26 | 26 |
|
27 |
| - public static final String STDLIB_DYLIB_NAME = "swiftCore"; |
28 |
| - public static final String SWIFTKITSWIFT_DYLIB_NAME = "SwiftKitSwift"; |
| 27 | + // Library names of core Swift and SwiftKit |
| 28 | + public static final String LIB_NAME_SWIFT_CORE = "swiftCore"; |
| 29 | + public static final String LIB_NAME_SWIFT_CONCURRENCY = "swift_Concurrency"; |
| 30 | + public static final String LIB_NAME_SWIFTKITSWIFT = "SwiftKitSwift"; |
29 | 31 |
|
30 |
| - private static final String STDLIB_MACOS_DYLIB_PATH = "/usr/lib/swift/libswiftCore.dylib"; |
| 32 | + /** |
| 33 | + * Allows for configuration if jextracted types should automatically attempt to load swiftCore and the library type is from. |
| 34 | + * <p/> |
| 35 | + * If all libraries you need to load are available in paths passed to {@code -Djava.library.path} this should work correctly, |
| 36 | + * however if attempting to load libraries from e.g. the jar as a resource, you may want to disable this. |
| 37 | + */ |
| 38 | + public static final boolean AUTO_LOAD_LIBS = System.getProperty("swift-java.auto-load-libraries") == null ? |
| 39 | + true |
| 40 | + : Boolean.getBoolean("swiftkit.auto-load-libraries"); |
31 | 41 |
|
32 | 42 | @SuppressWarnings("unused")
|
33 | 43 | private static final boolean INITIALIZED_LIBS = loadLibraries(false);
|
34 | 44 |
|
35 | 45 | public static boolean loadLibraries(boolean loadSwiftKit) {
|
36 |
| - System.loadLibrary(STDLIB_DYLIB_NAME); |
| 46 | + System.loadLibrary(LIB_NAME_SWIFTKITSWIFT); |
37 | 47 | if (loadSwiftKit) {
|
38 |
| - System.loadLibrary(SWIFTKITSWIFT_DYLIB_NAME); |
| 48 | + System.loadLibrary(LIB_NAME_SWIFTKITSWIFT); |
39 | 49 | }
|
40 | 50 | return true;
|
41 | 51 | }
|
42 | 52 |
|
43 | 53 | // ==== ------------------------------------------------------------------------------------------------------------
|
44 | 54 | // Loading libraries
|
45 | 55 |
|
46 |
| - public static void loadLibrary(String libname) { |
47 |
| - // TODO: avoid concurrent loadResource calls; one load is enough esp since we cause File IO when we do that |
48 |
| - try { |
49 |
| - // try to load a dylib from our classpath, e.g. when we included it in our jar |
50 |
| - loadResourceLibrary(libname); |
51 |
| - } catch (UnsatisfiedLinkError | RuntimeException e) { |
52 |
| - // fallback to plain system path loading |
53 |
| - System.loadLibrary(libname); |
54 |
| - } |
55 |
| - } |
56 |
| - |
57 | 56 | public static void loadResourceLibrary(String libname) {
|
58 | 57 | String resourceName = PlatformUtils.dynamicLibraryName(libname);
|
59 | 58 | if (CallTraces.TRACE_DOWNCALLS) {
|
|
0 commit comments