Skip to content

Commit c4527dc

Browse files
authored
Merge pull request #84580 from DougGregor/static-build-configure
2 parents 94f8a05 + 2a46916 commit c4527dc

40 files changed

+842
-313
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class IfConfigClauseRangeInfo;
5858
class GenericSignature;
5959
class GenericSignatureImpl;
6060
struct LabeledStmtInfo;
61+
class LangOptions;
6162
class LayoutConstraint;
6263
class LayoutConstraintInfo;
6364
struct LifetimeDescriptor;
@@ -82,6 +83,7 @@ enum class RequirementReprKind : unsigned;
8283
struct BridgedASTType;
8384
class BridgedCanType;
8485
class BridgedASTContext;
86+
class BridgedLangOptions;
8587
struct BridgedSubstitutionMap;
8688
struct BridgedGenericSignature;
8789
struct BridgedConformance;
@@ -192,15 +194,11 @@ BridgedDeclNameLoc_createParsed(BridgedASTContext cContext,
192194
swift::SourceLoc moduleSelectorLoc,
193195
swift::SourceLoc baseNameLoc);
194196

197+
195198
//===----------------------------------------------------------------------===//
196199
// MARK: ASTContext
197200
//===----------------------------------------------------------------------===//
198201

199-
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedEndianness : size_t {
200-
EndianLittle,
201-
EndianBig,
202-
};
203-
204202
class BridgedASTContext {
205203
swift::ASTContext * _Nonnull Ctx;
206204

@@ -218,16 +216,10 @@ class BridgedASTContext {
218216
unsigned getMajorLanguageVersion() const;
219217

220218
SWIFT_COMPUTED_PROPERTY
221-
unsigned getLangOptsTargetPointerBitWidth() const;
222-
223-
SWIFT_COMPUTED_PROPERTY
224-
bool getLangOptsAttachCommentsToDecls() const;
225-
226-
SWIFT_COMPUTED_PROPERTY
227-
BridgedEndianness getLangOptsTargetEndianness() const;
219+
BridgedAvailabilityMacroMap getAvailabilityMacroMap() const;
228220

229221
SWIFT_COMPUTED_PROPERTY
230-
BridgedAvailabilityMacroMap getAvailabilityMacroMap() const;
222+
BridgedDiagnosticEngine getDiags() const;
231223
};
232224

233225
#define IDENTIFIER_WITH_NAME(Name, _) \
@@ -259,56 +251,12 @@ SWIFT_NAME("BridgedASTContext.getDollarIdentifier(self:_:)")
259251
swift::Identifier
260252
BridgedASTContext_getDollarIdentifier(BridgedASTContext cContext, size_t idx);
261253

262-
SWIFT_NAME("BridgedASTContext.langOptsHasFeature(self:_:)")
263-
bool BridgedASTContext_langOptsHasFeature(BridgedASTContext cContext,
264-
BridgedFeature feature);
265-
266-
SWIFT_NAME("BridgedASTContext.langOptsCustomConditionSet(self:_:)")
267-
bool BridgedASTContext_langOptsCustomConditionSet(BridgedASTContext cContext,
268-
BridgedStringRef cName);
269-
270-
SWIFT_NAME("BridgedASTContext.langOptsHasFeatureNamed(self:_:)")
271-
bool BridgedASTContext_langOptsHasFeatureNamed(BridgedASTContext cContext,
272-
BridgedStringRef cName);
254+
SWIFT_NAME("getter:BridgedASTContext.langOpts(self:)")
255+
BridgedLangOptions BridgedASTContext_langOpts(BridgedASTContext cContext);
273256

274-
SWIFT_NAME("BridgedASTContext.langOptsHasAttributeNamed(self:_:)")
275-
bool BridgedASTContext_langOptsHasAttributeNamed(BridgedASTContext cContext,
276-
BridgedStringRef cName);
277-
278-
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetOS(self:_:)")
279-
bool BridgedASTContext_langOptsIsActiveTargetOS(BridgedASTContext cContext,
280-
BridgedStringRef cName);
281-
282-
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetArchitecture(self:_:)")
283-
bool BridgedASTContext_langOptsIsActiveTargetArchitecture(BridgedASTContext cContext,
284-
BridgedStringRef cName);
285-
286-
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetEnvironment(self:_:)")
287-
bool BridgedASTContext_langOptsIsActiveTargetEnvironment(BridgedASTContext cContext,
288-
BridgedStringRef cName);
289-
290-
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetRuntime(self:_:)")
291-
bool BridgedASTContext_langOptsIsActiveTargetRuntime(BridgedASTContext cContext,
292-
BridgedStringRef cName);
293-
294-
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetPtrAuth(self:_:)")
295-
bool BridgedASTContext_langOptsIsActiveTargetPtrAuth(BridgedASTContext cContext,
296-
BridgedStringRef cName);
297-
298-
SWIFT_NAME("BridgedASTContext.langOptsGetTargetAtomicBitWidths(self:_:)")
299-
SwiftInt BridgedASTContext_langOptsGetTargetAtomicBitWidths(BridgedASTContext cContext,
300-
SwiftInt* _Nullable * _Nonnull cComponents);
301-
302-
SWIFT_NAME("BridgedASTContext.langOptsGetLanguageVersion(self:_:)")
303-
SwiftInt BridgedASTContext_langOptsGetLanguageVersion(BridgedASTContext cContext,
304-
SwiftInt* _Nullable * _Nonnull cComponents);
305-
306-
SWIFT_NAME("BridgedASTContext.langOptsGetCompilerVersion(self:_:)")
307-
SwiftInt BridgedASTContext_langOptsGetCompilerVersion(BridgedASTContext cContext,
308-
SwiftInt* _Nullable * _Nonnull cComponents);
309-
310-
/* Deallocate an array of Swift int values that was allocated in C++. */
311-
void deallocateIntBuffer(SwiftInt * _Nullable cComponents);
257+
SWIFT_NAME("BridgedLangOptions.hasAttributeNamed(self:_:)")
258+
bool BridgedLangOptions_hasAttributeNamed(BridgedLangOptions cLangOpts,
259+
BridgedStringRef cName);
312260

313261
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedCanImportVersion : size_t {
314262
CanImportUnversioned,
@@ -324,6 +272,9 @@ bool BridgedASTContext_canImport(BridgedASTContext cContext,
324272
const SwiftInt *_Nullable versionComponents,
325273
SwiftInt numVersionComponents);
326274

275+
SWIFT_NAME("getter:BridgedASTContext.staticBuildConfigurationPtr(self:)")
276+
void * _Nonnull BridgedASTContext_staticBuildConfiguration(BridgedASTContext cContext);
277+
327278
//===----------------------------------------------------------------------===//
328279
// MARK: AST nodes
329280
//===----------------------------------------------------------------------===//

include/swift/AST/ASTBridgingImpl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ swift::DeclNameLoc BridgedDeclNameLoc::unbridged() const {
6666
return swift::DeclNameLoc(LocationInfo, NumArgumentLabels);
6767
}
6868

69+
//===----------------------------------------------------------------------===//
70+
// MARK: BridgedLangOptions
71+
//===----------------------------------------------------------------------===//
72+
73+
BridgedLangOptions::BridgedLangOptions(const swift::LangOptions &langOpts)
74+
: LangOpts(&langOpts) { }
75+
76+
const swift::LangOptions &BridgedLangOptions::unbridged() const {
77+
return *LangOpts;
78+
}
79+
6980
//===----------------------------------------------------------------------===//
7081
// MARK: BridgedASTContext
7182
//===----------------------------------------------------------------------===//

include/swift/AST/ASTContextGlobalCache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ struct ASTContext::GlobalCache {
8484
const NormalProtocolConformance *,
8585
std::vector<ConformanceIsolationError>
8686
> conformanceIsolationErrors;
87+
88+
/// The static build configuration. This points to an instance of the Swift
89+
/// StaticBuildConfiguration.
90+
void *StaticBuildConfiguration = nullptr;
8791
};
8892

8993
} // end namespace

include/swift/Basic/BasicBridging.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class VersionTuple;
6161
} // end namespace llvm
6262

