Skip to content

Commit 6052b73

Browse files
Duplicate e2e tests for Swift SDKs
Those files are copied from test/toolchain and modified to use the Swift SDK instead of the toolchain.
1 parent fac66aa commit 6052b73

File tree

22 files changed

+202
-6
lines changed

22 files changed

+202
-6
lines changed

.github/workflows/build-toolchain.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ jobs:
319319
name: ${{ matrix.target }}-test-results
320320
path: ./swift-test-results.tar.gz
321321

322+
- name: Run integration tests (Swift SDK)
323+
if: ${{ matrix.run_e2e_test && matrix.only_swift_sdk }}
324+
run: |
325+
docker exec swiftwasm-ci-buildbot /bin/bash -lc \
326+
"./llvm-project/llvm/utils/lit/lit.py \
327+
--param swift-sdk=wasm32-unknown-wasi \
328+
--param swift-sdks-path=./swiftwasm-build/tools/swift-sdk-generator/Bundles \
329+
--param scheme=main ./swiftwasm-build/test -vv"
330+
322331
- name: Cleanup docker volume
323332
if: ${{ matrix.container != null }}
324333
run: |

test/lit.cfg

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config.test_exec_root = lit_config.params.get(
2323
config.available_features.add("platform="+platform.system())
2424
config.available_features.add("scheme="+lit_config.params.get("scheme", "main"))
2525

26+
# --param package-path=PATH
2627
package_path = lit_config.params.get("package-path")
2728
if package_path:
2829
package_path = os.path.abspath(package_path)
@@ -31,6 +32,27 @@ else:
3132
lit_config.warning("'--param package-path=PATH' is not set, skipping toolchain tests")
3233
config.swift_package_path = package_path
3334

35+
# --param swift-sdk=<swift-sdk-id>
36+
swift_sdk = lit_config.params.get("swift-sdk")
37+
if swift_sdk:
38+
lit_config.note(f"testing Swift SDK: {swift_sdk}")
39+
else:
40+
lit_config.warning("'--param swift-sdk=<swift-sdk-id>' is not set, skipping Swift SDK tests")
41+
config.swift_sdk = swift_sdk
42+
43+
# --param swift-sdks-path=<swift-sdks-path>
44+
config.swift_sdks_path = lit_config.params.get("swift-sdks-path")
45+
46+
# --param base-toolchain-path=PATH
47+
base_toolchain_path = lit_config.params.get("base-toolchain-path")
48+
if base_toolchain_path:
49+
base_toolchain_path = os.path.abspath(base_toolchain_path)
50+
lit_config.note(f"using base toolchain: {base_toolchain_path}")
51+
else:
52+
base_toolchain_path = os.path.abspath(os.path.join(workspace_root, "build", "Packaging", "base-snapshot"))
53+
lit_config.note(f"using default base toolchain: {base_toolchain_path}")
54+
config.base_toolchain_path = base_toolchain_path
55+
3456
def llvm_tool_path(tool):
3557
candidates = []
3658
llvm_bin = lit_config.params.get("llvm-bin")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// swift-tools-version: 5.8
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "ClangModuleExample",
7+
targets: [
8+
.executableTarget(name: "Main", dependencies: ["_CModule"]),
9+
.target(name: "_CModule"),
10+
]
11+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import _CModule
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "_CModule.h"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <stddef.h> // Clang header should be found
2+
#if __wasi__
3+
# include <wasi/api.h> // wasi-libc header
4+
#endif
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module _CModule {
2+
header "_CModule.h"
3+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Foundation
2+
import XCTest
3+
import WASILibc
4+
5+
#if canImport(FoundationXML)
6+
import FoundationXML
7+
#endif
8+
// FIXME: This should be supported on swiftwasm branch
9+
// #if canImport(FoundationNetworking)
10+
// #error("FoundationNetworking should not be able to import now")
11+
// #endif
12+
13+
public func main() {
14+
_ = Date()
15+
_ = UUID()
16+
_ = URL(string: "https://example.com")!
17+
}

test/swift-sdk/clang-module.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: rm -rf %t.dir
2+
// RUN: mkdir -p %t.dir
3+
// RUN: %{swift} build --package-path %S/Inputs/clang-module-example --scratch-path %t.dir --triple wasm32-unknown-wasi --static-swift-stdlib
4+
5+
// Skipping this test on main until we include swift-testing in the SDK
6+
// REQUIRES: GH-5587
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %{target_simple_swift_build}
2+
// RUN: %{wasm_run} --dir %t.dir::/tmp --dir %t.dir::/tmp2 %t.dir/.build/debug/Check.wasm | %{FileCheck} %s
3+
// REQUIRES: FileCheck && scheme=main
4+
5+
import Foundation
6+
7+
// Bundle.main is derived from the path of the executable and cwd
8+
// CHECK: bundlePath: /tmp
9+
chdir("/tmp")
10+
print("bundlePath:", Bundle.main.bundlePath)
11+
12+
// CHECK: Bundle(path:).bundlePath: /tmp2
13+
print("Bundle(path:).bundlePath:", Bundle(path: "/tmp2")?.bundlePath ?? "nil")

0 commit comments

Comments
 (0)