Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no_std support #39

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[target.wasm32-unknown-unknown]
[target.'cfg(target_family = "wasm")']
runner = "wasm-bindgen-test-runner"
4 changes: 3 additions & 1 deletion .config/topic.dic
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
23
25
1G
1M
1ns
allocator
APIs
Atomics
de
Expand All @@ -12,6 +13,7 @@ io
JS
MDN
MSRV
representable
Serde
Serde's
timestamps
Expand Down
148 changes: 148 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Build

on:
push:
branches: ["main"]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
build:
name:
Build ${{ matrix.target.description }} ${{ matrix.rust.description }} ${{
matrix.features.description }}

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
target:
- { target: x86_64-unknown-linux-gnu, description: Native }
- { target: wasm32-unknown-unknown, description: Web }
- { target: wasm32v1-none, description: Wasm v1 }
rust:
- { version: "1.60", description: MSRV, atomics: false }
- { version: stable, atomics: false }
- { version: nightly, atomics: false }
- {
version: nightly,
description: with Atomics,
atomics: true,
component: --component rust-src,
flags: "-Ctarget-feature=+atomics,+bulk-memory",
build-std: true,
}
features:
- { features: "", no_std: false }
- { features: --features serde, no_std: false, description: (`serde`) }
- { features: --no-default-features, no_std: true, description: (`no_std`) }
- {
features: --no-default-features --features serde,
no_std: true,
description: "(`no_std`, `serde`)",
}
exclude:
- target: { target: x86_64-unknown-linux-gnu, description: Native }
rust: { version: nightly }
- target: { target: wasm32-unknown-unknown, description: Web }
rust: { version: nightly, atomics: false }
- target: { target: wasm32v1-none, description: Wasm v1 }
rust: { version: "1.60" }
- target: { target: wasm32v1-none, description: Wasm v1 }
rust: { version: stable }
- target: { target: wasm32v1-none, description: Wasm v1 }
features: { no_std: false }

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install ${{ matrix.rust.version }} --profile minimal ${{ matrix.rust.component }} --target ${{ matrix.target.target }}
rustup default ${{ matrix.rust.version }}
- name: Set `build-std` components
if: matrix.rust.build-std == true && matrix.features.no_std == false
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=panic_abort,std" >> $GITHUB_ENV
- name: Set `build-std` `no_std` components
if: matrix.rust.build-std == true && matrix.features.no_std == true
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
- name: Fix MSRV dependencies
if: matrix.rust.version == '1.60'
run: |
cargo update -p bumpalo --precise 3.14.0
cargo update -p serde --precise 1.0.210
cargo update -p syn --precise 2.0.67
- name: Build
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
run:
cargo build ${{ matrix.features.features }} --target ${{ matrix.target.target }}
$BUILD_STD_COMPONENTS

minimal-versions:
name:
Minimal Versions ${{ matrix.target.description }} ${{ matrix.rust.description }} ${{
matrix.features.description }}

runs-on: ubuntu-latest

defaults:
run:
working-directory: minimal-versions

strategy:
fail-fast: false
matrix:
target:
- { target: x86_64-unknown-linux-gnu, description: Native }
- { target: wasm32-unknown-unknown, description: Web }
- { target: wasm32v1-none, description: Wasm v1 }
rust:
- { version: "1.60", description: MSRV }
- { version: stable }
- { version: nightly }
features:
- { features: "", no_std: false }
- { features: --features serde, no_std: false, description: (`serde`) }
- { features: --no-default-features, no_std: true, description: (`no_std`) }
- {
features: --no-default-features --features serde,
no_std: true,
description: "(`no_std`, `serde`)",
}
exclude:
- target: { target: x86_64-unknown-linux-gnu, description: Native }
rust: { version: nightly }
- target: { target: wasm32-unknown-unknown, description: Web }
rust: { version: nightly }
- target: { target: wasm32v1-none, description: Wasm v1 }
rust: { version: "1.60" }
- target: { target: wasm32v1-none, description: Wasm v1 }
rust: { version: stable }
- target: { target: wasm32v1-none, description: Wasm v1 }
features: { no_std: false }

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install ${{ matrix.rust.version }} --profile minimal --target ${{ matrix.target.target }}
rustup default ${{ matrix.rust.version }}
- name: Downgrade to minimal versions
run: |
rustup toolchain install nightly --profile minimal
cargo +nightly update -Z minimal-versions
- name: Fix Rust nightly incompatible dependencies
if: matrix.rust.version == 'nightly'
run: |
cargo update -p proc-macro2 --precise 1.0.60
- name: Build
run: cargo build ${{ matrix.features.features }} --target ${{ matrix.target.target }}
64 changes: 34 additions & 30 deletions .github/workflows/coverage-documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:

jobs:
coverage:
name: Test Coverage ${{ matrix.mt.description }}
name: Test Coverage ${{ matrix.mt.description }} ${{ matrix.features.description }}

runs-on: ubuntu-latest

Expand All @@ -24,15 +24,24 @@ jobs:
strategy:
matrix:
mt:
- { id: 0 }
- { id: "st" }
- {
id: 1,
id: "mt",
description: with Atomics,
component: --component rust-src,
cflags: -matomics -mbulk-memory,
flags: "-Ctarget-feature=+atomics,+bulk-memory",
args: "-Zbuild-std=panic_abort,std",
build-std: true,
}
features:
- { id: "", features: "", no_std: false }
- { id: -no_std, features: --no-default-features, no_std: true, description: (`no_std`) }

