#!/usr/bin/env bash12# Script to re-vendor the WIT files that Wasmtime uses as defined by a3# particular tag in upstream repositories.4#5# This script is executed on CI to ensure that everything is up-to-date.6set -ex78# The make_vendor function takes a base path (e.g., "wasi") and a list9# of packages in the format "name@tag". It constructs the full destination10# path, downloads the tarballs from GitHub, extracts the relevant files, and11# removes any unwanted directories.12make_vendor() {13local name=$114local packages=$215local path="crates/$name/wit/deps"1617rm -rf $path18mkdir -p $path1920for package in $packages; do21IFS='@' read -r repo tag subdir <<< "$package"22mkdir -p "$path/$repo"23cached_extracted_dir="$cache_dir/$repo-$tag"2425if [[ ! -d $cached_extracted_dir ]]; then26mkdir -p $cached_extracted_dir27curl --retry 5 --retry-all-errors -sLO https://github.com/WebAssembly/wasi-$repo/archive/$tag.tar.gz28tar xzf $tag.tar.gz --strip-components=1 -C $cached_extracted_dir29rm $tag.tar.gz30rm -rf $cached_extracted_dir/${subdir:-"wit"}/deps*31fi3233cp -r $cached_extracted_dir/${subdir:-"wit"}/* $path/$repo34done35}3637cache_dir=$(mktemp -d)3839make_vendor "wasi-io" "40[email protected]41"4243make_vendor "wasi/src/p2" "44[email protected]45[email protected]46[email protected]47[email protected]48[email protected]49[email protected]50"5152make_vendor "wasi-http" "53[email protected]54[email protected]55[email protected]56[email protected]57[email protected]58[email protected]59[email protected]60"6162make_vendor "wasi-tls" "63[email protected]64[email protected]+505fc9865"6667make_vendor "wasi-config" "config@f4d699b"6869make_vendor "wasi-keyvalue" "keyvalue@219ea36"7071make_vendor "wasi/src/p3" "72[email protected]@wit-0.3.0-draft73[email protected]@wit-0.3.0-draft74[email protected]@wit-0.3.0-draft75[email protected]@wit-0.3.0-draft76[email protected]@wit-0.3.0-draft77"7879make_vendor "wasi-http/src/p3" "80[email protected]@wit-0.3.0-draft81[email protected]@wit-0.3.0-draft82[email protected]@wit-0.3.0-draft83[email protected]@wit-0.3.0-draft84[email protected]@wit-0.3.0-draft85[email protected]@wit-0.3.0-draft86"8788rm -rf $cache_dir8990# Separately (for now), vendor the `wasi-nn` WIT files since their retrieval is91# slightly different than above.92repo=https://raw.githubusercontent.com/WebAssembly/wasi-nn93revision=0.2.0-rc-2024-10-2894curl --retry 5 --retry-all-errors -L $repo/$revision/wasi-nn.witx -o crates/wasi-nn/witx/wasi-nn.witx95curl --retry 5 --retry-all-errors -L $repo/$revision/wit/wasi-nn.wit -o crates/wasi-nn/wit/wasi-nn.wit969798