Skip to content

jextract: Evaluate IfConfigDecl and add --static-build-config option#671

Open
sidepelican wants to merge 13 commits intoswiftlang:mainfrom
sidepelican:syntax603
Open

jextract: Evaluate IfConfigDecl and add --static-build-config option#671
sidepelican wants to merge 13 commits intoswiftlang:mainfrom
sidepelican:syntax603

Conversation

@sidepelican
Copy link
Copy Markdown
Contributor

It seems difficult for the jextract plugin to reliably execute -print-static-build-config.
Instead, this PR embeds a fixed JExtractDefaultBuildConfiguration.

The policy for this fixed configuration is to resolve the widest possible range of #if conditions.

This approach introduces a risk where jextract might generate code for functions that are not actually present in the loaded Swift library, which would result in a runtime error.
However, I believe providing access to these functions by default is more useful than having them be completely unavailable.

To support cases where a specific configuration is required, I have added a --static-build-config <filepath> option to jextract.
This allows users to provide their own generated JSON file to customize the BuildConfiguration.

@sidepelican sidepelican requested a review from ktoso as a code owner April 2, 2026 09:02
expectedChunks: [
"public static void androidFunc()",
"public final class CannotImport",
"public final class IsNotDebug",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice, that's what I would expect here

Copy link
Copy Markdown
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.

Looks great, minor concerns about the big features json... I'd rather we don't have to commit that. We may have to NOT have a .shared at all and just compute this during generation instead

@sidepelican
Copy link
Copy Markdown
Contributor Author

@ktoso The new BuildToolsPlugin now allows running -print-static-build-config during builds.

It uses a global swift command so the results may not always match the exact build-time swift version.

@sidepelican
Copy link
Copy Markdown
Contributor Author

Is the Android CI having some trouble at the moment?
Also, since 6.3 has been officially released, I thought it would be a good idea to add a CI job pinned specifically to 6.3.

@ktoso
Copy link
Copy Markdown
Collaborator

ktoso commented Apr 3, 2026

Yeah we should do a 6.3 job, I'll follow up on it

@madsodgaard
Copy link
Copy Markdown
Contributor

Great addition! Could we perhaps add some docs about this feature?

@ktoso
Copy link
Copy Markdown
Collaborator

ktoso commented Apr 3, 2026

Docs would be good about this, it's worth understanding how this works.

I'm offline this evening already, can merge in the morning

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.

3 participants