⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

System.loadLibrary uses the module name instead of the library (product) name #521

@sidepelican

Description

@sidepelican

The name of the dynamic library (.so file) generated by SwiftPM depends on the name in the .library product.

.library(
    name: "my-module", // This name is used for the file: libmy-module.so
    type: .dynamic,
    targets: ["MyModule"]
)

However, SwiftJava currently uses the module name for System.loadLibrary. In the example above, it tries to load libMyModule.so, which causes an error because the file does not exist.

public final class MySwiftClass implements JNISwiftInstance {
  static final String LIB_NAME = "MyModule"; // Should be "my-module"
  
  static boolean initializeLibs() {
      System.loadLibrary(SwiftLibraries.LIB_NAME_SWIFT_JAVA);
      System.loadLibrary(LIB_NAME); // Error
      return true;
  }
}

Expected Behavior:
I think we should have one of the following:

  1. Use the library (product) name for code generation instead of the module name.
  2. Or, show an error if the library name and module name are different (or if there are multiple modules).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions