Skip to content

Introduce subcommand for jextract to prevent linking Foundation#624

Merged
ktoso merged 8 commits intoswiftlang:mainfrom
madsodgaard:jextract-no-foundation
Mar 17, 2026
Merged

Introduce subcommand for jextract to prevent linking Foundation#624
ktoso merged 8 commits intoswiftlang:mainfrom
madsodgaard:jextract-no-foundation

Conversation

@madsodgaard
Copy link
Contributor

Resolves #619

Specifying any non Swift files as build plugin outputs, will make SPM generate a bundle accessor file which imports Foundation unconditionally.

To solve this, we introduce a new subcommand that handles the callback part of the JExtract build plugin.

@madsodgaard madsodgaard requested a review from ktoso as a code owner March 16, 2026 09:08
// inputFiles includes the Swift outputs from jextract so that SPM knows
// this command must run after jextract finishes.
var javaCallbacksArguments = [
"java-callbacks-build",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we HAVE to do it all int one huge mega step? Can we not invoke multiple commands one by one? I'd like to make this hidden in command line somehow...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, what would we benefit from writing multiple commands? As this is only intended for internal use and a workaround for the SwiftPM limitation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant finding some way to keep the previous workflow going rather than introducing this command

@preconcurrency import SystemPackage
#endif

/// Builds Swift-Java callbacks in a single command:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Put a huge WORKAROUND: rdar://172649681 if we invoke commands one by one with java outputs SwiftPM will link Foundation here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, would be good if you filed an issue on swiftpm explaining this behavior, might be better to track that way coming from you directly as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Can you please construct a Linkage test that would show this problem? I'd like to not regress on it by accident

/// Gradle output directories) as module resources, which would trigger
/// resource_bundle_accessor.swift generation and pull Foundation.Bundle into the binary.
extension SwiftJava {
struct JavaCallbacksBuildCommand: AsyncParsableCommand {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Man I really dislike this command... we'll have to copy around and keep it updated constantly :-\

Before we merge this, can we make sure we can't avoid it? How about just ignoring the java outputs, does swiftpm prevent things from working if we just pretend they don't exist but we write them anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is I am guessing that SwiftPM uses the input/output to derive the dependencies between the build commands. So, I am afraid that it will run the builds in the wrong order.

Alternatively, if its only using it for stale checks, that means that if we remove them from the outputs, we would retrigger those commands on each invocation of the build plugin. Maybe someone from the SwiftPM team can confirm the behaviour here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dschaefer2 would you mind confirming we have no other way out here?

@ktoso ktoso merged commit 5458246 into swiftlang:main Mar 17, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding JExtractSwiftPlugin links Full Foundation

2 participants