6363
namespace swift {
64+
class LangOptions;
6465
class SourceLoc;
6566
class SourceRange;
6667
class CharSourceRange;
@@ -451,6 +452,84 @@ struct BridgedSwiftClosure {
451452
BRIDGED_INLINE void operator()(const void *_Nullable);
452453
};
453454

455+
//===----------------------------------------------------------------------===//
456+
// MARK: LangOptions
457+
//===----------------------------------------------------------------------===//
458+
459+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedEndianness : size_t {
460+
EndianLittle,
461+
EndianBig,
462+
};
463+
464+
class BridgedLangOptions {
465+
const swift::LangOptions * _Nonnull LangOpts;
466+
467+
public:
468+
SWIFT_UNAVAILABLE("Use init(raw:) instead")
469+
BRIDGED_INLINE BridgedLangOptions(const swift::LangOptions &langOpts);
470+
471+
SWIFT_UNAVAILABLE("Use '.raw' instead")
472+
BRIDGED_INLINE const swift::LangOptions &unbridged() const;
473+
474+
SWIFT_COMPUTED_PROPERTY
475+
const void *_Nonnull getRaw() const { return LangOpts; }
476+
477+
SWIFT_COMPUTED_PROPERTY
478+
unsigned getMajorLanguageVersion() const;
479+
480+
SWIFT_COMPUTED_PROPERTY
481+
unsigned getTargetPointerBitWidth() const;
482+
483+
SWIFT_COMPUTED_PROPERTY
484+
BridgedEndianness getTargetEndianness() const;
485+
486+
SWIFT_COMPUTED_PROPERTY
487+
bool getAttachCommentsToDecls() const;
488+
};
489+
490+
/// Key used when enumerating build configuration entries to the
491+
/// StaticBuildConfiguration initializer for an ASTContext.
492+
enum ENUM_EXTENSIBILITY_ATTR(closed) BuildConfigurationKey : size_t {
493+
BCKCustomCondition,
494+
BCKFeature,
495+
BCKAttribute,
496+
BCKTargetOSName,
497+
BCKTargetArchitecture,
498+
BCKTargetEnvironment,
499+
BCKTargetRuntime,
500+
BCKTargetPointerAuthenticationScheme,
501+
BCKTargetObjectFileFormat
502+
};
503+
504+
SWIFT_NAME("BridgedLangOptions.hasFeature(self:_:)")
505+
bool BridgedLangOptions_hasFeature(BridgedLangOptions cLangOpts,
506+
BridgedFeature feature);
507+
508+
SWIFT_NAME("BridgedLangOptions.getTargetAtomicBitWidths(self:_:)")
509+
SwiftInt BridgedLangOptions_getTargetAtomicBitWidths(BridgedLangOptions cLangOpts,
510+
SwiftInt* _Nullable * _Nonnull cComponents);
511+
512+
SWIFT_NAME("BridgedLangOptions.getLanguageVersion(self:_:)")
513+
SwiftInt BridgedLangOptions_getLanguageVersion(BridgedLangOptions cLangOpts,
514+
SwiftInt* _Nullable * _Nonnull cComponents);
515+
516+
SWIFT_NAME("BridgedLangOptions.getCompilerVersion(self:_:)")
517+
SwiftInt BridgedLangOptions_getCompilerVersion(BridgedLangOptions cLangOpts,
518+
SwiftInt* _Nullable * _Nonnull cComponents);
519+
520+
/* Deallocate an array of Swift int values that was allocated in C++. */
521+
void deallocateIntBuffer(SwiftInt * _Nullable cComponents);
522+
523+
/// Enumerate all of the key/value pairs for the build configuration by calling
524+
/// the given callback for each one.
525+
SWIFT_NAME("BridgedLangOptions.enumerateBuildConfigurationEntries(self:callbackContext:callback:)")
526+
void BridgedLangOptions_enumerateBuildConfigurationEntries(
527+
BridgedLangOptions cLangOpts,
528+
void * _Nonnull callbackContext,
529+
void (* _Nonnull callback)(
530+
BridgedLangOptions cLangOpts, void * _Nonnull callbackContext,
531+
BuildConfigurationKey key, BridgedStringRef value));
532+
454533
SWIFT_END_NULLABILITY_ANNOTATIONS
455534

456535
#ifndef PURE_BRIDGING_MODE
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===--- BasicSwift.h -------------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 - 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BRIDGING_BASICSWIFT_H
14+
#define SWIFT_BRIDGING_BASICSWIFT_H
15+
16+
#include "swift/Basic/BasicBridging.h"
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
/// Create a new static build configuration for the given language options.
23+
void * _Nonnull swift_Basic_createStaticBuildConfiguration(BridgedLangOptions cLangOpts);
24+
25+
/// Free the given static build configuration.
26+
void swift_Basic_freeStaticBuildConfiguration(void * _Nonnull staticBuildConfiguration);
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
32+
#endif // SWIFT_BRIDGING_BASICSWIFT_H

include/swift/Bridging/MacroEvaluation.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_BRIDGING_MACROS_H
1515

1616
#include "swift/Basic/BasicBridging.h"
17+
#include "swift/AST/ASTBridging.h"
1718

1819
#ifdef __cplusplus
1920
extern "C" {
@@ -40,13 +41,13 @@ void swift_Macros_freeExpansionReplacements(
4041
ptrdiff_t *_Nullable replacementsPtr, ptrdiff_t numReplacements);
4142

4243
ptrdiff_t swift_Macros_expandFreestandingMacro(
43-
void *_Nonnull diagEngine, const void *_Nonnull macro,
44+
BridgedASTContext cContext, const void *_Nonnull macro,
4445
const char *_Nonnull discriminator, uint8_t rawMacroRole,
4546
void *_Nonnull sourceFile, const void *_Nullable sourceLocation,
4647
BridgedStringRef *_Nonnull evaluatedSourceOut);
4748

4849
ptrdiff_t swift_Macros_expandAttachedMacro(
49-
void *_Nonnull diagEngine, const void *_Nonnull macro,
50+
BridgedASTContext cContext, const void *_Nonnull macro,
5051
const char *_Nonnull discriminator, const char *_Nonnull qualifiedType,
5152
const char *_Nonnull conformances, uint8_t rawMacroRole,
5253
void *_Nonnull customAttrSourceFile,

include/swift/Frontend/FrontendOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ class FrontendOptions {
326326
/// exit.
327327
bool PrintTargetInfo = false;
328328

329+
/// Indicates that the frontend should print the static build configuration
330+
/// information as JSON.
331+
bool PrintBuildConfig = false;
332+
329333
/// Indicates that the frontend should print the supported features and then
330334
/// exit.
331335
bool PrintSupportedFeatures = false;

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,9 @@ def target_legacy_spelling : Joined<["--"], "target=">,
15421542
def print_target_info : Flag<["-"], "print-target-info">,
15431543
Flags<[FrontendOption]>,
15441544
HelpText<"Print target information for the given target <triple>, such as x86_64-apple-macos10.9">, MetaVarName<"<triple>">;
1545+
def print_static_build_config : Flag<["-"], "print-static-build-config">,
1546+
Flags<[FrontendOption]>,
1547+
HelpText<"Print static build configuration that can be used to evaluate #ifs in Swift source code">;
15451548

15461549
def print_supported_features : Flag<["-"], "print-supported-features">,
15471550
Flags<[FrontendOption]>,

0 commit comments

Comments
 (0)