Skip to content

Commit 5fa84e8

Browse files
authored
tools: automate uvwasi dependency update
Refs: nodejs/security-wg#828 PR-URL: #47509 Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent bae4420 commit 5fa84e8

File tree

3 files changed

+95
-7
lines changed

3 files changed

+95
-7
lines changed

.github/workflows/tools.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ jobs:
190190
cat temp-output
191191
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
192192
rm temp-output
193+
- id: uvwasi
194+
subsystem: deps
195+
label: dependencies
196+
run: |
197+
./tools/dep_updaters/update-uvwasi.sh > temp-output
198+
cat temp-output
199+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
200+
rm temp-output
193201
steps:
194202
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
195203
with:

doc/contributing/maintaining-web-assembly.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ Node.js GitHub organization. As needed, an updated copy
7878
is vendored into the Node.js deps in
7979
[deps/uvwasi](https://github.com/nodejs/node/tree/main/deps/uvwasi).
8080

81-
To update the copy of uvwasi in the Node.js deps:
82-
83-
* Copy over the contents of `include` and `src` to the corresponding
84-
directories.
85-
* Check if any additional files have been added and need to be added
86-
to the `sources` list in `deps/uvwasi/uvwasi.gyp`.
87-
8881
In addition to the code from uvwasi, Node.js includes bindings and
8982
APIs that allow WebAssembly to be run with WASI support from Node.js.
9083
The documentation for this API is in
@@ -95,3 +88,12 @@ The implementation of the bindings and the public API is in:
9588
* [src/node\_wasi.h](https://github.com/nodejs/node/blob/main/src/node_wasi.h)
9689
* [src/node\_wasi.cc](https://github.com/nodejs/node/blob/main/src/node_wasi.cc)
9790
* [lib/wasi.js](https://github.com/nodejs/node/blob/main/lib/wasi.js)
91+
92+
### Running the update script
93+
94+
The `tools/dep_updaters/update-uvwasi.sh` script automates the update of
95+
the uvwasi source files.
96+
97+
```bash
98+
./tools/dep_updaters/update-uvwasi.sh
99+
```

tools/dep_updaters/update-uvwasi.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update uvwasi in the source tree to a specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_DIR="$BASE_DIR/deps"
7+
8+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
9+
[ -x "$NODE" ] || NODE=$(command -v node)
10+
11+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
12+
const res = await fetch('https://api.github.com/repos/nodejs/uvwasi/releases/latest');
13+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
14+
const { tag_name } = await res.json();
15+
console.log(tag_name.replace('v', ''));
16+
EOF
17+
)"
18+
19+
CURRENT_MAJOR_VERSION=$(grep "#define UVWASI_VERSION_MAJOR" "$DEPS_DIR/uvwasi/include/uvwasi.h" | sed -n "s/^.*MAJOR \(.*\)/\1/p")
20+
CURRENT_MINOR_VERSION=$(grep "#define UVWASI_VERSION_MINOR" "$DEPS_DIR/uvwasi/include/uvwasi.h" | sed -n "s/^.*MINOR \(.*\)/\1/p")
21+
CURRENT_PATCH_VERSION=$(grep "#define UVWASI_VERSION_PATCH" "$DEPS_DIR/uvwasi/include/uvwasi.h" | sed -n "s/^.*PATCH \(.*\)/\1/p")
22+
CURRENT_VERSION="$CURRENT_MAJOR_VERSION.$CURRENT_MINOR_VERSION.$CURRENT_PATCH_VERSION"
23+
24+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
25+
26+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
27+
echo "Skipped because uvwasi is on the latest version."
28+
exit 0
29+
fi
30+
31+
echo "Making temporary workspace"
32+
33+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
34+
echo "$WORKSPACE"
35+
cleanup () {
36+
EXIT_CODE=$?
37+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
38+
exit $EXIT_CODE
39+
}
40+
41+
trap cleanup INT TERM EXIT
42+
43+
UVWASI_ZIP="uvwasi-$NEW_VERSION"
44+
cd "$WORKSPACE"
45+
46+
echo "Fetching UVWASI source archive..."
47+
curl -sL -o "$UVWASI_ZIP.zip" "https://github.com/nodejs/uvwasi/archive/refs/tags/v$NEW_VERSION.zip"
48+
49+
echo "Moving existing GYP build file"
50+
mv "$DEPS_DIR/uvwasi/"*.gyp "$WORKSPACE/"
51+
rm -rf "$DEPS_DIR/uvwasi/"
52+
53+
echo "Unzipping..."
54+
unzip "$UVWASI_ZIP.zip" -d "$DEPS_DIR/uvwasi/"
55+
rm "$UVWASI_ZIP.zip"
56+
57+
mv "$WORKSPACE/"*.gyp "$DEPS_DIR/uvwasi/"
58+
cd "$DEPS_DIR/uvwasi/"
59+
60+
echo "Copying new files to deps folder"
61+
cp -r "$UVWASI_ZIP/include" "$DEPS_DIR/uvwasi/"
62+
cp -r "$UVWASI_ZIP/src" "$DEPS_DIR/uvwasi/"
63+
cp "$UVWASI_ZIP/LICENSE" "$DEPS_DIR/uvwasi/"
64+
rm -rf "$UVWASI_ZIP"
65+
66+
echo "All done!"
67+
echo ""
68+
echo "Please git add uvwasi, commit the new version:"
69+
echo ""
70+
echo "$ git add -A deps/uvwasi"
71+
echo "$ git commit -m \"deps: update uvwasi to $NEW_VERSION\""
72+
echo ""
73+
echo "Make sure to update the deps/uvwasi/uvwasi.gyp if any significant changes have occurred upstream"
74+
echo ""
75+
76+
# The last line of the script should always print the new version,
77+
# as we need to add it to $GITHUB_ENV variable.
78+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)