diff --git a/.cargo/config.toml b/.cargo/config.toml index 6b509f5..4e547e5 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ -[build] -target = "wasm32-wasip1" +[alias] +xtask = "run --package xtask --release --" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cb9ef59 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,82 @@ +name: CI +on: + push: + branches: + - master + pull_request: + branches: + - master + +env: + XTASK_WASI_SDK_VERSION: 24 + XTASK_BINARYEN_VERSION: 119 + XTASK_TYPST_VERSION: 0.12.0 + XTASK_WORK_DIR: ./ci_work_dir + +jobs: + test: + name: Build Typst Plugin + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-wasip1 + - name: Restore WASI SDK + uses: actions/cache/restore@v4 + with: + path: ci_work_dir/wasi_sdk + key: tools-wasi-sdk-${{ env.XTASK_WASI_SDK_VERSION }} + - name: Restore wasi-stub + uses: actions/cache/restore@v4 + with: + path: | + zint-typst-plugin/vendor/wasm-minimal-protocol/target/release/wasi-stub + zint-typst-plugin/vendor/wasm-minimal-protocol/target/debug/wasi-stub + key: tools-wasi-stub-${{ hashFiles('zint-typst-plugin/vendor/wasm-minimal-protocol/crates/wasi-stub/**') }} + - name: Restore wasm-opt + uses: actions/cache/restore@v4 + with: + path: ci_work_dir/tools/wasm-opt + key: tools-binaryen-${{ env.XTASK_BINARYEN_VERSION }} + - name: Restore typst + uses: actions/cache/restore@v4 + with: + path: ci_work_dir/tools/typst + key: tools-typst-${{ env.XTASK_TYPST_VERSION }} + - name: Run CI xtask + run: cargo xtask ci + - name: Cache WASI SDK + uses: actions/cache/save@v4 + with: + path: ci_work_dir/wasi_sdk + key: tools-wasi-sdk-${{ env.XTASK_WASI_SDK_VERSION }} + - name: Cache wasi-stub + uses: actions/cache/save@v4 + with: + path: | + zint-typst-plugin/vendor/wasm-minimal-protocol/target/release/wasi-stub + zint-typst-plugin/vendor/wasm-minimal-protocol/target/debug/wasi-stub + key: tools-wasi-stub-${{ hashFiles('zint-typst-plugin/vendor/wasm-minimal-protocol/crates/wasi-stub/**') }} + - name: Cache wasm-opt + uses: actions/cache/save@v4 + with: + path: ci_work_dir/tools/wasm-opt + key: tools-binaryen-${{ env.XTASK_BINARYEN_VERSION }} + - name: Cache typst + uses: actions/cache/save@v4 + with: + path: ci_work_dir/tools/typst + key: tools-typst-${{ env.XTASK_TYPST_VERSION }} + - uses: actions/upload-artifact@v4 + with: + name: plugin-wasm + path: ./typst-package/zint_typst_plugin.wasm + retention-days: 7 + - uses: actions/upload-artifact@v4 + with: + name: manual + path: ./typst-package/manual.pdf + retention-days: 7 diff --git a/.gitignore b/.gitignore index d6b8394..a38906f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,4 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk - -# CMake build files -build/ - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb - +### C ### # Prerequisites *.d @@ -53,6 +36,7 @@ build/ *.i*86 *.x86_64 *.hex +*.wasm # Debug files *.dSYM/ @@ -60,16 +44,78 @@ build/ *.idb *.pdb -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf -license.html -*.wasm +# Build files +build/ + +# Cache +.cache + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# Backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Windows shortcuts +*.lnk + +### Project ### +# Compiled documents *.pdf +# Generated files +typst-package/3rdparty_license.html +typst-package/example.svg + +# Duplicate license +typst-package/LICENSE + +# Keep manual !typst-package/manual.pdf diff --git a/.gitmodules b/.gitmodules index 8f77cac..82023c2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "zint-wasm-sys/zint"] path = zint-wasm-sys/zint url = https://github.com/zint/zint +[submodule "zint-typst-plugin/vendor/wasm-minimal-protocol"] + path = zint-typst-plugin/vendor/wasm-minimal-protocol + url = https://github.com/Caellian/wasm-minimal-protocol.git + branch = zint-wasi-vendor diff --git a/Cargo.toml b/Cargo.toml index 6e74e6a..b169725 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,40 @@ [workspace] package.edition = "2021" +package.license = "MIT" resolver = "2" members = [ "zint-wasm-sys", "zint-wasm-rs", - "zint-typst-plugin" + "zint-typst-plugin", + "zint-typst-plugin/vendor/wasm-minimal-protocol/crates/macro", + "zint-typst-plugin/vendor/wasm-minimal-protocol/crates/wasi-stub", + "xtask" ] -package.license = "MIT" +default-members = [ + "zint-wasm-sys", + "zint-wasm-rs", + "zint-typst-plugin", +] + [profile.release] -lto = true # Enable link-time optimization -strip = true # Strip symbols from binary* -opt-level = 'z' # Optimize for size -codegen-units = 1 # Reduce number of codegen units to increase optimizations -panic = 'abort' # Abort on panic +# Enable link-time optimization +lto = true +# Strip symbols from binary +strip = true + +[profile.plugin-debug] +inherits = "dev" +# Abort on panic +panic = 'abort' + +[profile.plugin-release] +inherits = "release" +# Optimize for size +opt-level = 'z' +# Reduce number of codegen units to increase optimizations +codegen-units = 1 +# Abort on panic +panic = 'abort' + +[workspace.dependencies] +walkdir = "2" diff --git a/README.md b/README.md index 39972dd..6f57704 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,23 @@ _(click on the image to open)_ ## Build -Install wasi-sdk. Put them at `/opt/wasi-sdk`. Then run: +Clone with: +```sh +git clone --recurse-submodules -j8 https://github.com/Enter-tainer/zint-wasi.git +``` +You must have standard development tools pre-installed on your machine and in path: +- cargo (rustc; get with [rustup](https://rustup.rs/)) +- tar +- wget/curl +- gcc/clang +To build the typst package, run: +```sh +cargo xtask package ``` -./build.sh -``` + +See [`xtask` readme](./xtask/README.md) for more information. ## License diff --git a/build.sh b/build.sh deleted file mode 100755 index 2c6111a..0000000 --- a/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -euxo pipefail -cargo build --release --target wasm32-wasip1 -cargo about generate about.hbs > typst-package/license.html -wasi-stub -r 0 ./target/wasm32-wasip1/release/zint_typst_plugin.wasm -o typst-package/zint_typst_plugin.wasm -wasm-opt typst-package/zint_typst_plugin.wasm -O3 --enable-bulk-memory -o typst-package/zint_typst_plugin.wasm -cp LICENSE typst-package/LICENSE -typst compile typst-package/manual.typ typst-package/manual.pdf -typst compile typst-package/example.typ typst-package/example.svg -# We're only showing the first page -# rm assets/*.svg -# typst compile typst-package/manual.typ 'assets/doc-{n}.svg' diff --git a/about.hbs b/dist/3rdparty_license.hbs similarity index 100% rename from about.hbs rename to dist/3rdparty_license.hbs diff --git a/typst-package/LICENSE b/typst-package/LICENSE deleted file mode 100644 index afcabe8..0000000 --- a/typst-package/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 mgt - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/typst-package/example.svg b/typst-package/example.svg deleted file mode 100644 index b0ac808..0000000 --- a/typst-package/example.svg +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/typst-package/manual.pdf b/typst-package/manual.pdf index d052fc2..897925d 100644 Binary files a/typst-package/manual.pdf and b/typst-package/manual.pdf differ diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 0000000..b0ef317 --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "xtask" +version = "0.1.0" +edition.workspace = true +license.workspace = true + +[dependencies] +# should be as minimal as possible with as few transient dependencies as +# possible, prefer using system tools instead + +xxhash-rust = { version = "0.8", features = ["xxh3"] } +walkdir = { workspace = true } diff --git a/xtask/README.md b/xtask/README.md new file mode 100644 index 0000000..b38de31 --- /dev/null +++ b/xtask/README.md @@ -0,0 +1,49 @@ +# tiaoma xtask + +[xtask](https://github.com/matklad/cargo-xtask) is an extension to `cargo build` that's made specifically to make building +this plugin and testing it simpler. + +xtask commands are executed through cargo: + +```lua +cargo xtask [ARGS...] +``` + +## Commands + +- `package-plugin`: builds the tiaoma wasm plugin + - `--debug`: creates a debug build of the plugin +- `build-manual`: compiles the manual +- `package`: packages all requirements needed for publishing + +Command arguments are transitive, which means that running +`cargo xtask package --debug` will pass that flag to all task that `package` +depends on (i.e. `package-plugin`). + +There are some other internal commands (like `ci`), but they're not meant to be +run as part of the normal development process, but instead under very specific +conditions. Don't rely on them being present, consistent or free of +side-effects. + +## State options + +xtask can be configured with various state variables. These are stored in +[`xtask/state`](./state) and can be overriden with environment variables +prefixed with `XTASK_` (`XTASK_