swiftlang / swiftlang/swift-java

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

Open
#521 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
1.2k
Forks
123
Avg merge
1d 7h
Merged PRs (30d)
16

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or code-generation entry points are named. Locate where SwiftPM library products become the generated Java LIB_NAME and compare the product name with the module name; done means the generated System.loadLibrary call uses the correct library name or reports unsupported mismatches clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.