Coder Social home page Coder Social logo

cytommi / js-compute-runtime Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fastly/js-compute-runtime

0.0 0.0 0.0 19.28 MB

JavaScript runtime for Fastly Compute@Edge

License: Apache License 2.0

JavaScript 5.55% Rust 3.62% Makefile 0.66% C++ 64.83% C 5.65% Shell 1.05% HTML 0.63% TypeScript 18.00%

js-compute-runtime's Introduction

Fastly Compute@Edge JS Runtime

The JS Compute Runtime for Fastly's Compute@Edge platform provides the environment JavaScript is executed in when using the Compute@Edge JavaScript SDK.

Note: If you just want to use JavaScript on the Compute@Edge 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 ensure that the headers and object files for the SpiderMonkey JavaScript engine are available. It's recommended to download pre-built object files:

(cd c-dependencies/spidermonkey && sh download-engine.sh)

Alternatively, the engine can also be built from source using c-dependencies/spidermonkey/build-engine.sh. That should only be required if you want to modify the engine itself, however.

In addition you need to have the following tools installed to successfully build, and build from a linux based system.

  • Rust

    curl -so rust.sh https://sh.rustup.rs && sh rust.sh -y
    restart shell or run source $HOME/.cargo/env
    
  • Build tools

    sudo apt install build-essential
  • binaryen

    sudo apt install binaryen
  • rust target wasm32-wasi

    rustup target add wasm32-wasi
  • cbindgen

    cargo install cbindgen
  • wasi-sdk, version 12, with alternate install instructions

    curl -sS -L -O https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz
    tar xf wasi-sdk-12.0-linux.tar.gz
    sudo mkdir -p /opt/wasi-sdk
    sudo mv wasi-sdk-12.0/* /opt/wasi-sdk/
  • rust version - the rust version may need to be pinned due to the WASI spidermonkey version, the current version can be found at main.yml under "Install pinned Rust version and wasm32-wasi target"

     rustup update 1.57.0 --no-self-update
    
     cd /location/of/js-compute-runtime
     rustup override set 1.57.0
    

Once that is done, the runtime and the CLI tool for applying it to JS source code can be built using cargo:

cargo build --release

Build a windows executable

To build for windows on a linux system you need to install the following modules:

sudo apt-get install gcc-mingw-w64
rustup target add x86_64-pc-windows-gnu

then you can run the following

cargo build --target x86_64-pc-windows-gnu --release

Testing

The JS Compute Runtime doesn't currently contain automated tests itself. Instead, Fastly runs an automated test suite for an internal repository for the JavaScript SDK using the runtime.

Manual testing is well supported, however. To test your changes, you can follow these steps:

  1. Build the runtime's CLI tool, see above
  2. Create a C@E service from a JS source file by running the CLI tool
  3. Test the service using Fastly's local testing server

As an example, to turn a file test.js with this source code:

addEventListener('fetch', e => {
  console.log("Hello World!");
});

into a C@E service with your build of the CLI tool, run the following command:

cargo run --release -- test.js test.wasm

Then test your service in Viceroy:

viceroy test.wasm

Testing a Dev Release

โš ๏ธ 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 Compute@Edge project. Then you can use the normal Fastly CLI to build your service.

Please submit an issue if you find any problems during testing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.