-
Notifications
You must be signed in to change notification settings - Fork 100
jextract: Evaluate IfConfigDecl and add --static-build-config option 2 #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f030ef2
Update swift-syntax to 603
sidepelican e118d1b
Add JExtractDefaultBuildConfiguration
sidepelican c475769
Add visiting ifConfigDecl logic
sidepelican dda539a
Add IfConfigTests
sidepelican 4b6e407
swift format
sidepelican 8690e90
Add static build configuration option
sidepelican e3e6f34
Add overrideWithStaticBuildConfigurationFile test case
sidepelican 8d291bd
swift format
sidepelican c0d7758
Update Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift
sidepelican e6fb03a
Move .shared into the type itself
sidepelican b93b3b1
Introduce build tools plugin to capture static build configuration
sidepelican aee4cc7
Skip swiftinterfaceCommonPattern test for old compiler
sidepelican ca64cd9
Fix for swift 6.1
sidepelican 711b13e
Add document for --static-build-config
sidepelican 25c6b41
Merge remote-tracking branch 'origin/main' into syntax603
sidepelican e7203ee
Use module bundle to avoid SwiftPM bug
sidepelican 01bd03e
Avoid license header check
sidepelican File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Plugins/_StaticBuildConfigPlugin/_StaticBuildConfigPlugin.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the Swift.org project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import Foundation | ||
| import PackagePlugin | ||
|
|
||
| @main | ||
| struct _StaticBuildConfigPlugin: BuildToolPlugin { | ||
| func createBuildCommands(context: PluginContext, target: any Target) async throws -> [Command] { | ||
| let executable = try context.tool(named: "StaticBuildConfigPluginExecutable").url | ||
| let out = context.pluginWorkDirectoryURL.appending(path: "static-build-config.json") | ||
| return [ | ||
| .buildCommand( | ||
| displayName: "Run -print-static-build-config", | ||
| executable: executable, | ||
| arguments: [out.path(percentEncoded: false)], | ||
| environment: [:], | ||
| inputFiles: [], | ||
| outputFiles: [out] | ||
| ) | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
Sources/JExtractSwiftLib/JExtractDefaultBuildConfiguration.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the Swift.org project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import Foundation | ||
| import SwiftIfConfig | ||
| import SwiftSyntax | ||
|
|
||
| /// A default, fixed build configuration during static analysis for interface extraction. | ||
| struct JExtractDefaultBuildConfiguration: BuildConfiguration { | ||
| static let shared = JExtractDefaultBuildConfiguration() | ||
|
|
||
| private var base: StaticBuildConfiguration | ||
|
|
||
| init() { | ||
| guard let url = Bundle.module.url(forResource: "static-build-config", withExtension: "json") else { | ||
| fatalError("static-build-config.json is not found in module bundle") | ||
| } | ||
| do { | ||
| let data = try Data(contentsOf: url) | ||
| let decoder = JSONDecoder() | ||
| base = try decoder.decode(StaticBuildConfiguration.self, from: data) | ||
| } catch { | ||
| fatalError("\(error)") | ||
| } | ||
| } | ||
|
|
||
| func isCustomConditionSet(name: String) throws -> Bool { | ||
| base.isCustomConditionSet(name: name) | ||
| } | ||
|
|
||
| func hasFeature(name: String) throws -> Bool { | ||
| base.hasFeature(name: name) | ||
| } | ||
|
|
||
| func hasAttribute(name: String) throws -> Bool { | ||
| base.hasAttribute(name: name) | ||
| } | ||
|
|
||
| func canImport(importPath: [(TokenSyntax, String)], version: CanImportVersion) throws -> Bool { | ||
| try base.canImport(importPath: importPath, version: version) | ||
| } | ||
|
|
||
| func isActiveTargetOS(name: String) throws -> Bool { | ||
| true | ||
| } | ||
|
|
||
| func isActiveTargetArchitecture(name: String) throws -> Bool { | ||
| true | ||
| } | ||
|
|
||
| func isActiveTargetEnvironment(name: String) throws -> Bool { | ||
| true | ||
| } | ||
|
|
||
| func isActiveTargetRuntime(name: String) throws -> Bool { | ||
| true | ||
| } | ||
|
|
||
| func isActiveTargetPointerAuthentication(name: String) throws -> Bool { | ||
| true | ||
| } | ||
|
|
||
| func isActiveTargetObjectFormat(name: String) throws -> Bool { | ||
| true | ||
| } | ||
|
|
||
| var targetPointerBitWidth: Int { | ||
| base.targetPointerBitWidth | ||
| } | ||
|
|
||
| var targetAtomicBitWidths: [Int] { | ||
| base.targetAtomicBitWidths | ||
| } | ||
|
|
||
| var endianness: Endianness { | ||
| base.endianness | ||
| } | ||
|
|
||
| var languageVersion: VersionTuple { | ||
| base.languageVersion | ||
| } | ||
|
|
||
| var compilerVersion: VersionTuple { | ||
| base.compilerVersion | ||
| } | ||
| } | ||
|
|
||
| extension BuildConfiguration where Self == JExtractDefaultBuildConfiguration { | ||
| static var jextractDefault: JExtractDefaultBuildConfiguration { | ||
| .shared | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // The actual resources will be generated by the buildToolsPlugin. This file is necessary for SwiftPM to generate a module bundle. | ||
| {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm resources cause pulling in Foundation but hopefully just for the specific target, so this won't show up in any of the runtime modules...
Please keep an eye out on it @madsodgaard but it seems our linking test is happy so we should be good 👍