Skip to content

Commit 2700a2e

Browse files
committed
avoid explicitly loading libs; they can be loaded by the generated module
1 parent 8402944 commit 2700a2e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Samples/SwiftKitSampleApp/src/main/java/com/example/swift/HelloJava2Swift.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@ public static void main(String[] args) {
3232
boolean traceDowncalls = Boolean.getBoolean("jextract.trace.downcalls");
3333
System.out.println("Property: jextract.trace.downcalls = " + traceDowncalls);
3434

35-
final var dylibNames = List.of(
36-
"swiftCore",
37-
"ExampleSwiftLibrary"
38-
);
39-
40-
41-
System.out.println("Loading libraries...");
42-
43-
for (var lib : dylibNames) {
44-
System.out.printf("Loading: %s... ", lib);
45-
System.loadLibrary(lib);
46-
System.out.println("ok.");
47-
}
48-
4935
examples();
5036
}
5137

Sources/JExtractSwift/Swift2JavaTranslator+Printing.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ extension Swift2JavaTranslator {
100100
printImports(&printer)
101101

102102
printModuleClass(&printer) { printer in
103+
104+
printStaticLibraryLoad(&printer)
105+
103106
// TODO: print all "static" methods
104107
for decl in importedGlobalFuncs {
105108
printFunctionDowncallMethods(&printer, decl)
@@ -266,7 +269,7 @@ extension Swift2JavaTranslator {
266269
private func printClassConstants(printer: inout CodePrinter) {
267270
printer.print(
268271
"""
269-
static final String DYLIB_NAME = "\(swiftModuleName)";
272+
static final String LIB_NAME = "\(swiftModuleName)";
270273
static final Arena LIBRARY_ARENA = Arena.ofAuto();
271274
"""
272275
)
@@ -458,6 +461,17 @@ extension Swift2JavaTranslator {
458461
)
459462
}
460463

464+
public func printStaticLibraryLoad(_ printer: inout CodePrinter) {
465+
printer.print(
466+
"""
467+
static {
468+
System.loadLibrary("swiftCore");
469+
System.loadLibrary(LIB_NAME);
470+
}
471+
"""
472+
)
473+
}
474+
461475
public func printFunctionDowncallMethods(_ printer: inout CodePrinter, _ decl: ImportedFunc) {
462476
printer.printSeparator(decl.identifier)
463477

0 commit comments

Comments
 (0)