-
Notifications
You must be signed in to change notification settings - Fork 100
jextract: Evaluate IfConfigDecl and add --static-build-config option #671
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
14 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 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
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 outSwift = context.pluginWorkDirectoryURL.appending(path: "StaticBuildConfiguration+embedded.swift") | ||
| return [ | ||
| .buildCommand( | ||
| displayName: "Run -print-static-build-config", | ||
| executable: try context.tool(named: "StaticBuildConfigPluginExecutable").url, | ||
| arguments: [outSwift.absoluteURL.path(percentEncoded: false)], | ||
| environment: [:], | ||
| inputFiles: [], | ||
| outputFiles: [outSwift.absoluteURL] | ||
| ) | ||
| ] | ||
| } | ||
| } |
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
99 changes: 99 additions & 0 deletions
99
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,99 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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() { | ||
| let decoder = JSONDecoder() | ||
| do { | ||
| base = try decoder.decode(StaticBuildConfiguration.self, from: StaticBuildConfiguration.embedded) | ||
| } catch { | ||
| fatalError("Embedded StaticBuildConfiguration is broken! data: \(String(data: StaticBuildConfiguration.embedded, encoding: .utf8) ?? "")") | ||
| } | ||
| } | ||
|
|
||
| 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
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.
Uh oh!
There was an error while loading. Please reload this page.