The JS Compute Runtime for Fastly's Compute platform provides the environment JavaScript is executed in when using the Fastly Compute JavaScript SDK.
Note: If you just want to use JavaScript on the Fastly Compute Platform, we recommend using the JavaScript Starter Kits provided by the Fastly CLI tool. For more information please see the JavaScript documentation on the Fastly Developer Hub.
Note that this repository uses Git submodules, so you will need to run
git submodule update --recursive --init
to pull down or update submodules.
To build from source, you need to have the following tools installed to successfully build, depending on your system.
- Build tools
sudo apt install build-essential
- Rust
curl -so rust.sh https://sh.rustup.rs && sh rust.sh -y restart shell or run source $HOME/.cargo/env
- binaryen
sudo apt install binaryen
- rust target wasm32-wasi
rustup target add wasm32-wasi
- cbindgen
cargo install cbindgen
- wasi-sdk, version 20,
with alternate install instructions
curl -sS -L -O https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz tar xf wasi-sdk-20.0-linux.tar.gz sudo mkdir -p /opt/wasi-sdk sudo mv wasi-sdk-20.0/* /opt/wasi-sdk/
Build the runtime using npm:
npm run build
- Build tools
# First, install Xcode from the Mac App Store. Then: sudo xcode-select --switch /Applications/Xcode.app sudo xcodebuild -license
- Homebrew
# From homebrew.sh /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- wget
brew install wget
- binaryen
brew install binaryen
- Python
brew install python@3
- Rust
curl -so rust.sh https://sh.rustup.rs && sh rust.sh -y # then, restart shell or run: source $HOME/.cargo/env
- rust target wasm32-wasi
rustup target add wasm32-wasi
- cbindgen
cargo install cbindgen
- wasi-sdk, version 20,
with alternate install instructions
curl -sS -L -O https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz tar xf wasi-sdk-20.0-macos.tar.gz sudo mkdir -p /opt/wasi-sdk sudo mv wasi-sdk-20.0/* /opt/wasi-sdk/
Build the runtime using npm:
npm run build
You can test a local build of the JS Compute runtime by installing it in your JavaScript Compute application and running that locally or by uploading it to your Fastly service.
-
First, follow the directions in Building the JS Compute Runtime for your platform to obtain a local build. The build outputs are the following files:
fastly.wasm
fastly.debug.wasm
fastly-weval.wasm
fastly-ics.wevalcache
-
Create a local tarball using npm.
npm pack
The resulting tarball will have a filename such as
fastly-js-compute-<version>.tgz
. -
In your Compute application, install the tarball using
npm
:npm install /path/to/fastly-js-compute-<version>.tgz
-
Build and test or deploy your application as usual, using
fastly compute serve
orfastly compute publish
, or an appropriate npm script.
Dev builds are released before production releases to allow for further testing. These are not released upstream to NPM, however you can acquire them from the Releases section. Download the runtime for your platform, extract the executable and place it in the /node_modules/@fastly/js-compute/bin/PLATFORM folder of your Fastly Compute project. Then you can use the normal Fastly CLI to build your service.
Please submit an issue if you find any problems during testing.
The JS Compute Runtime has automated tests which run on all pull-requests. The test applications are located within <./integration-tests/js-compute>.
To run an end-to-end test which builds and deploys an application to fastly:
- Build the runtime and cli:
npm run build
in the root of the project - Change to the test directory for the runtime:
cd integration-tests/js-compute/
- Install the test dependencies:
npm install
- Get a list of all the applications to test:
node test.js
- Test a single application via:
node test.js <name>
or test all vianode test.js --all