Skip to content

Commit

Permalink
Add include dir from a clang module into the build args.
Browse files Browse the repository at this point in the history
Each clang module has public `include` dir. When building current module
then it typically works as-is, but when a module has non-standard
source location, then explicit include of `include` is necessary.
  • Loading branch information
yyvch authored and jakepetroules committed Jan 21, 2025
1 parent 083840e commit 8469311
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Fixtures/Miscellaneous/APIDiff/CIncludePath/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Sample",
products: [
.library(
name: "Sample",
targets: ["Sample"]
),
],
targets: [
.target(
name: "CSample",
sources: ["./vendorsrc/src"],
cSettings: [
.headerSearchPath("./vendorsrc/include"),
]
),
.target(
name: "Sample",
dependencies: ["CSample"]
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#include "config.h"
#include "../vendorsrc/include/vendor.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define HAVE_VENDOR_CONFIG
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

#include "config.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "vendor.h"

int vendor__func(int n)
{
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import CSample
1 change: 1 addition & 0 deletions Sources/Build/BuildPlan/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
if let includeDir = targetDescription.moduleMap?.parentDirectory {
arguments += ["-I", includeDir.pathString]
}
arguments += ["-I", targetDescription.clangTarget.includeDir.pathString]
}
}

Expand Down
10 changes: 10 additions & 0 deletions Tests/CommandsTests/APIDiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ final class APIDiffTests: CommandsTestCase {
}
}

func testAPIDiffOfVendoredCDependency() async throws {
try skipIfApiDigesterUnsupportedOrUnset()
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
let packageRoot = fixturePath.appending("CIncludePath")
let (output, _) = try await execute(["diagnose-api-breaking-changes", "main"], packagePath: packageRoot)

XCTAssertMatch(output, .contains("No breaking changes detected in Sample"))
}
}

func testNoBreakingChanges() async throws {
try skipIfApiDigesterUnsupportedOrUnset()
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
Expand Down

0 comments on commit 8469311

Please sign in to comment.