File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -152,12 +152,32 @@ extension BuildParameters {
152152 args = [ " -alias " , " _ \( target. c99name) _main " , " _main " ]
153153 case . elf:
154154 args = [ " --defsym " , " main= \( target. c99name) _main " ]
155+ case . coff:
156+ // If the user is specifying a custom entry point name that isn't "main", assume they may be setting WinMain or wWinMain
157+ // and don't do any modifications ourselves. In that case the linker will infer the WINDOWS subsystem and call WinMainCRTStartup,
158+ // which will then call the custom entry point. And WinMain/wWinMain != main, so this still won't run into duplicate symbol
159+ // issues when called from a test target, which always uses main.
160+ if let customEntryPointFunctionName = findCustomEntryPointFunctionName ( of: target) , customEntryPointFunctionName != " main " {
161+ return nil
162+ }
163+ args = [ " /ALTERNATENAME:main= \( target. c99name) _main " , " /SUBSYSTEM:CONSOLE " ]
155164 default :
156165 return nil
157166 }
158167 return args. asSwiftcLinkerFlags ( )
159168 }
160169
170+ private func findCustomEntryPointFunctionName( of target: ResolvedModule ) -> String ? {
171+ let flags = createScope ( for: target) . evaluate ( . OTHER_SWIFT_FLAGS)
172+ var it = flags. makeIterator ( )
173+ while let value = it. next ( ) {
174+ if value == " -Xfrontend " && it. next ( ) == " -entry-point-function-name " && it. next ( ) == " -Xfrontend " {
175+ return it. next ( )
176+ }
177+ }
178+ return nil
179+ }
180+
161181 /// Returns the scoped view of build settings for a given target.
162182 func createScope( for target: ResolvedModule ) -> BuildSettings . Scope {
163183 BuildSettings . Scope ( target. underlying. buildSettings, environment: buildEnvironment)
Original file line number Diff line number Diff line change @@ -3875,7 +3875,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
38753875 observabilityScope: observability. topScope
38763876 ) )
38773877 }
3878- let supportingTriples : [ Basics . Triple ] = [ . x86_64Linux, . x86_64MacOS]
3878+ let supportingTriples : [ Basics . Triple ] = [ . x86_64Linux, . x86_64MacOS, . x86_64Windows ]
38793879 for triple in supportingTriples {
38803880 let result = try await createResult ( for: triple)
38813881 let exe = try result. moduleBuildDescription ( for: " exe " ) . swift ( ) . compileArguments ( )
@@ -3884,7 +3884,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
38843884 XCTAssertMatch ( linkExe, [ . contains( " exe_main " ) ] )
38853885 }
38863886
3887- let unsupportingTriples : [ Basics . Triple ] = [ . wasi, . windows ]
3887+ let unsupportingTriples : [ Basics . Triple ] = [ . wasi]
38883888 for triple in unsupportingTriples {
38893889 let result = try await createResult ( for: triple)
38903890 let exe = try result. moduleBuildDescription ( for: " exe " ) . swift ( ) . compileArguments ( )
You can’t perform that action at this time.
0 commit comments