-
Notifications
You must be signed in to change notification settings - Fork 653
/
Copy pathcheck-cxx-interop-compatibility.sh
executable file
·48 lines (38 loc) · 1.6 KB
/
check-cxx-interop-compatibility.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
log "Checking for Cxx interoperability compatibility..."
source_dir=$(pwd)
working_dir=$(mktemp -d)
project_name=$(basename "$working_dir")
source_file=Sources/$project_name/$(echo "$project_name" | tr . _).swift
library_products=$( swift package dump-package | jq -r '.products[] | select(.type.library != null) | .name')
package_name=$(swift package dump-package | jq -r '.name')
cd "$working_dir"
swift package init
{
echo "let swiftSettings: [SwiftSetting] = [.interoperabilityMode(.Cxx)]"
echo "for target in package.targets { target.swiftSettings = (target.swiftSettings ?? []) + swiftSettings }"
} >> Package.swift
echo "package.dependencies.append(.package(path: \"$source_dir\"))" >> Package.swift
for product in $library_products; do
echo "package.targets.first!.dependencies.append(.product(name: \"$product\", package: \"$package_name\"))" >> Package.swift
echo "import $product" >> "$source_file"
done
swift build
log "✅ Passed the Cxx interoperability tests."