Skip to content

Commit 6e729d2

Browse files
Prevents coupling UTF-16 text value encodings to WASM targets (#198)
* migrate from wasm32-wasi to wasm32-wasip1-threads * wasm: introduce test cases to verify the integrity between platforms * ci: running unit tests over wasm * tests: making unit-tests compatible with wasm * propagate cursor exceptions * rust: define features for automerge wasi * update cargo lock * generate wasm library using wasm32-wasip1 and wasm32-wasip1-threads * propagate automerge rust changes to uniffi * ci: split dependencies from job of running tests * running tests using wasm32-wasip1 * bump to automerge core 0.5.12 * forcing xcode 15.4 * ci: fix cache toolchain key check
1 parent 4159e71 commit 6e729d2

18 files changed

+2014
-1539
lines changed

.github/workflows/ci.yaml

+93-28
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,123 @@ on:
66
branches: [main]
77

88
jobs:
9-
build-test:
9+
10+
automerge-dependencies:
1011
runs-on: macos-14
1112
env:
1213
LOCAL_BUILD: true
1314
DEVELOPER_DIR: /Applications/Xcode_15.4.app
15+
concurrency:
16+
group: automerge-dependencies-${{ github.head_ref || github.run_id }}
17+
cancel-in-progress: true
1418
steps:
15-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
20+
- name: Cache Automerge XCFramework and library
21+
id: cache-automerge
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
automergeFFI.xcframework
26+
automergeFFI.xcframework.zip
27+
libuniffi_automerge.a
28+
libuniffi_automerge_threads.a
29+
key: automerge-dependencies-{{ hashFiles(AutomergeUniffi/automerge.swift) }}-{{ hashFiles(rust/Cargo.lock) }}
1630
- uses: actions-rs/toolchain@v1
1731
with:
1832
profile: minimal
19-
toolchain: 1.78.0
33+
toolchain: 1.81.0
2034
default: true
21-
- name: get xcode information
22-
run: |
23-
xcodebuild -version
24-
swift --version
25-
- name: build xcframework
35+
- name: Select Xcode 15.4
36+
run: sudo xcode-select -s /Applications/Xcode_15.4.app
37+
- name: Build Automerge XCFramework and library
38+
if: steps.cache-automerge.outputs.cache-hit != 'true'
2639
run: ./scripts/build-xcframework.sh
27-
- name: compress framework
40+
- name: Compress Automerge XCFramework
41+
if: steps.cache-automerge.outputs.cache-hit != 'true'
2842
run: ./scripts/compress-framework.sh
43+
- uses: actions/upload-artifact@v4
44+
if: steps.cache-automerge.outputs.cache-hit != 'true'
45+
with:
46+
name: libuniffi_automerge
47+
path: |
48+
libuniffi_automerge.a
49+
libuniffi_automerge_threads.a
50+
51+
mac:
52+
runs-on: macos-14
53+
needs: automerge-dependencies
54+
steps:
55+
- uses: actions/checkout@v4
56+
- name: Select Xcode 15.4
57+
run: sudo xcode-select -s /Applications/Xcode_15.4.app
58+
- name: Restore Automerge XCFramework and library
59+
uses: actions/cache/restore@v4
60+
with:
61+
path: |
62+
automergeFFI.xcframework
63+
automergeFFI.xcframework.zip
64+
libuniffi_automerge.a
65+
libuniffi_automerge_threads.a
66+
key: automerge-dependencies-{{ hashFiles(AutomergeUniffi/automerge.swift) }}-{{ hashFiles(rust/Cargo.lock) }}
67+
- name: Get swift version
68+
run: swift --version
2969
- name: Swift tests
3070
run: swift test
3171

32-
build-wasm32-unknown-wasi:
72+
wasm:
3373
runs-on: ubuntu-latest
74+
needs: automerge-dependencies
75+
strategy:
76+
matrix:
77+
include:
78+
- toolchain: swift-DEVELOPMENT-SNAPSHOT-2024-10-08-a
79+
swift-sdk: swift-wasm-DEVELOPMENT-SNAPSHOT-2024-10-15-a
80+
checksum: 229cd9d3b0ed582c7ef7c3064888ad78764e4743b5a770df92554a94513f53fb
3481
steps:
3582
- uses: actions/checkout@v4
36-
- uses: actions-rs/toolchain@v1
37-
with:
38-
profile: minimal
39-
toolchain: 1.78.0
40-
default: true
41-
- run: rustup target add wasm32-wasi
42-
- uses: swiftwasm/setup-swiftwasm@v1
83+
- uses: bytecodealliance/actions/wasmtime/setup@v1
84+
- name: Restore Automerge XCFramework and library
85+
uses: actions/cache/restore@v4
4386
with:
44-
swift-version: "wasm-5.9.1-RELEASE"
45-
#- run: cargo build --manifest-path rust/Cargo.toml --target wasm32-wasi --release
46-
- run: scripts/ci/wasi-regen-swift.sh
47-
- uses: actions/upload-artifact@v4
87+
path: |
88+
automergeFFI.xcframework
89+
automergeFFI.xcframework.zip
90+
libuniffi_automerge.a
91+
libuniffi_automerge_threads.a
92+
key: automerge-dependencies-{{ hashFiles(AutomergeUniffi/automerge.swift) }}-{{ hashFiles(rust/Cargo.lock) }}
93+
- name: Cache Toolchain for WebAssembly
94+
id: cache-wasm-toolchain
95+
uses: actions/cache@v4
4896
with:
49-
name: libuniffi_automerge-wasm32-unknown-wasi.a
50-
path: ./rust/target/wasm32-wasi/release/libuniffi_automerge.a
51-
- run: swift build --triple wasm32-unknown-wasi
97+
path: /tmp/swift-toolchain.tar.gz
98+
key: wasm-toolchain-${{ matrix.checksum }}
99+
- name: Download Toolchain for WebAssembly
100+
if: steps.cache-wasm-toolchain.outputs.cache-hit != 'true'
101+
run: |
102+
SWIFT_TOOLCHAIN_TAG="${{ matrix.toolchain }}"
103+
set -ex
104+
curl -f -o /tmp/swift-toolchain.tar.gz "https://download.swift.org/development/ubuntu2204/$SWIFT_TOOLCHAIN_TAG/$SWIFT_TOOLCHAIN_TAG-ubuntu22.04.tar.gz"
105+
- name: Install Swift and Swift SDK for WebAssembly
106+
run: |
107+
PREFIX=/opt/swift
108+
SWIFT_SDK_TAG="${{ matrix.swift-sdk }}"
109+
set -ex
110+
sudo mkdir -p $PREFIX; sudo tar -xzf /tmp/swift-toolchain.tar.gz -C $PREFIX --strip-component 1
111+
$PREFIX/usr/bin/swift sdk install "https://github.com/swiftwasm/swift/releases/download/$SWIFT_SDK_TAG/$SWIFT_SDK_TAG-wasm32-unknown-wasi.artifactbundle.zip" --checksum ${{ matrix.checksum }}
112+
echo "$PREFIX/usr/bin" >> $GITHUB_PATH
113+
- name: Build tests
114+
run: swift build --swift-sdk wasm32-unknown-wasi --build-tests -Xlinker "`pwd`/libuniffi_automerge.a" -Xlinker -z -Xlinker stack-size=$((1024 * 1024))
115+
- name: Run tests
116+
run: wasmtime run --wasm max-wasm-stack=$((1024 * 1024)) --dir . .build/debug/AutomergePackageTests.wasm
52117

53118
rustfmt:
54119
runs-on: macos-latest
55120
steps:
56-
- uses: actions/checkout@v3
121+
- uses: actions/checkout@v4
57122
- uses: actions-rs/toolchain@v1
58123
with:
59124
profile: minimal
60-
toolchain: 1.78.0
125+
toolchain: 1.81.0
61126
default: true
62127
components: rustfmt
63128
- name: Clippy
@@ -66,11 +131,11 @@ jobs:
66131
clippy:
67132
runs-on: macos-latest
68133
steps:
69-
- uses: actions/checkout@v3
134+
- uses: actions/checkout@v4
70135
- uses: actions-rs/toolchain@v1
71136
with:
72137
profile: minimal
73-
toolchain: 1.78.0
138+
toolchain: 1.81.0
74139
default: true
75140
components: clippy
76141
- name: Clippy

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
.vscode
66
# generated WebAssembly library from build scripts
77
libuniffi_automerge.a
8+
libuniffi_automerge_threads.a
89

910
# generated by the UniFFI build process and replicated into repos,
1011
# but not stored directly, since they're generated

0 commit comments

Comments
 (0)