Skip to content
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

Add test fixture for experimental-lto-mode #6891

Merged
merged 5 commits into from
Dec 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Fixtures/Miscellaneous/LTO/SwiftAndCTargets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
12 changes: 12 additions & 0 deletions Fixtures/Miscellaneous/LTO/SwiftAndCTargets/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// swift-tools-version: 5.9

import PackageDescription

let package = Package(
name: "SwiftAndCTargets",
targets: [
.target(name: "cLib"),
.executableTarget(name: "exe", dependencies: ["cLib", "swiftLib"]),
.target(name: "swiftLib"),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

#include "include/cLib.h"

void cPrint(int value) {
printf("c value: %i\n", value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

extern void cPrint(int);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import swiftLib
import cLib

cPrint(1)
swiftPrint(value: 2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func swiftPrint(value: Int) {
print("swift value: \(value)")
}
10 changes: 10 additions & 0 deletions Sources/Build/BuildDescription/ProductBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
// User arguments (from -Xlinker) should follow generated arguments to allow user overrides
args += self.buildParameters.flags.linkerFlags.asSwiftcLinkerFlags()

// Enable the correct lto mode if requested.
switch self.buildParameters.linkingParameters.linkTimeOptimizationMode {
case nil:
break
case .full:
args += ["-lto=llvm-full"]
case .thin:
args += ["-lto=llvm-thin"]
}

// Pass default library paths from the toolchain.
for librarySearchPath in self.buildParameters.toolchain.librarySearchPaths {
args += ["-L", librarySearchPath.pathString]
Expand Down
21 changes: 21 additions & 0 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,27 @@ class MiscellaneousTestCase: XCTestCase {
}
}

func testLTO() throws {
#if os(macOS)
// FIXME: this test requires swift-driver to be installed
// Currently swift-ci does not build/install swift-driver before running
// swift-package-manager tests which results in this test failing.
// See the following additional discussion:
// - https://github.com/apple/swift/pull/69696
// - https://github.com/apple/swift/pull/61766
// - https://github.com/apple/swift-package-manager/pull/5842#issuecomment-1301632685
try fixture(name: "Miscellaneous/LTO/SwiftAndCTargets") { fixturePath in
let output = try executeSwiftBuild(
fixturePath,
extraArgs: ["--experimental-lto-mode=full", "--verbose"])
// FIXME: On macOS dsymutil cannot find temporary .o files? (#6890)
// Ensure warnings like the following are not present in build output
// warning: (arm64) /var/folders/ym/6l_0x8vj0b70sz_4h9d70p440000gn/T/main-e120de.o unable to open object file: No such file or directory
// XCTAssertNoMatch(output.stdout, .contains("unable to open object file"))
}
#endif
}

func testUnicode() throws {
#if !os(Linux) && !os(Android) // TODO: - Linux has trouble with this and needs investigation.
try fixture(name: "Miscellaneous/Unicode") { fixturePath in
Expand Down