env:
CFLAGS_wasm32_unknown_unknown: ${{ matrix.mt.cflags }}
RUSTFLAGS:
-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir
--cfg=wasm_bindgen_unstable_test_coverage ${{ matrix.mt.flags }}

steps:
- name: Checkout
Expand All @@ -50,31 +59,25 @@ jobs:
run: |
rustup toolchain install nightly --profile minimal --target wasm32-unknown-unknown ${{ matrix.mt.component }}
rustup default nightly
- name: Set `build-std` components
if: matrix.mt.build-std == true && matrix.features.no_std == false
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=panic_abort,std" >> $GITHUB_ENV
- name: Set `build-std` `no_std` components
if: matrix.mt.build-std == true && matrix.features.no_std == true
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
- name: Test
env:
CHROMEDRIVER: chromedriver
CFLAGS_wasm32_unknown_unknown: ${{ matrix.mt.cflags }}
CARGO_HOST_RUSTFLAGS: --cfg=wasm_bindgen_unstable_test_coverage
RUSTFLAGS:
-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir
--cfg=wasm_bindgen_unstable_test_coverage ${{ matrix.mt.flags }}
WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT: coverage-output
run: |
mkdir coverage-output
cargo test --all-features --target wasm32-unknown-unknown -Ztarget-applies-to-host -Zhost-config ${{ matrix.mt.args }} --tests
WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT=$(realpath coverage-output) cargo test --workspace --features serde --target wasm32-unknown-unknown $BUILD_STD_COMPONENTS ${{ matrix.features.features }} --tests
- name: Prepare Object Files
env:
CFLAGS_wasm32_unknown_unknown: ${{ matrix.mt.cflags }}
CARGO_HOST_RUSTFLAGS: --cfg=wasm_bindgen_unstable_test_coverage
RUSTFLAGS:
-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir
--cfg=wasm_bindgen_unstable_test_coverage ${{ matrix.mt.flags }}
run: |
mkdir coverage-input
crate_name=web_time
IFS=$'\n'
for file in $(
cargo test --all-features --target wasm32-unknown-unknown -Ztarget-applies-to-host -Zhost-config ${{ matrix.mt.args }} --tests --no-run --message-format=json | \
cargo test --workspace --features serde --target wasm32-unknown-unknown $BUILD_STD_COMPONENTS ${{ matrix.features.features }} --tests --no-run --message-format=json | \
jq -r "select(.reason == \"compiler-artifact\") | (select(.target.kind == [\"test\"]) // select(.target.name == \"$crate_name\")) | .filenames[0]"
)
do
Expand All @@ -90,7 +93,7 @@ jobs:
- name: Upload Test Coverage Artifact
uses: actions/upload-artifact@v4
with:
name: test-coverage-${{ matrix.mt.id }}
name: test-coverage-${{ matrix.mt.id }}${{ matrix.features.id }}
path: coverage-output
retention-days: 1
if-no-files-found: error
Expand All @@ -105,20 +108,22 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install LLVM v19
- name: Install Rust nightly
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main"
sudo apt-get install llvm-19
rustup toolchain install nightly --profile minimal --component llvm-tools
rustup default nightly
- name: Install `cargo-binutils`
uses: taiki-e/install-action@v2
with:
tool: cargo-binutils
- name: Download Test Coverage
uses: actions/download-artifact@v4
with:
pattern: test-coverage-*
path: coverage-input
- name: Merge Profile Data
run:
llvm-profdata-19 merge -sparse coverage-input/*/*.profraw -o
coverage-input/coverage.profdata
rust-profdata merge -sparse coverage-input/*/*.profraw -o coverage-input/coverage.profdata
- name: Export Code Coverage Report
run: |
mkdir coverage-output
Expand All @@ -127,16 +132,15 @@ jobs:
do
objects+=(-object $file)
done
llvm-cov-19 show -show-instantiations=false -output-dir coverage-output -format=html -instr-profile=coverage-input/coverage.profdata ${objects[@]} -sources src
llvm-cov-19 export -format=text -summary-only -instr-profile=coverage-input/coverage.profdata ${objects[@]} -sources src | \
rust-cov show -show-instantiations=false -output-dir coverage-output -format=html -instr-profile=coverage-input/coverage.profdata ${objects[@]} -sources src
rust-cov export -format=text -summary-only -instr-profile=coverage-input/coverage.profdata ${objects[@]} -sources src | \
printf '{ "coverage": "%.2f%%" }' $(jq '.data[0].totals.functions.percent') > coverage-output/coverage.json
sed 's/<!doctype html>//' coverage-output/index.html | perl -p0e 's/<a[^>]*>((?!here).*?)<\/a>/$1/g' >> $GITHUB_STEP_SUMMARY
sed 's/<!doctype html>//' coverage-output/index.html | sed "s/<script src='control.js'><\/script>//" | perl -p0e 's/<a[^>]*>((?!here).*?)<\/a>/$1/g' >> $GITHUB_STEP_SUMMARY
- name: Upload Test Coverage Artifact
uses: actions/upload-artifact@v4
with:
name: test-coverage
path: coverage-output
retention-days: 1
if-no-files-found: error

document:
Expand All @@ -158,7 +162,7 @@ jobs:
RUSTDOCFLAGS: --crate-version main --cfg=docsrs
run:
cargo doc --no-deps -Z rustdoc-map -Z rustdoc-scrape-examples --target
wasm32-unknown-unknown --all-features
wasm32-unknown-unknown --features serde
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Fix permissions
Expand Down
Loading
Loading