-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge preliminary support for WebAssembly.
- Loading branch information
Showing
9 changed files
with
484 additions
and
15 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 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,165 @@ | ||
#! /usr/bin/env bash | ||
|
||
panic() | ||
{ | ||
echo "ERROR: $*" 1>& 2 | ||
exit 1 | ||
} | ||
|
||
perform_cleanup() | ||
{ | ||
if [ -n "$tmp_dir" -a -d "$tmp_dir" ]; then | ||
rm -rf "$tmp_dir" || \ | ||
echo "warning: cannot remove temporary directory $tmp_dir" | ||
fi | ||
} | ||
|
||
usage() | ||
{ | ||
cat <<- EOF | ||
usage: | ||
$0 [options] -p \$out_dir | ||
Examples | ||
======== | ||
$0 -C -t /tmp/mdadams/wasi_jasper-XXXXXX -o /tmp/mdadams/wasi_jasper | ||
EOF | ||
if [ $# -ne 0 ]; then | ||
echo "BAD USAGE: $*" | ||
fi | ||
exit 2 | ||
} | ||
|
||
self_dir="$(dirname "$0")" || panic | ||
install_wasi_sdk="$self_dir/install_wasi_sdk" | ||
install_wasmtime="$self_dir/install_wasmtime" | ||
wasm_cc="$self_dir/wasm_cc" | ||
wasm_cxx="$self_dir/wasm_cxx" | ||
|
||
wasi_sdk_version=20.0 | ||
wasmtime_version=12.0.1 | ||
|
||
tmp_dir_template="${JAS_TMP_DIR:-/tmp}/wasi_jasper-XXXXXX" | ||
cleanup=1 | ||
source_dir="$self_dir/.." | ||
out_dir= | ||
version=unknown-version | ||
|
||
while getopts ":hCt:s:o:V:" option; do | ||
case "$option" in | ||
C) | ||
cleanup=0;; | ||
t) | ||
tmp_dir_template="$OPTARG";; | ||
s) | ||
source_dir="$OPTARG";; | ||
o) | ||
out_dir="$OPTARG";; | ||
V) | ||
version="$OPTARG";; | ||
h) | ||
usage;; | ||
*) | ||
usage "invalid option $option";; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) | ||
|
||
if [ -z "$tmp_dir_template" ]; then | ||
usage "no temporary directory pathname template specified" | ||
fi | ||
|
||
if [ -z "$source_dir" ]; then | ||
usage "no source directory specified" | ||
fi | ||
|
||
if [ -z "$out_dir" ]; then | ||
usage "no output directory specified" | ||
fi | ||
|
||
tmp_dir="$(mktemp -d "$tmp_dir_template")" || \ | ||
panic "cannot create temporary directory" | ||
if [ "$cleanup" -ne 0 ]; then | ||
trap perform_cleanup EXIT | ||
fi | ||
|
||
sde_dir="$tmp_dir/wasm" | ||
wasi_sdk_dir="$sde_dir/wasi_sdk" | ||
wasmtime_dir="$sde_dir/wasmtime" | ||
|
||
"$install_wasi_sdk" -d "$wasi_sdk_dir" -v "$wasi_sdk_version" || \ | ||
panic "cannot install WASI SDK" | ||
"$install_wasmtime" -d "$wasmtime_dir" -v "$wasmtime_version" || \ | ||
panic "cannot install wasmtime" | ||
wasmtime="$wasmtime_dir/bin/wasmtime" | ||
|
||
export WASI_SDK_ROOT_DIR="$wasi_sdk_dir" | ||
export CC="$wasm_cc" | ||
export CXX="$wasm_cxx" | ||
export PATH="$wasi_sdk_dir/bin:$PATH" | ||
|
||
lld="$(type -P lld)" || lld= | ||
echo "lld program: $lld" | ||
|
||
#source_dir="$tmp_dir/git" | ||
build_dir="$tmp_dir/build" | ||
install_dir="$tmp_dir/install" | ||
readme_file="$install_dir/README.txt" | ||
|
||
configure_options=( | ||
-DCMAKE_INSTALL_PREFIX="$install_dir" | ||
-DCMAKE_BUILD_TYPE=Release | ||
-DCMAKE_VERBOSE_MAKEFILE=1 | ||
-DJAS_CROSSCOMPILING=1 | ||
-DJAS_STDC_VERSION=201112L | ||
-DJAS_ENABLE_MULTITHREADING_SUPPORT=0 | ||
-DJAS_ENABLE_SHARED=0 | ||
-DJAS_ENABLE_CXX=0 | ||
-DJAS_USE_JAS_INIT=1 | ||
-DJAS_STRICT=0 | ||
-DJAS_WASM=1 | ||
-DJAS_ENABLE_DOC=0 | ||
) | ||
|
||
cmake -H"$source_dir" -B"$build_dir" "${configure_options[@]}" || \ | ||
panic "configure failed" | ||
|
||
cmake --build "$build_dir" || \ | ||
panic "build failed" | ||
|
||
cmake --build "$build_dir" --target install || \ | ||
panic "install failed" | ||
|
||
"$wasmtime" "$install_dir/bin/imginfo" < "$source_dir/data/images/goldenears.jp2" || panic "jasper failed" | ||
|
||
cat > "$readme_file" <<- EOF | ||
JasPer WebAssembly Edition ($version) | ||
This directory contains several JasPer programs built for a WebAssembly | ||
target that uses WASI for interfacing to the host environment. | ||
The command-line interface (CLI) for these programs is identical to | ||
their non-WebAssembly counterparts. For detailed information on the | ||
CLI for these programs, refer to the online manual at: | ||
https://jasper-software.github.io/jasper-manual/latest/html/index.html | ||
In order to run these WebAssembly programs, you will need a WebAssembly | ||
runtime with WASI support, such as: | ||
Wasmtime (https://wasmtime.dev) | ||
Wasmer (https://wasmer.io) | ||
WAMR (https://bytecodealliance.github.io/wamr.dev) | ||
WasmEdge (https://wasmedge.org) | ||
EOF | ||
[ $? -eq 0 ] || panic "cannot make readme file" | ||
|
||
if [ ! -d "$out_dir" ]; then | ||
mkdir -p "$out_dir" || panic | ||
fi | ||
|
||
for file in jasper imginfo imgcmp; do | ||
cp -a "$install_dir/bin/$file" "$out_dir" || panic | ||
done | ||
cp -a "$readme_file" "$out_dir" || panic |
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,53 @@ | ||
#! /usr/bin/env bash | ||
|
||
panic() | ||
{ | ||
echo "ERROR: $*" | ||
exit 1 | ||
} | ||
|
||
wasi_sdk_version= | ||
install_dir= | ||
|
||
while getopts :d:v: option; do | ||
case "$option" in | ||
d) | ||
install_dir="$OPTARG";; | ||
v) | ||
wasi_sdk_version="$OPTARG";; | ||
esac | ||
done | ||
|
||
if [ -z "$install_dir" ]; then | ||
panic "no install directory specified" | ||
fi | ||
if [ -z "$wasi_sdk_version" ]; then | ||
panic "no version specified" | ||
fi | ||
|
||
if [ ! -d "$install_dir" ]; then | ||
mkdir -p "$install_dir" || \ | ||
panic "cannot make directory $install_dir" | ||
fi | ||
|
||
#source_dir="$install_dir/.source" | ||
#build_dir="$install_dir/.build" | ||
#build_dir_2="$install_dir/.build2" | ||
|
||
wasi_sdk_archive_url="https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-$wasi_sdk_version-linux.tar.gz" | ||
|
||
wasi_sdk_archive="$install_dir/.wasi-sdk.tar.xz" | ||
|
||
if [ ! -d "$install_dir" ]; then | ||
mkdir -p "$install_dir" || \ | ||
panic "cannot make directory $install_dir" | ||
fi | ||
|
||
wget -O "$wasi_sdk_archive" "$wasi_sdk_archive_url" || \ | ||
panic "wget failed" | ||
tar -x -z -f "$wasi_sdk_archive" --strip-components=1 -C "$install_dir" || \ | ||
panic "tar failed" | ||
|
||
#rm -rf "$source_dir" || panic | ||
#rm -rf "$build_dir" || panic | ||
#rm -rf "$build_dir_2" || panic |
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,74 @@ | ||
#! /usr/bin/env bash | ||
|
||
# Wasmtime release artifacts for download: | ||
# - library and headers for C API: | ||
# wasmtime-$version-x86_64-linux-c-api.tar.xz | ||
# - program to run WASM applications: | ||
# wasmtime-$version-x86_64-linux.tar.xz | ||
|
||
panic() | ||
{ | ||
echo "ERROR: $*" | ||
exit 1 | ||
} | ||
|
||
usage() | ||
{ | ||
cat <<- EOF | ||
usage: $0 [options] | ||
-d \$install_dir | ||
-v \$version | ||
EOF | ||
exit 2 | ||
} | ||
|
||
wasmtime_version= | ||
install_dir= | ||
|
||
while getopts :d:v: option; do | ||
case "$option" in | ||
d) | ||
install_dir="$OPTARG";; | ||
v) | ||
wasmtime_version="$OPTARG";; | ||
*) | ||
usage "invalid option $OPTARG";; | ||
esac | ||
done | ||
|
||
if [ -z "$install_dir" ]; then | ||
panic "no install directory specified" | ||
fi | ||
if [ -z "$wasmtime_version" ]; then | ||
panic "no version specified" | ||
fi | ||
|
||
if [ ! -d "$install_dir" ]; then | ||
mkdir -p "$install_dir" || \ | ||
panic "cannot make directory $install_dir" | ||
fi | ||
|
||
#source_dir="$install_dir/.source" | ||
#build_dir="$install_dir/.build" | ||
#build_dir_2="$install_dir/.build2" | ||
|
||
wasmtime_archive="$install_dir/.wasmtime.tar.xz" | ||
wasmtime_capi_archive="$install_dir/.wasmtime-capi.tar.xz" | ||
wasmtime_archive_url="https://github.com/bytecodealliance/wasmtime/releases/download/v$wasmtime_version/wasmtime-v$wasmtime_version-x86_64-linux.tar.xz" | ||
wasmtime_capi_archive_url="https://github.com/bytecodealliance/wasmtime/releases/download/v$wasmtime_version/wasmtime-v$wasmtime_version-x86_64-linux-c-api.tar.xz" | ||
|
||
wget -O "$wasmtime_archive" "$wasmtime_archive_url" || \ | ||
panic "wget failed" | ||
wget -O "$wasmtime_capi_archive" "$wasmtime_capi_archive_url" || \ | ||
panic "wget failed" | ||
if [ ! -d "$install_dir/bin" ]; then | ||
mkdir -p "$install_dir/bin" | ||
fi | ||
tar -x -J -f "$wasmtime_archive" --strip-components=1 -C "$install_dir/bin" || \ | ||
panic "tar failed" | ||
tar -x -J -f "$wasmtime_capi_archive" --strip-components=1 -C "$install_dir" || \ | ||
panic "tar failed" | ||
|
||
#rm -rf "$source_dir" || panic | ||
#rm -rf "$build_dir" || panic | ||
#rm -rf "$build_dir_2" || panic |
Oops, something went wrong.