Skip to content

Commit 11ae2af

Browse files
NakaokaReiclaude
andcommitted
ci: fix C++ interop validation to build sample apps instead of entire package
The previous approach tried to build swift-java itself with C++ interop mode enabled, which fails because dependencies like swift-system don't support being built in C++ mode. The actual goal is to verify that projects depending on swift-java can build with C++ interop enabled. This change: - Replaces test-swift-cxx-interop jobs with verify-samples-cxx-interop - Adds CXX_INTEROP environment variable support to all sample Package.swift - Uses .interoperabilityMode(.Cxx) conditionally when CXX_INTEROP=1 - Tests all 7 sample apps with C++ interop on Linux (6.1.3, 6.2, nightly) and macOS (6.2) Fixes: #391 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9d1c8f9 commit 11ae2af

File tree

8 files changed

+96
-21
lines changed

8 files changed

+96
-21
lines changed

.github/workflows/pull_request.yml

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,47 +176,69 @@ jobs:
176176
- name: Swift Test
177177
run: "swift test"
178178

179-
test-swift-cxx-interop:
180-
name: Test (Swift, C++ Interop) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
179+
# Test that projects depending on swift-java can build with C++ interoperability enabled.
180+
# This is important because users may enable -cxx-interoperability-mode=default in their
181+
# own projects, and swift-java's public API must be compatible with that mode.
182+
# See: https://github.com/swiftlang/swift-java/issues/391
183+
verify-samples-cxx-interop:
184+
name: Sample ${{ matrix.sample_app }} (C++ Interop) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
181185
runs-on: ubuntu-latest
182186
strategy:
183187
fail-fast: false
184188
matrix:
185-
swift_version: ['6.2', 'nightly']
189+
swift_version: ['6.1.3', '6.2', 'nightly']
186190
os_version: ['jammy']
187191
jdk_vendor: ['corretto']
192+
sample_app: [
193+
'JavaDependencySampleApp',
194+
'JavaKitSampleApp',
195+
'JavaProbablyPrime',
196+
'JavaSieve',
197+
'SwiftAndJavaJarSampleLib',
198+
'SwiftJavaExtractFFMSampleApp',
199+
'SwiftJavaExtractJNISampleApp',
200+
]
188201
container:
189202
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
190203
env:
191-
SWIFT_JAVA_VERBOSE: true
204+
CXX_INTEROP: '1'
192205
steps:
193206
- uses: actions/checkout@v4
194207
- name: Prepare CI Environment
195208
uses: ./.github/actions/prepare_env
196-
- name: Swift Build with C++ Interoperability
197-
run: swift build --build-tests --disable-sandbox --disable-experimental-prebuilts -Xswiftc -cxx-interoperability-mode=default
198-
- name: Swift Test with C++ Interoperability
199-
run: swift test --disable-experimental-prebuilts -Xswiftc -cxx-interoperability-mode=default
209+
- name: "Verify sample with C++ Interop: ${{ matrix.sample_app }}"
210+
run: .github/scripts/validate_sample.sh Samples/${{ matrix.sample_app }}
200211

201-
test-swift-cxx-interop-macos:
202-
name: Test (Swift, C++ Interop) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
212+
verify-samples-cxx-interop-macos:
213+
name: Sample ${{ matrix.sample_app }} (C++ Interop) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
203214
runs-on: [self-hosted, macos, sequoia, ARM64]
204215
strategy:
205216
fail-fast: false
206217
matrix:
207218
swift_version: ['6.2']
208219
os_version: ['macos']
209220
jdk_vendor: ['corretto']
221+
sample_app: [
222+
'JavaDependencySampleApp',
223+
'JavaKitSampleApp',
224+
'JavaProbablyPrime',
225+
'JavaSieve',
226+
'SwiftAndJavaJarSampleLib',
227+
'SwiftJavaExtractFFMSampleApp',
228+
'SwiftJavaExtractJNISampleApp',
229+
]
210230
env:
211-
SWIFT_JAVA_VERBOSE: true
231+
CXX_INTEROP: '1'
212232
steps:
213233
- uses: actions/checkout@v4
214234
- name: Prepare CI Environment
215235
uses: ./.github/actions/prepare_env
216-
- name: Swift Build with C++ Interoperability
217-
run: swift build --build-tests --disable-sandbox -Xswiftc -cxx-interoperability-mode=default
218-
- name: Swift Test with C++ Interoperability
219-
run: swift test -Xswiftc -cxx-interoperability-mode=default
236+
- name: Install Swiftly
237+
run: ./.github/scripts/install_swiftly.sh
238+
env:
239+
SWIFT_VERSION: "${{ matrix.swift_version }}"
240+
- name: "Verify sample with C++ Interop: ${{ matrix.sample_app }}"
241+
run: .github/scripts/validate_sample.sh Samples/${{ matrix.sample_app }}
220242

