Skip to content

Commit 979610a

Browse files
authored
[6.1] Add include dir from a clang module into the build args. (#8241)
- Description: Fix build error for `diagnose-api-breaking-changes` command when C code is in non-standard location - Scope: Package - Risk: Low - Testing: New test for this specific scenario. However, the test suite is deactivated in 6.1 unless [#8196](#8196) is cherry-picked too. - Issue: #8073 - Cherry-picked from: #8209 - Author: @yyvch - Reviewers: @plemarquand @jakepetroules
1 parent fbde755 commit 979610a

File tree

8 files changed

+51
-0
lines changed

8 files changed

+51
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// swift-tools-version: 6.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "Sample",
8+
products: [
9+
.library(
10+
name: "Sample",
11+
targets: ["Sample"]
12+
),
13+
],
14+
targets: [
15+
.target(
16+
name: "CSample",
17+
sources: ["./vendorsrc/src"],
18+
cSettings: [
19+
.headerSearchPath("./vendorsrc/include"),
20+
]
21+
),
22+
.target(
23+
name: "Sample",
24+
dependencies: ["CSample"]
25+
),
26+
]
27+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
#include "config.h"
3+
#include "../vendorsrc/include/vendor.h"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define HAVE_VENDOR_CONFIG
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
#include "config.h"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "vendor.h"
2+
3+
int vendor__func(int n)
4+
{
5+
return 0;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import CSample

Sources/Build/BuildPlan/BuildPlan.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
593593
if let includeDir = targetDescription.moduleMap?.parentDirectory {
594594
arguments += ["-I", includeDir.pathString]
595595
}
596+
arguments += ["-I", targetDescription.clangTarget.includeDir.pathString]
596597
}
597598
}
598599

Tests/CommandsTests/APIDiffTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ final class APIDiffTests: CommandsTestCase {
273273
}
274274
}
275275

276+
func testAPIDiffOfVendoredCDependency() async throws {
277+
try skipIfApiDigesterUnsupportedOrUnset()
278+
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
279+
let packageRoot = fixturePath.appending("CIncludePath")
280+
let (output, _) = try await execute(["diagnose-api-breaking-changes", "main"], packagePath: packageRoot)
281+
282+
XCTAssertMatch(output, .contains("No breaking changes detected in Sample"))
283+
}
284+
}
285+
276286
func testNoBreakingChanges() async throws {
277287
try skipIfApiDigesterUnsupportedOrUnset()
278288
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in

0 commit comments

Comments
 (0)