diff --git a/Fixtures/Miscellaneous/TestableExeWithResources/Package.swift b/Fixtures/Miscellaneous/TestableExeWithResources/Package.swift new file mode 100644 index 00000000000..6c9d054b9ca --- /dev/null +++ b/Fixtures/Miscellaneous/TestableExeWithResources/Package.swift @@ -0,0 +1,18 @@ +// swift-tools-version: 6.0 +import PackageDescription + +let package = Package( + name: "TestableExe", + targets: [ + .executableTarget( + name: "TestableExe", + resources: [.embedInCode("foo.txt")] + ), + .testTarget( + name: "TestableExeTests", + dependencies: [ + "TestableExe", + ] + ), + ] +) diff --git a/Fixtures/Miscellaneous/TestableExeWithResources/Sources/TestableExe/foo.txt b/Fixtures/Miscellaneous/TestableExeWithResources/Sources/TestableExe/foo.txt new file mode 100644 index 00000000000..5716ca5987c --- /dev/null +++ b/Fixtures/Miscellaneous/TestableExeWithResources/Sources/TestableExe/foo.txt @@ -0,0 +1 @@ +bar diff --git a/Fixtures/Miscellaneous/TestableExeWithResources/Sources/TestableExe/main.swift b/Fixtures/Miscellaneous/TestableExeWithResources/Sources/TestableExe/main.swift new file mode 100644 index 00000000000..f09072009b6 --- /dev/null +++ b/Fixtures/Miscellaneous/TestableExeWithResources/Sources/TestableExe/main.swift @@ -0,0 +1,5 @@ +public func GetGreeting1() -> String { + return String(decoding: PackageResources.foo_txt, as: UTF8.self) +} + +print("\(GetGreeting1())!") diff --git a/Fixtures/Miscellaneous/TestableExeWithResources/Tests/TestableExeTests/TestableExeTests.swift b/Fixtures/Miscellaneous/TestableExeWithResources/Tests/TestableExeTests/TestableExeTests.swift new file mode 100644 index 00000000000..1e7ce512c62 --- /dev/null +++ b/Fixtures/Miscellaneous/TestableExeWithResources/Tests/TestableExeTests/TestableExeTests.swift @@ -0,0 +1,8 @@ +import XCTest +@testable import TestableExe + +final class TestableExeTests: XCTestCase { + func testExample() throws { + XCTAssertEqual(GetGreeting1(), "bar\n") + } +} diff --git a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift index 0fa439ab914..13a45341cc8 100644 --- a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift +++ b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift @@ -317,6 +317,14 @@ extension PackagePIFProjectBuilder { // `inputResourceBundleName`. shouldGenerateBundleAccessor = true shouldGenerateEmbedInCodeAccessor = true + if resourceBundleName != nil { + let resourceTargetID = pifTargetIdForResourceBundle(sourceModule.name) + self.project[keyPath: sourceModuleTargetKeyPath].common.addDependency( + on: resourceTargetID, + platformFilters: [], + linkProduct: false + ) + } } // Find the PIF target for the resource bundle, if any. Otherwise fall back to the module. diff --git a/Tests/CommandsTests/TestCommandTests.swift b/Tests/CommandsTests/TestCommandTests.swift index 38961e48428..a17ee6eb4c7 100644 --- a/Tests/CommandsTests/TestCommandTests.swift +++ b/Tests/CommandsTests/TestCommandTests.swift @@ -1251,4 +1251,29 @@ struct TestCommandTests { } } + @Test( + .IssueWindowsLongPath, + .tags( + .Feature.TargetType.Executable, + ), + arguments: SupportedBuildSystemOnAllPlatforms, BuildConfiguration.allCases, + ) + func testableExecutableWithEmbeddedResources( + buildSystem: BuildSystemProvider.Kind, + configuration: BuildConfiguration, + ) async throws { + try await withKnownIssue(isIntermittent: true) { + try await fixture(name: "Miscellaneous/TestableExeWithResources") { fixturePath in + let result = try await execute( + ["--vv"], + packagePath: fixturePath, + configuration: configuration, + buildSystem: buildSystem, + ) + } + } when: { + .windows == ProcessInfo.hostOperatingSystem + } + } + }