Skip to content

Commit b3e522d

Browse files
authored
Merge pull request swiftlang#1286 from DougGregor/macro-frontend-opts
2 parents 2f05fda + 670879d commit b3e522d

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ extension Driver {
237237
commandLine.appendFlag(.emptyAbiDescriptor)
238238
}
239239

240+
if isFrontendArgSupported(.emitMacroExpansionFiles) {
241+
try commandLine.appendLast(.emitMacroExpansionFiles, from: &parsedOptions)
242+
}
243+
244+
if isFrontendArgSupported(.pluginPath) {
245+
try commandLine.appendAll(.pluginPath, from: &parsedOptions)
246+
247+
let defaultPluginPath = try toolchain.executableDir.parentDirectory
248+
.appending(components: "lib", "swift", "host", "plugins")
249+
commandLine.appendFlag(.pluginPath)
250+
commandLine.appendPath(defaultPluginPath)
251+
}
252+
240253
// Pass down -user-module-version if we are working with a compiler that
241254
// supports it.
242255
if let ver = parsedOptions.getLastArgument(.userModuleVersion)?.asSingle,

Sources/SwiftOptions/Options.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ extension Option {
146146
public static let disableImplicitConcurrencyModuleImport: Option = Option("-disable-implicit-concurrency-module-import", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable the implicit import of the _Concurrency module.")
147147
public static let disableImplicitStringProcessingModuleImport: Option = Option("-disable-implicit-string-processing-module-import", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable the implicit import of the _StringProcessing module.")
148148
public static let disableImplicitSwiftModules: Option = Option("-disable-implicit-swift-modules", .flag, attributes: [.frontend, .noDriver], helpText: "Disable building Swift modules implicitly by the compiler")
149+
public static let disableImportPtrauthFieldFunctionPointers: Option = Option("-disable-import-ptrauth-field-function-pointers", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable import of custom ptrauth qualified field function pointers")
149150
public static let disableIncrementalImports: Option = Option("-disable-incremental-imports", .flag, attributes: [.frontend], helpText: "Disable cross-module incremental build metadata and driver scheduling for Swift modules")
150151
public static let disableIncrementalLlvmCodegeneration: Option = Option("-disable-incremental-llvm-codegen", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable incremental llvm code generation.")
151152
public static let disableInferPublicConcurrentValue: Option = Option("-disable-infer-public-sendable", .flag, attributes: [.frontend, .noDriver], helpText: "Disable inference of Sendable conformances for public structs and enums")
@@ -265,6 +266,7 @@ extension Option {
265266
public static let emitLoadedModuleTracePathEQ: Option = Option("-emit-loaded-module-trace-path=", .joined, alias: Option.emitLoadedModuleTracePath, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput])
266267
public static let emitLoadedModuleTracePath: Option = Option("-emit-loaded-module-trace-path", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput], metaVar: "<path>", helpText: "Emit the loaded module trace JSON to <path>")
267268
public static let emitLoadedModuleTrace: Option = Option("-emit-loaded-module-trace", .flag, attributes: [.frontend, .noInteractive, .supplementaryOutput], helpText: "Emit a JSON file containing information about what modules were loaded")
269+
public static let emitMacroExpansionFiles: Option = Option("-emit-macro-expansion-files", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Specify when to emit macro expansion file: 'none', 'debug', or 'diagnostics'")
268270
public static let emitMigratedFilePath: Option = Option("-emit-migrated-file-path", .separate, attributes: [.frontend, .noDriver, .noInteractive, .doesNotAffectIncrementalBuild], metaVar: "<path>", helpText: "Emit the migrated source file to <path>")
269271
public static let emitModuleDependenciesPath: Option = Option("-emit-module-dependencies-path", .separate, attributes: [.argumentIsPath, .supplementaryOutput], metaVar: "<path>", helpText: "Emit a discovered dependencies file for the emit-module task to <path>")
270272
public static let emitModuleDocPath: Option = Option("-emit-module-doc-path", .separate, attributes: [.frontend, .noDriver], metaVar: "<path>", helpText: "Output module documentation file <path>")
@@ -349,6 +351,7 @@ extension Option {
349351
public static let enableExperimentalStringProcessing: Option = Option("-enable-experimental-string-processing", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable experimental string processing")
350352
public static let enableExplicitExistentialTypes: Option = Option("-enable-explicit-existential-types", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable experimental support for explicit existential types")
351353
public static let enableImplicitDynamic: Option = Option("-enable-implicit-dynamic", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Add 'dynamic' to all declarations")
354+
public static let enableImportPtrauthFieldFunctionPointers: Option = Option("-enable-import-ptrauth-field-function-pointers", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable import of custom ptrauth qualified field function pointers")
352355
public static let enableIncrementalImports: Option = Option("-enable-incremental-imports", .flag, attributes: [.frontend], helpText: "Enable cross-module incremental build metadata and driver scheduling for Swift modules")
353356
public static let enableInferPublicConcurrentValue: Option = Option("-enable-infer-public-sendable", .flag, attributes: [.frontend, .noDriver], helpText: "Enable inference of Sendable conformances for public structs and enums")
354357
public static let enableInvalidEphemeralnessAsError: Option = Option("-enable-invalid-ephemeralness-as-error", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Diagnose invalid ephemeral to non-ephemeral conversions as errors")
@@ -408,6 +411,7 @@ extension Option {
408411
public static let explicitInterfaceModuleBuild: Option = Option("-explicit-interface-module-build", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Use the specified command-line to build the module from interface, instead of flags specified in the interface")
409412
public static let driverExplicitModuleBuild: Option = Option("-explicit-module-build", .flag, attributes: [.helpHidden], helpText: "Prebuild module dependencies to make them explicit")
410413
public static let explicitSwiftModuleMap: Option = Option("-explicit-swift-module-map-file", .separate, attributes: [.frontend, .noDriver], metaVar: "<path>", helpText: "Specify a JSON file containing information of explicit Swift modules")
414+
public static let exportAs: Option = Option("-export-as", .separate, attributes: [.frontend], helpText: "Module name to use when referenced in clients module interfaces")
411415
public static let externalPassPipelineFilename: Option = Option("-external-pass-pipeline-filename", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<pass_pipeline_file>", helpText: "Use the pass pipeline defined by <pass_pipeline_file>")
412416
public static let e: Option = Option("-e", .separate, attributes: [], helpText: "Executes a line of code provided on the command line")
413417
public static let FEQ: Option = Option("-F=", .joined, alias: Option.F, attributes: [.frontend, .argumentIsPath])
@@ -557,6 +561,7 @@ extension Option {
557561
public static let placeholderDependencyModuleMap: Option = Option("-placeholder-dependency-module-map-file", .separate, attributes: [.frontend, .noDriver], metaVar: "<path>", helpText: "Specify a JSON file containing information of external Swift module dependencies")
558562
public static let playgroundHighPerformance: Option = Option("-playground-high-performance", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Omit instrumentation that has a high runtime performance impact")
559563
public static let playground: Option = Option("-playground", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Apply the playground semantics and transformation")
564+
public static let pluginPath: Option = Option("-plugin-path", .separate, attributes: [.frontend, .argumentIsPath], helpText: "Add directory to the plugin search path")
560565
public static let prebuiltModuleCachePathEQ: Option = Option("-prebuilt-module-cache-path=", .joined, alias: Option.prebuiltModuleCachePath, attributes: [.helpHidden, .frontend, .noDriver])
561566
public static let prebuiltModuleCachePath: Option = Option("-prebuilt-module-cache-path", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Directory of prebuilt modules for loading module interfaces")
562567
public static let prefixSerializedDebuggingOptions: Option = Option("-prefix-serialized-debugging-options", .flag, attributes: [.frontend], helpText: "Apply debug prefix mappings to serialized debug info in Swiftmodule files")
@@ -659,6 +664,7 @@ extension Option {
659664
public static let suppressStaticExclusivitySwap: Option = Option("-suppress-static-exclusivity-swap", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Suppress static violations of exclusive access with swap()")
660665
public static let suppressWarnings: Option = Option("-suppress-warnings", .flag, attributes: [.frontend], helpText: "Suppress all warnings")
661666
public static let swiftAsyncFramePointerEQ: Option = Option("-swift-async-frame-pointer=", .joined, attributes: [.helpHidden, .frontend, .noDriver], helpText: "One of 'auto', 'always' or 'never'")
667+
public static let swiftModuleFile: Option = Option("-swift-module-file=", .joined, attributes: [.frontend, .noDriver], metaVar: "<name>=<path>", helpText: "Specify Swift module input explicitly built from textual interface")
662668
public static let swiftOnly: Option = Option("-swift-only", .flag, attributes: [.noDriver], helpText: "Only include APIs defined from Swift source")
663669
public static let swiftOnly_: Option = Option("--swift-only", .flag, alias: Option.swiftOnly, attributes: [.noDriver], helpText: "Only include APIs defined from Swift source")
664670
public static let swiftVersion: Option = Option("-swift-version", .separate, attributes: [.frontend, .moduleInterface], metaVar: "<vers>", helpText: "Interpret input according to a specific Swift language version number")
@@ -885,6 +891,7 @@ extension Option {
885891
Option.disableImplicitConcurrencyModuleImport,
886892
Option.disableImplicitStringProcessingModuleImport,
887893
Option.disableImplicitSwiftModules,
894+
Option.disableImportPtrauthFieldFunctionPointers,
888895
Option.disableIncrementalImports,
889896
Option.disableIncrementalLlvmCodegeneration,
890897
Option.disableInferPublicConcurrentValue,
@@ -1004,6 +1011,7 @@ extension Option {
10041011
Option.emitLoadedModuleTracePathEQ,
10051012
Option.emitLoadedModuleTracePath,
10061013
Option.emitLoadedModuleTrace,
1014+
Option.emitMacroExpansionFiles,
10071015
Option.emitMigratedFilePath,
10081016
Option.emitModuleDependenciesPath,
10091017
Option.emitModuleDocPath,
@@ -1088,6 +1096,7 @@ extension Option {
10881096
Option.enableExperimentalStringProcessing,
10891097
Option.enableExplicitExistentialTypes,
10901098
Option.enableImplicitDynamic,
1099+
Option.enableImportPtrauthFieldFunctionPointers,
10911100
Option.enableIncrementalImports,
10921101
Option.enableInferPublicConcurrentValue,
10931102
Option.enableInvalidEphemeralnessAsError,
@@ -1147,6 +1156,7 @@ extension Option {
11471156
Option.explicitInterfaceModuleBuild,
11481157
Option.driverExplicitModuleBuild,
11491158
Option.explicitSwiftModuleMap,
1159+
Option.exportAs,
11501160
Option.externalPassPipelineFilename,
11511161
Option.e,
11521162
Option.FEQ,
@@ -1296,6 +1306,7 @@ extension Option {
12961306
Option.placeholderDependencyModuleMap,
12971307
Option.playgroundHighPerformance,
12981308
Option.playground,
1309+
Option.pluginPath,
12991310
Option.prebuiltModuleCachePathEQ,
13001311
Option.prebuiltModuleCachePath,
13011312
Option.prefixSerializedDebuggingOptions,
@@ -1398,6 +1409,7 @@ extension Option {
13981409
Option.suppressStaticExclusivitySwap,
13991410
Option.suppressWarnings,
14001411
Option.swiftAsyncFramePointerEQ,
1412+
Option.swiftModuleFile,
14011413
Option.swiftOnly,
14021414
Option.swiftOnly_,
14031415
Option.swiftVersion,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6633,6 +6633,19 @@ final class SwiftDriverTests: XCTestCase {
66336633
#endif
66346634
}
66356635

6636+
func testPluginPaths() throws {
6637+
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"])
6638+
guard driver.isFrontendArgSupported(.pluginPath) else {
6639+
return
6640+
}
6641+
6642+
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
6643+
XCTAssertEqual(jobs.count, 1)
6644+
let job = jobs.first!
6645+
XCTAssertTrue(job.commandLine.contains(.flag("-plugin-path")))
6646+
XCTAssertTrue(job.commandLine.contains(.path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "lib", "swift", "host", "plugins")))))
6647+
}
6648+
66366649
func testRegistrarLookup() throws {
66376650
#if os(Windows)
66386651
let SDKROOT: AbsolutePath = localFileSystem.currentWorkingDirectory!.appending(components: "SDKROOT")

0 commit comments

Comments
 (0)