Skip to content

Commit 5ff426d

Browse files
committed
Initial commit
0 parents  commit 5ff426d

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

.github/workflows/build.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
merge_group:
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
name: build
14+
runs-on: ubuntu-24.04
15+
permissions:
16+
pages: write
17+
id-token: write
18+
steps:
19+
- name: ghc-wasm-meta
20+
run: |
21+
pushd "$(mktemp -d)"
22+
curl -L https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz | tar xz --strip-components=1
23+
PREFIX=/tmp/.ghc-wasm SKIP_GHC=1 ./setup.sh
24+
/tmp/.ghc-wasm/add_to_github_path.sh
25+
echo "WASI_SDK_PREFIX=/tmp/.ghc-wasm/wasi-sdk" >> $GITHUB_ENV
26+
popd
27+
28+
- name: build-zstd
29+
run: |
30+
pushd "$(mktemp -d)"
31+
curl -L https://github.com/haskell-wasm/zstd/archive/refs/heads/release.tar.gz | tar xz --strip-components=1
32+
./install-wasi.sh
33+
popd
34+
35+
- name: build-libarchive
36+
run: |
37+
pushd "$(mktemp -d)"
38+
curl -L https://github.com/haskell-wasm/libarchive/archive/refs/heads/patch/3.8.tar.gz | tar xz --strip-components=1
39+
./install-wasi.sh
40+
popd
41+
42+
- name: test-playground
43+
run: |
44+
mkdir ghc-in-browser
45+
curl -L https://github.com/haskell-wasm/ghc-in-browser/archive/refs/heads/gh-pages.tar.gz | tar xz --strip-components=1 -C ghc-in-browser
46+
pushd ghc-in-browser
47+
48+
cp /tmp/wasi/bin/bsdtar.wasm .
49+
sed -i -e "s|https://haskell-wasm.github.io/bsdtar-wasm/bsdtar.wasm|./bsdtar.wasm|" index.html
50+
curl -L https://gitlab.haskell.org/haskell-wasm/ghc/-/raw/ghc-9.14/.gitlab/hello.hs -O
51+
curl -L https://gitlab.haskell.org/haskell-wasm/ghc/-/raw/ghc-9.14/testsuite/tests/ghc-api-browser/playground001.js -o test.js
52+
sed -i -e 's|".mjs": "application/javascript",|".mjs": "application/javascript", ".wasm": "application/wasm"|' test.js
53+
54+
chmod +x test.js
55+
./test.js '{"browser":"chrome","executablePath":"/usr/bin/google-chrome-stable","args":["--no-sandbox"]}' | grep -F 'main = putStrLn "hello world"'
56+
popd
57+
58+
- name: upload-pages-artifact
59+
uses: actions/upload-pages-artifact@v4
60+
with:
61+
path: /tmp/wasi/bin
62+
retention-days: 90
63+
64+
- name: deploy-pages
65+
uses: actions/deploy-pages@v4
66+
if: github.event_name == 'push' && github.ref_name == 'master'

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2025 Cheng Shao
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer
9+
in this position and unchanged.
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17+
IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# `bsdtar-wasm`
2+
3+
[![Chat on Matrix](https://matrix.to/img/matrix-badge.svg)](https://matrix.to/#/#haskell.wasm:matrix.org)
4+
5+
This repo hosts a `wasm32-wasi` build of the `bsdtar` CLI from the
6+
[libarchive](https://libarchive.org) project, with
7+
[`zstd`](https://facebook.github.io/zstd) support. It can be used to
8+
extract a `.tar.zst` archive in the wasi vfs, useful when:
9+
10+
- You need to download a large binary artifact, and the default
11+
gzip/brotli compression provided by the CDN is not good enough
12+
- You need to set up a vfs with many files, and issuing one `fetch`
13+
per file can become a bottleneck
14+
15+
## How to use
16+
17+
### The wasm modules
18+
19+
There are two `wasm32-wasi` modules available here:
20+
21+
- [`bsdtar.wasm`](https://haskell-wasm.github.io/bsdtar-wasm/bsdtar.wasm)
22+
- [`zstd.wasm`](https://haskell-wasm.github.io/bsdtar-wasm/zstd.wasm)
23+
24+
They are command modules without any custom imports/exports, fully
25+
single-threaded, compiled with LLVM ThinLTO and optimized by
26+
`wasm-opt`, with `simd128` feature enabled. `bsdtar.wasm` only
27+
supports `zstd`, doesn't support other filters like `xz` or `gzip`.
28+
29+
Simply run them and pass the right CLI arguments as well as the right
30+
input (either stdin or a file in the wasi vfs), then check the exit
31+
code and use the output.
32+
33+
Prefer `zstd.wasm` when only decompressing a single file, otherwise
34+
use `bsdtar.wasm`.
35+
36+
### The wasi implementation
37+
38+
The wasm modules work fine with `wasmtime` and `node`/`uvwasi`. But
39+
for browsers, the only wasi implementation that works right now is
40+
[`haskell-wasm/browser_wasi_shim`](https://github.com/haskell-wasm/browser_wasi_shim),
41+
which can be directly imported from this
42+
[URL](https://esm.sh/gh/haskell-wasm/browser_wasi_shim). Upstream npm
43+
release lacks some important bugfixes at the moment.
44+
45+
## Building
46+
47+
The wasm-enabled forks of the relevant projects are available at:
48+
49+
- [`haskell-wasm/zstd`](https://github.com/haskell-wasm/zstd)
50+
- [`haskell-wasm/libarchive`](https://github.com/haskell-wasm/libarchive)
51+
52+
Start from `install-wasi.sh` in the above repos.
53+
54+
The wasm patches are based on upstream release branches instead of
55+
development branches, and there's currently no plan to upstream them
56+
due to limited time. That being said, the heavylifting is done by
57+
upstream and the wasm patches are just bandaids to get things working
58+
for my use-case; feel free to use them as starting points for building
59+
whatever you have in mind.

0 commit comments

Comments
 (0)