-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Motivation We use `wasm-nm` (the Wasm version of [`nm`](https://web.mit.edu/gnu/doc/html/binutils_3.html)) to geta list of exported functions. Unfortunately `wasm-nm` is no longer maintained and fails with the latest Wasm files that have new instructions. `ic-wasm info` provides the same information, but not in a machine readable form. Where we have switched to ic-wasm we use sed to extract the interesting information, at which point the output is practically in the standard `nm` output format. I propose to ask upstream to provide a machine readable output, preferably in the `nm` format, and in the meantime make a polyfill. ## Alternatives considered Copy and paste the sed incantation into the one place we use `wasm-nm` in this repository. I'd rather get a clean solution pushed upstream. --------- Co-authored-by: Max Murphy <max@winning.black>
- Loading branch information
Showing
5 changed files
with
64 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ DIDC_VERSION=2023-07-25 | |
QUILL_VERSION=0.4.0 | ||
IDL2JSON_VERSION=0.8.5 | ||
BINSTALL_VERSION=1.3.0 | ||
IC_WASM_VERSION=0.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
SOURCE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" | ||
PATH="$SOURCE_DIR:$PATH" | ||
|
||
print_help() { | ||
cat <<-EOF | ||
Polyfill for the now outdated wasm-nm. | ||
Supports only: | ||
wasm-nm -e SOMEFILE.wasm | ||
wasm-nm -e -j SOMEFILE.wasm | ||
Note: ic-wasm now provides much the same information, but not in a very machine-readable format. | ||
EOF | ||
} | ||
|
||
# Source the clap.bash file --------------------------------------------------- | ||
source "$SOURCE_DIR/clap.bash" | ||
# Define options | ||
clap.define short=e long=export desc="Display only export symbols." variable=ONLY_EXPORT nargs=0 | ||
clap.define short=j long=export desc="Just display the symbol names (no type)." variable=NO_TYPE nargs=0 | ||
# Source the output file ---------------------------------------------------------- | ||
source "$(clap.build)" | ||
|
||
(($# == 1)) || { | ||
echo "ERROR: Please provide the Wasm filename as a positional argument, like this:" | ||
echo " wasm-nm -e my-file.wasm" | ||
exit 1 | ||
} >&2 | ||
|
||
WASM_FILENAME="${1:-}" | ||
|
||
export_symbols() { | ||
ic-wasm "${WASM_FILENAME:-}" info | sed -nE '/^Exported methods:/,/^]/p' | sed '1d;$d' | sed -E 's/.*"(.*)",/\1/;s/ *\(.*//g' | { | ||
if [[ "${NO_TYPE:-}" == "true" ]]; then | ||
cat | ||
else | ||
sed 's/^/e /g' | ||
fi | ||
} | ||
} | ||
|
||
if [[ "${ONLY_EXPORT}" == "true" ]]; then | ||
export_symbols | ||
else | ||
{ | ||
echo "ERROR: Action not supported, sorry." | ||
exit 1 | ||
} >&2 | ||
fi |