Skip to content

Latest commit

 

History

History
152 lines (125 loc) · 5.36 KB

DEVELOPMENT.md

File metadata and controls

152 lines (125 loc) · 5.36 KB

Fastly Compute JS Runtime

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.

Working with the JS Compute Runtime source

Note that this repository uses Git submodules, so you will need to run

git submodule update --recursive --init

to pull down or update submodules.

Building the JS Compute Runtime

To build from source, you need to have the following tools installed to successfully build, depending on your system.

Linux

  • 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

macOS (Apple silicon)

  • 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

Testing a Local build in a Compute application

⚠️ You should not use this for production workloads!!!!!!!!

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.

  1. 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
  2. Create a local tarball using npm.

    npm pack

    The resulting tarball will have a filename such as fastly-js-compute-<version>.tgz.

  3. In your Compute application, install the tarball using npm:

    npm install /path/to/fastly-js-compute-<version>.tgz
  4. Build and test or deploy your application as usual, using fastly compute serve or fastly compute publish, or an appropriate npm script.

Testing a Dev Release in a Compute application

⚠️ You should not use this for production workloads!!!!!!!!

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.

Automated 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 via node test.js --all