Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SwiftLibraries load was "overdoing it" a bit.

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,35 @@

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.
* <p/>
* 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;
}

// ==== ------------------------------------------------------------------------------------------------------------
// 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) {
Expand Down
Loading