Skip to content

Commit d291523

Browse files
committed
feat: add fixed-length list support and update related functionality
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent 3a6404f commit d291523

20 files changed

Lines changed: 269 additions & 51 deletions

File tree

‎.github/workflows/macos.yml‎

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
name: MacOS
22

3-
# Disabled: Known to fail
4-
# To re-enable, uncomment the 'on:' section below
53
on:
6-
workflow_dispatch: # Manual trigger only
7-
# push:
8-
# branches:
9-
# - trunk
10-
# - main
11-
# pull_request:
12-
# branches:
13-
# - trunk
14-
# - main
4+
push:
5+
branches:
6+
- trunk
7+
- main
8+
pull_request:
9+
branches:
10+
- trunk
11+
- main
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}
16+
cancel-in-progress: true
1517

1618
env:
1719
CTEST_OUTPUT_ON_FAILURE: 1
@@ -22,7 +24,7 @@ jobs:
2224
matrix:
2325
include:
2426
# - os: "macos-13"
25-
- os: "macos-14"
27+
- os: "macos-latest"
2628
fail-fast: false
2729

2830
runs-on: ${{ matrix.os }}
@@ -43,15 +45,13 @@ jobs:
4345
target/
4446
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4547

46-
- name: Cache vcpkg registry
47-
uses: actions/cache@v4
48+
- name: Restore vcpkg registry
49+
uses: actions/cache/restore@v4
4850
with:
4951
path: |
5052
build/vcpkg_installed/
5153
build/vcpkg_packages/
52-
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
53-
restore-keys: |
54-
${{ runner.os }}-vcpkg-
54+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json', './vcpkg_overlays/**') }}
5555

5656
- name: install dependencies
5757
run: |
@@ -65,6 +65,25 @@ jobs:
6565
run: |
6666
cmake --preset linux-ninja-Debug
6767
68+
- name: Fix WASI SDK macOS compiler
69+
run: |
70+
wasi_sdk="${GITHUB_WORKSPACE}/build/vcpkg_installed/arm64-osx/wasi-sdk"
71+
if [[ -f "${wasi_sdk}/libexec/libclang-cpp.dylib" && ! -f "${wasi_sdk}/lib/libclang-cpp.dylib" ]]; then
72+
cp "${wasi_sdk}/libexec/libclang-cpp.dylib" "${wasi_sdk}/lib/libclang-cpp.dylib"
73+
fi
74+
if [[ -f "${wasi_sdk}/libexec/libLLVM.dylib" && ! -f "${wasi_sdk}/lib/libLLVM.dylib" ]]; then
75+
cp "${wasi_sdk}/libexec/libLLVM.dylib" "${wasi_sdk}/lib/libLLVM.dylib"
76+
fi
77+
while IFS= read -r -d '' binary; do
78+
if file "${binary}" | grep -q 'Mach-O'; then
79+
install_name_tool -delete_rpath "@loader_path/../../lib" "${binary}" || true
80+
install_name_tool -add_rpath "@loader_path/../lib" "${binary}" || true
81+
fi
82+
done < <(find "${wasi_sdk}/bin" "${wasi_sdk}/lib" -type f -print0)
83+
test -f "${wasi_sdk}/lib/libclang-cpp.dylib"
84+
test -f "${wasi_sdk}/lib/libLLVM.dylib"
85+
"${wasi_sdk}/bin/clang" --version
86+
6887
- name: build
6988
run: |
7089
cmake --build --preset linux-ninja-Debug
@@ -81,6 +100,15 @@ jobs:
81100
echo "Running wit-stub-generation-test (failures expected and will be reported)..."
82101
ctest -VV -R "wit-stub-generation-test"
83102
103+
- name: Save vcpkg registry
104+
if: always()
105+
uses: actions/cache/save@v4
106+
with:
107+
path: |
108+
build/vcpkg_installed/
109+
build/vcpkg_packages/
110+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json', './vcpkg_overlays/**') }}
111+
84112
- name: Upload error logs
85113
if: ${{ failure() || cancelled() }}
86114
uses: actions/upload-artifact@v4

‎.github/workflows/release.yml‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
tags:
66
- "v*.*.*"
77

8+
concurrency:
9+
group: ${{ github.workflow }}
10+
cancel-in-progress: true
11+
812
env:
913
CTEST_OUTPUT_ON_FAILURE: 1
1014

@@ -93,9 +97,8 @@ jobs:
9397
target/
9498
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
9599

96-
- name: Cache vcpkg registry
97-
if: always()
98-
uses: actions/cache@v4
100+
- name: Restore vcpkg registry
101+
uses: actions/cache/restore@v4
99102
with:
100103
path: |
101104
build/vcpkg_installed/
@@ -116,6 +119,15 @@ jobs:
116119
run: |
117120
cmake --build --preset ${{ matrix.build-preset }}
118121
122+
- name: Save vcpkg registry
123+
if: always()
124+
uses: actions/cache/save@v4
125+
with:
126+
path: |
127+
build/vcpkg_installed/
128+
build/vcpkg_packages/
129+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
130+
119131
- name: Create Packages
120132
working-directory: build
121133
run: |

‎.github/workflows/ubuntu.yml‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
- main
1212
workflow_dispatch:
1313

14+
concurrency:
15+
group: ${{ github.workflow }}
16+
cancel-in-progress: true
17+
1418
env:
1519
CTEST_OUTPUT_ON_FAILURE: 1
1620
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
@@ -26,6 +30,7 @@ jobs:
2630
matrix:
2731
include:
2832
- os: "ubuntu-24.04"
33+
- os: "ubuntu-26.04"
2934
fail-fast: false
3035

3136
runs-on: ${{ matrix.os }}
@@ -44,18 +49,17 @@ jobs:
4449
~/.cargo/registry/cache/
4550
~/.cargo/git/db/
4651
target/
47-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
52+
key: ${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4853

49-
- name: Cache vcpkg registry
50-
if: always()
51-
uses: actions/cache@v4
54+
- name: Restore vcpkg registry
55+
uses: actions/cache/restore@v4
5256
with:
5357
path: |
5458
build/vcpkg_installed/
5559
build/vcpkg_packages/
56-
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
60+
key: ${{ matrix.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
5761
restore-keys: |
58-
${{ runner.os }}-vcpkg-
62+
${{ matrix.os }}-vcpkg-
5963
6064
- name: install dependencies
6165
run: |
@@ -89,6 +93,15 @@ jobs:
8993
with:
9094
token: ${{ secrets.CODECOV_TOKEN }}
9195

96+
- name: Save vcpkg registry
97+
if: always()
98+
uses: actions/cache/save@v4
99+
with:
100+
path: |
101+
build/vcpkg_installed/
102+
build/vcpkg_packages/
103+
key: ${{ matrix.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
104+
92105
- name: Upload error logs
93106
if: ${{ failure() || cancelled() }}
94107
uses: actions/upload-artifact@v4

‎.github/workflows/windows.yml‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
- main
1212
workflow_dispatch:
1313

14+
concurrency:
15+
group: ${{ github.workflow }}
16+
cancel-in-progress: true
17+
1418
env:
1519
CTEST_OUTPUT_ON_FAILURE: 1
1620

@@ -48,8 +52,8 @@ jobs:
4852
target/
4953
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
5054

51-
- name: Cache vcpkg registry
52-
uses: actions/cache@v4
55+
- name: Restore vcpkg registry
56+
uses: actions/cache/restore@v4
5357
with:
5458
path: |
5559
build/vcpkg_installed/
@@ -89,6 +93,15 @@ jobs:
8993
Set-Location "$env:SHORT_WORKSPACE/build"
9094
& ctest -C Debug -VV
9195
96+
- name: Save vcpkg registry
97+
if: always()
98+
uses: actions/cache/save@v4
99+
with:
100+
path: |
101+
build/vcpkg_installed/
102+
build/vcpkg_packages/
103+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
104+
92105
- name: Remove short workspace mapping
93106
if: always()
94107
run: |

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ This repository contains a C++ ABI implementation of the WebAssembly Component M
1616

1717
### OS
1818
- [x] Ubuntu 24.04
19-
- [ ] MacOS 13
20-
- [ ] MacOS 14 (Arm)
19+
- [x] Ubuntu 26.04
20+
- [x] macOS (latest, builds and passes tests)
2121
- [ ] Windows 2019
2222
- [x] Windows 2022
2323

@@ -36,6 +36,7 @@ This repository contains a C++ ABI implementation of the WebAssembly Component M
3636
- [x] Char
3737
- [x] Strings (UTF-8, UTF-16, Latin-1+UTF-16)
3838
- [x] List
39+
- [x] Fixed-length list (`cmcpp::fixed_list_t<T, N>`)
3940
- [x] Map
4041
- [x] Record
4142
- [x] Tuple

‎docs/spec-alignment.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
This document tracks alignment between the upstream Component Model spec/reference (in `ref/component-model`) and this library’s C++ entrypoints.
44

5+
- Upstream baseline: `2bed77e4228841c1d2721996d3ecc169ff96b158`
56
- Upstream references:
67
- `ref/component-model/design/mvp/CanonicalABI.md`
78
- `ref/component-model/design/mvp/Concurrency.md`
@@ -53,11 +54,11 @@ This document tracks alignment between the upstream Component Model spec/referen
5354

5455
## Thread built-ins (upstream)
5556

56-
These are referenced by the upstream spec/reference but do not currently have direct C++ canonical built-in entrypoints in this repo:
57+
These additional thread built-ins are implemented by direct C++ canonical entrypoints:
5758

58-
- `thread.new_ref` / `thread.new-ref` (implemented: `cmcpp::canon_thread_new_ref`)
59-
- `thread.new-indirect` (implemented: `cmcpp::canon_thread_new_indirect`)
60-
- `thread.spawn-ref` (implemented: `cmcpp::canon_thread_spawn_ref`)
61-
- `thread.spawn-indirect` (implemented: `cmcpp::canon_thread_spawn_indirect`)
62-
- `thread.switch-to` (implemented: `cmcpp::canon_thread_switch_to`)
63-
- `thread.available-parallelism` (implemented: `cmcpp::canon_thread_available_parallelism`)
59+
- `thread.new-ref`: `cmcpp::canon_thread_new_ref`
60+
- `thread.new-indirect`: `cmcpp::canon_thread_new_indirect`
61+
- `thread.spawn-ref`: `cmcpp::canon_thread_spawn_ref`
62+
- `thread.spawn-indirect`: `cmcpp::canon_thread_spawn_indirect`
63+
- `thread.switch-to`: `cmcpp::canon_thread_switch_to`
64+
- `thread.available-parallelism`: `cmcpp::canon_thread_available_parallelism`

‎grammar/Wit.g4‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ importItem
5757
externType
5858
: funcType ';'
5959
| 'interface' '{' interfaceItems* '}'
60+
| usePath ';'
6061
;
6162

6263
// Item: include ---
@@ -352,6 +353,9 @@ keyword
352353
Identifier: LETTER (LETTER | DIGIT | '-')*
353354
;
354355

356+
NUM_ID: '0' | POSITIVE_DIGIT | POSITIVE_DIGIT DIGITS
357+
;
358+
355359
// Semver: https://semver.org/
356360
VALID_SEMVER
357361
: VERSION_CORE
@@ -401,9 +405,6 @@ ALPHANUM_ID
401405
| ID_CHARS NON_DIGIT ID_CHARS
402406
;
403407

404-
NUM_ID: '0' | POSITIVE_DIGIT | POSITIVE_DIGIT DIGITS
405-
;
406-
407408
ID_CHARS: ID_CHAR | ID_CHAR ID_CHARS
408409
;
409410

‎include/cmcpp.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <cmcpp/tuple.hpp>
1313
#include <cmcpp/record.hpp>
1414
#include <cmcpp/list.hpp>
15+
#include <cmcpp/fixed_list.hpp>
1516
#include <cmcpp/map.hpp>
1617
#include <cmcpp/variant.hpp>
1718
#include <cmcpp/func.hpp>

‎include/cmcpp/fixed_list.hpp‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef CMCPP_FIXED_LIST_HPP
2+
#define CMCPP_FIXED_LIST_HPP
3+
4+
#include "context.hpp"
5+
#include "lift.hpp"
6+
#include "load.hpp"
7+
#include "lower.hpp"
8+
#include "store.hpp"
9+
10+
namespace cmcpp
11+
{
12+
template <FixedList T>
13+
inline void store(LiftLowerContext &cx, const T &values, uint32_t ptr)
14+
{
15+
using Element = typename ValTrait<T>::inner_type;
16+
for (size_t i = 0; i < values.size(); ++i)
17+
{
18+
cmcpp::store(cx, values[i], ptr + i * ValTrait<Element>::size);
19+
}
20+
}
21+
22+
template <FixedList T>
23+
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &values)
24+
{
25+
WasmValVector flat;
26+
flat.reserve(ValTrait<T>::flat_types_len);
27+
for (const auto &value : values)
28+
{
29+
auto element_flat = cmcpp::lower_flat(cx, value);
30+
flat.insert(flat.end(), element_flat.begin(), element_flat.end());
31+
}
32+
return flat;
33+
}
34+
35+
template <FixedList T>
36+
inline T load(const LiftLowerContext &cx, uint32_t ptr)
37+
{
38+
using Element = typename ValTrait<T>::inner_type;
39+
T values{};
40+
for (size_t i = 0; i < values.size(); ++i)
41+
{
42+
values[i] = cmcpp::load<Element>(cx, ptr + i * ValTrait<Element>::size);
43+
}
44+
return values;
45+
}
46+
47+
template <FixedList T>
48+
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
49+
{
50+
using Element = typename ValTrait<T>::inner_type;
51+
T values{};
52+
for (auto &value : values)
53+
{
54+
value = cmcpp::lift_flat<Element>(cx, vi);
55+
}
56+
return values;
57+
}
58+
}
59+
60+
#endif

‎include/cmcpp/lift.hpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ namespace cmcpp
2828
template <List T>
2929
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi);
3030

31+
template <FixedList T>
32+
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi);
33+
3134
template <Flags T>
3235
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi);
3336

0 commit comments

Comments
 (0)