Skip to content

Fixup cross platform specs handling of DEAD_CODE_STRIPPING #576

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 1 commit into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/SWBGenericUnixPlatform/Specs/UnixLd.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@
};
Condition = "$(ALTERNATE_LINKER) == gold";
},
{
Name = "DEAD_CODE_STRIPPING";
Type = Boolean;
DefaultValue = NO;
Condition = "$(MACH_O_TYPE) != mh_object";
CommandLineArgs = {
YES = ("-Xlinker", "--gc-sections");
NO = ();
};
},
{
// Frameworks are Mac specific
Name = "SYSTEM_FRAMEWORK_SEARCH_PATHS";
Expand Down
5 changes: 5 additions & 0 deletions Sources/SWBQNXPlatform/Specs/QNXLd.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
};
Condition = "$(ALTERNATE_LINKER) == gold";
},
{
Name = "DEAD_CODE_STRIPPING";
Type = Boolean;
Condition = "NO";
},
{
// Frameworks are Mac specific
Name = "SYSTEM_FRAMEWORK_SEARCH_PATHS";
Expand Down
5 changes: 4 additions & 1 deletion Sources/SWBUniversalPlatform/Specs/Ld.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@
Type = Boolean;
DefaultValue = NO;
Condition = "$(MACH_O_TYPE) != mh_object";
CommandLineFlag = "-dead_strip";
CommandLineArgs = {
YES = ("-dead_strip");
NO = ();
};
},
{
Name = "BUNDLE_LOADER";
Expand Down
10 changes: 10 additions & 0 deletions Sources/SWBWebAssemblyPlatform/Specs/WasmLd.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
NO = ();
};
},
{
Name = "DEAD_CODE_STRIPPING";
Type = Boolean;
DefaultValue = NO;
Condition = "$(MACH_O_TYPE) != mh_object";
CommandLineArgs = {
YES = ("-Xlinker", "--gc-sections");
NO = ();
};
},
{
// Frameworks are Mac specific
Name = "SYSTEM_FRAMEWORK_SEARCH_PATHS";
Expand Down
10 changes: 10 additions & 0 deletions Sources/SWBWindowsPlatform/Specs/WindowsLd.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@
Type = String;
Condition = "NO";
},
{
Name = "DEAD_CODE_STRIPPING";
Type = Boolean;
DefaultValue = NO;
Condition = "$(MACH_O_TYPE) != mh_object";
CommandLineArgs = {
YES = ("-Xlinker", "/OPT:REF");
NO = ();
};
},
{
// No such concept
Name = "LD_RUNPATH_SEARCH_PATHS";
Expand Down
60 changes: 59 additions & 1 deletion Tests/SWBTaskConstructionTests/TaskConstructionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

import struct Foundation.Data
import Foundation

import Testing

Expand Down Expand Up @@ -8657,6 +8657,64 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
}
}

@Test(.requireSDKs(.host))
func crossPlatformDeadCodeStripping() async throws {
try await withTemporaryDirectory { tmpDir in
let testProject = TestProject(
"aProject",
sourceRoot: tmpDir,
groupTree: TestGroup(
"SomeFiles", path: "Sources",
children: [
TestFile("SourceFile.c"),
]),
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: [
"DEAD_CODE_STRIPPING": "YES",
"ONLY_ACTIVE_ARCH": "YES"
])
],
targets: [
TestStandardTarget(
"Library",
type: .dynamicLibrary,
buildConfigurations: [
TestBuildConfiguration("Debug")
],
buildPhases: [
TestSourcesBuildPhase([
"SourceFile.c",
])
]
)]
)

let fs = PseudoFS()

let core = try await getCore()
let tester = try TaskConstructionTester(core, testProject)

try await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: [:]), runDestination: .host, fs: fs) { results in
try results.checkTask(.matchRuleType("Ld")) { task in
switch try ProcessInfo.processInfo.hostOperatingSystem() {
case .macOS:
task.checkCommandLineContains(["-dead_strip"])
task.checkCommandLineDoesNotContain("--gc-sections")
task.checkCommandLineDoesNotContain("/OPT:REF")
case .windows:
task.checkCommandLineDoesNotContain("-dead_strip")
task.checkCommandLineDoesNotContain("--gc-sections")
task.checkCommandLineContains(["/OPT:REF"])
default:
task.checkCommandLineDoesNotContain("-dead_strip")
task.checkCommandLineContains(["--gc-sections"])
task.checkCommandLineDoesNotContain("/OPT:REF")
}
}
}
}
}

@Test(.requireSDKs(.macOS))
func warningSuppression() async throws {
try await withTemporaryDirectory { tmpDir in
Expand Down
Loading