Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Integralist
Copy link
Collaborator

@Integralist Integralist commented May 24, 2022

Fixes #534

EXAMPLE

Use wasp-strip to reduce the size of the WASM binary.

In the fastly.toml file:

[scripts]
post_build = "ls -lh bin/main.wasm | cut -d ' ' -f 9 && wasm-strip bin/main.wasm && ls -lh bin/main.wasm | cut -d ' ' -f 9"

Some of the output has been omitted (...) for brevity:

$ fastly compute build --verbose

...
Verifying package manifest...
Verifying local rust toolchain...
Checking if `rustc` is installed...
Checking the `rustc` version...
Checking the `wasm32-wasi` target is installed...
Checking if `cargo` is installed...

...

Building package using rust toolchain...
       ...
       Fresh testing-fastly-cli v0.1.0 (/Users/integralist/Code/test-projects/testing-fastly-cli)
    Finished release [optimized + debuginfo] target(s) in 0.02s

5.5M
468K

Creating package archive...

SUCCESS: Built package 'testing-fastly-cli' (pkg/testing-fastly-cli.tar.gz)

We can see the 'before' size 5.5M vs the 'after' size 468K of the bin/main.wasm file.

If we run tar -ztvf pkg/testing-fastly-cli.tar.gz we can also see that the wasm file inside the .tar.gz is the reduced file size:

drwx------  0 integralist staff       0 24 May 16:49 testing-fastly-cli/
-rw-r--r--  0 integralist staff     195 24 May 16:49 testing-fastly-cli/Cargo.toml
drwx------  0 integralist staff       0 24 May 16:49 testing-fastly-cli/bin/
-rw-r--r--  0 integralist staff  479157 24 May 16:49 testing-fastly-cli/bin/main.wasm
-rw-r--r--  0 integralist staff     684 24 May 16:49 testing-fastly-cli/fastly.toml

This demonstrates the post_build is executed after the wasm file is created but before it's packaged inside a tar.gz archive.

Additional

I have a separate (internal) PR ready to update https://developer.fastly.com/reference/compute/fastly-toml/ to document the new post_build field.

@Integralist Integralist requested review from a team and triblondon and removed request for a team May 24, 2022 15:57
@Integralist Integralist added the enhancement New feature or request label May 25, 2022
@Integralist Integralist merged commit f2a6dc3 into main May 25, 2022
@Integralist Integralist deleted the integralist/scripts_postbuild branch May 25, 2022 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Wasm-strip for fastly compute build?

3 participants