221243
build-swift-android:
222244
name: Sample SwiftJavaExtractJNISampleApp (Android) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} android:${{matrix.sdk_triple}})

Samples/JavaDependencySampleApp/Package.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ let javaIncludePath = "\(javaHome)/include"
4040
#error("Currently only macOS and Linux platforms are supported, this may change in the future.")
4141
#endif
4242

43+
// Support C++ interoperability mode via CXX_INTEROP environment variable.
44+
// This is used to test that swift-java's public API is compatible with projects
45+
// that enable C++ interoperability mode.
46+
// See: https://github.com/swiftlang/swift-java/issues/391
47+
let cxxInteropEnabled = ProcessInfo.processInfo.environment["CXX_INTEROP"] == "1"
48+
4349
let package = Package(
4450
name: "JavaDependencySampleApp",
4551
platforms: [
@@ -73,6 +79,7 @@ let package = Package(
7379
swiftSettings: [
7480
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
7581
.swiftLanguageMode(.v5),
82+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
7683
],
7784
plugins: [
7885
.plugin(name: "SwiftJavaPlugin", package: "swift-java"),
@@ -92,6 +99,7 @@ let package = Package(
9299
swiftSettings: [
93100
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
94101
.swiftLanguageMode(.v5),
102+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
95103
],
96104
plugins: [
97105
// .plugin(name: "SwiftJavaBootstrapJavaPlugin", package: "swift-java"),

Samples/JavaKitSampleApp/Package.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ let javaIncludePath = "\(javaHome)/include"
3939
let javaPlatformIncludePath = "\(javaIncludePath)/win32)"
4040
#endif
4141

42+
// Support C++ interoperability mode via CXX_INTEROP environment variable.
43+
// This is used to test that swift-java's public API is compatible with projects
44+
// that enable C++ interoperability mode.
45+
// See: https://github.com/swiftlang/swift-java/issues/391
46+
let cxxInteropEnabled = ProcessInfo.processInfo.environment["CXX_INTEROP"] == "1"
47+
4248
let package = Package(
4349
name: "JavaKitSampleApp",
4450
platforms: [
@@ -70,7 +76,8 @@ let package = Package(
7076
],
7177
swiftSettings: [
7278
.swiftLanguageMode(.v5),
73-
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
79+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
80+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
7481
],
7582
plugins: [
7683
.plugin(name: "JavaCompilerPlugin", package: "swift-java"),

Samples/JavaProbablyPrime/Package.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
import CompilerPluginSupport
55
import PackageDescription
66

7+
import class Foundation.ProcessInfo
8+
9+
// Support C++ interoperability mode via CXX_INTEROP environment variable.
10+
// This is used to test that swift-java's public API is compatible with projects
11+
// that enable C++ interoperability mode.
12+
// See: https://github.com/swiftlang/swift-java/issues/391
13+
let cxxInteropEnabled = ProcessInfo.processInfo.environment["CXX_INTEROP"] == "1"
14+
715
let package = Package(
816
name: "JavaProbablyPrime",
917
platforms: [
@@ -34,7 +42,8 @@ let package = Package(
3442
.product(name: "ArgumentParser", package: "swift-argument-parser"),
3543
],
3644
swiftSettings: [
37-
.swiftLanguageMode(.v5)
45+
.swiftLanguageMode(.v5),
46+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
3847
],
3948
plugins: [
4049
.plugin(name: "SwiftJavaPlugin", package: "swift-java"),

Samples/JavaSieve/Package.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ let javaIncludePath = "\(javaHome)/include"
3939
#error("Currently only macOS and Linux platforms are supported, this may change in the future.")
4040
#endif
4141

42+
// Support C++ interoperability mode via CXX_INTEROP environment variable.
43+
// This is used to test that swift-java's public API is compatible with projects
44+
// that enable C++ interoperability mode.
45+
// See: https://github.com/swiftlang/swift-java/issues/391
46+
let cxxInteropEnabled = ProcessInfo.processInfo.environment["CXX_INTEROP"] == "1"
47+
4248
let package = Package(
4349
name: "JavaSieve",
4450
platforms: [
@@ -59,7 +65,8 @@ let package = Package(
5965
],
6066
exclude: ["swift-java.config"],
6167
swiftSettings: [
62-
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
68+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
69+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
6370
],
6471
plugins: [
6572
.plugin(name: "SwiftJavaPlugin", package: "swift-java"),
@@ -77,7 +84,8 @@ let package = Package(
7784
],
7885
exclude: ["swift-java.config"],
7986
swiftSettings: [
80-
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
87+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
88+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
8189
],
8290
plugins: [
8391
.plugin(name: "SwiftJavaPlugin", package: "swift-java"),

Samples/SwiftAndJavaJarSampleLib/Package.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ let javaIncludePath = "\(javaHome)/include"
4040
#error("Currently only macOS and Linux platforms are supported, this may change in the future.")
4141
#endif
4242

43+
// Support C++ interoperability mode via CXX_INTEROP environment variable.
44+
// This is used to test that swift-java's public API is compatible with projects
45+
// that enable C++ interoperability mode.
46+
// See: https://github.com/swiftlang/swift-java/issues/391
47+
let cxxInteropEnabled = ProcessInfo.processInfo.environment["CXX_INTEROP"] == "1"
48+
4349
let package = Package(
4450
name: "SwiftAndJavaJarSampleLib",
4551
platforms: [
@@ -70,7 +76,8 @@ let package = Package(
7076
],
7177
swiftSettings: [
7278
.swiftLanguageMode(.v5),
73-
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
79+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
80+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
7481
],
7582
plugins: [
7683
.plugin(name: "JExtractSwiftPlugin", package: "swift-java"),

Samples/SwiftJavaExtractFFMSampleApp/Package.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ let javaIncludePath = "\(javaHome)/include"
4040
#error("Currently only macOS and Linux platforms are supported, this may change in the future.")
4141
#endif
4242

43+
// Support C++ interoperability mode via CXX_INTEROP environment variable.
44+
// This is used to test that swift-java's public API is compatible with projects
45+
// that enable C++ interoperability mode.
46+
// See: https://github.com/swiftlang/swift-java/issues/391
47+
let cxxInteropEnabled = ProcessInfo.processInfo.environment["CXX_INTEROP"] == "1"
48+
4349
let package = Package(
4450
name: "SwiftJavaExtractFFMSampleApp",
4551
platforms: [
@@ -72,7 +78,8 @@ let package = Package(
7278
],
7379
swiftSettings: [
7480
.swiftLanguageMode(.v5),
75-
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
81+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
82+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
7683
],
7784
plugins: [
7885
.plugin(name: "JExtractSwiftPlugin", package: "swift-java"),

Samples/SwiftJavaExtractJNISampleApp/Package.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ let javaIncludePath = "\(javaHome)/include"
4040
#error("Currently only macOS and Linux platforms are supported, this may change in the future.")
4141
#endif
4242

43+
// Support C++ interoperability mode via CXX_INTEROP environment variable.
44+
// This is used to test that swift-java's public API is compatible with projects
45+
// that enable C++ interoperability mode.
46+
// See: https://github.com/swiftlang/swift-java/issues/391
47+
let cxxInteropEnabled = ProcessInfo.processInfo.environment["CXX_INTEROP"] == "1"
48+
4349
let package = Package(
4450
name: "JExtractJNISampleApp",
4551
platforms: [
@@ -70,6 +76,7 @@ let package = Package(
7076
swiftSettings: [
7177
.swiftLanguageMode(.v5),
7278
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
79+
.interoperabilityMode(.Cxx, .when(platforms: cxxInteropEnabled ? [.macOS, .linux] : [])),
7380
],
7481
plugins: [
7582
.plugin(name: "JExtractSwiftPlugin", package: "swift-java")

0 commit comments

Comments
 (0)