Skip to content

Commit dad74dc

Browse files
Jake ChampionJakeChampion
authored andcommitted
chore: Add SDK metadata field to generated js-compute-runtime wasm files
1 parent 4b583e7 commit dad74dc

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

.github/workflows/main.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ defaults:
1111
shell: bash
1212
env:
1313
viceroy_version: 0.3.5
14+
wasm-tools_version: 1.0.28
1415

1516
jobs:
1617
build:
1718
name: Build
19+
needs: [ensure_cargo_installs]
1820
strategy:
1921
matrix:
2022
profile: [debug, release]
@@ -27,6 +29,20 @@ jobs:
2729
- uses: ./.github/actions/cache-crates
2830
with:
2931
lockfiles: 'c-dependencies/js-compute-runtime/**/Cargo.lock'
32+
33+
- name: Restore wasm-tools from cache
34+
uses: actions/cache@v3
35+
id: wasm-tools
36+
with:
37+
path: "/home/runner/.cargo/bin/wasm-tools"
38+
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
39+
40+
- name: "Check wasm-tools has been restored"
41+
if: steps.wasm-tools.outputs.cache-hit != 'true'
42+
run: |
43+
echo "wasm-tools was not restored from the cache"
44+
echo "bailing out from the build early"
45+
exit 1
3046
3147
- uses: ./.github/actions/install-rust
3248
with:
@@ -102,6 +118,9 @@ jobs:
102118
- crate: viceroy
103119
version: 0.3.5 # Note: workflow-level env vars can't be used in matrix definitions
104120
options: ""
121+
- crate: wasm-tools
122+
version: 1.0.28 # Note: workflow-level env vars can't be used in matrix definitions
123+
options: ""
105124
runs-on: ubuntu-latest
106125
steps:
107126
- name: Cache ${{ matrix.crate }} ${{ matrix.version }}
@@ -143,6 +162,20 @@ jobs:
143162
path: "/home/runner/.cargo/bin/viceroy"
144163
key: crate-cache-viceroy-${{ env.viceroy_version }}
145164

165+
- name: Restore wasm-tools from cache
166+
uses: actions/cache@v3
167+
id: wasm-tools
168+
with:
169+
path: "/home/runner/.cargo/bin/wasm-tools"
170+
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
171+
172+
- name: "Check wasm-tools has been restored"
173+
if: steps.wasm-tools.outputs.cache-hit != 'true'
174+
run: |
175+
echo "wasm-tools was not restored from the cache"
176+
echo "bailing out from the build early"
177+
exit 1
178+
146179
- run: yarn install --frozen-lockfile
147180

148181
- name: Build WPT runtime
@@ -221,6 +254,20 @@ jobs:
221254
with:
222255
path: "/home/runner/.cargo/bin/viceroy"
223256
key: crate-cache-viceroy-${{ env.viceroy_version }}
257+
258+
- name: Restore wasm-tools from cache
259+
uses: actions/cache@v3
260+
id: wasm-tools
261+
with:
262+
path: "/home/runner/.cargo/bin/wasm-tools"
263+
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
264+
265+
- name: "Check wasm-tools has been restored"
266+
if: steps.wasm-tools.outputs.cache-hit != 'true'
267+
run: |
268+
echo "wasm-tools was not restored from the cache"
269+
echo "bailing out from the build early"
270+
exit 1
224271
225272
# https://github.com/fastly/js-compute-runtime/issues/361
226273
# TODO: Use engine-debug on all apps once we upgrade to FF 109

c-dependencies/js-compute-runtime/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11

22
# Build constants ##############################################################
33

4+
45
# The path to the directory containing this Makefile, the
56
# //c-dependencies/js-compute-runtime directory.
67
FSM_SRC := $(shell dirname "$(realpath $(firstword $(MAKEFILE_LIST)))")
78

89
# The path to the //c-dependencies directory.
910
ROOT_SRC := $(shell dirname "$(FSM_SRC)")
1011

12+
# The name of the project
13+
PROJECT_NAME := $(shell npm info "$(ROOT_SRC)/.." --json name)
14+
PROJECT_VERSION := $(shell npm info "$(ROOT_SRC)/.." --json version)
15+
1116
# Environmentally derived config ###############################################
1217

1318
# Build verbosity, useful when debugging build failures. Setting it to anything
@@ -62,6 +67,15 @@ else
6267
WASM_STRIP = wasm-opt --strip-debug -o $1 $1
6368
endif
6469

70+
# The path to the wasm-tools executable
71+
WASM_TOOLS ?= $(shell which wasm-tools)
72+
73+
ifeq ($(WASM_TOOLS),)
74+
$(error ERROR: "No wasm-tools found in PATH, consider running 'cargo install wasm-tools'")
75+
else
76+
WASM_METADATA = $(WASM_TOOLS) metadata add --sdk $(PROJECT_NAME)=$(PROJECT_VERSION) --output $1 $1
77+
endif
78+
6579
# The base build directory, where all our build artifacts go.
6680
BUILD := $(FSM_SRC)/build
6781

@@ -275,6 +289,7 @@ $(OBJ_DIR)/js-compute-runtime.wasm: $(OBJ_DIR)/c-at-e-world/c_at_e_world_adapter
275289
$(call cmd_format,WASI_LD,$@) PATH="$(FSM_SRC)/scripts:$$PATH" \
276290
$(WASI_CXX) $(LD_FLAGS) $(OPENSSL_LIBS) -o $@ $^
277291
$(call cmd_format,WASM_STRIP,$@) $(call WASM_STRIP,$@)
292+
$(call cmd_format,WASM_METADATA,$@) $(call WASM_METADATA,$@)
278293

279294
$(eval $(call compile_cxx,$(FSM_SRC)/impl/main.cpp))
280295

@@ -294,6 +309,7 @@ $(OBJ_DIR)/js-compute-runtime-component.wasm: $(OBJ_DIR)/c-at-e-world/c_at_e_wor
294309
$(call cmd_format,WASI_LD,$@) PATH="$(FSM_SRC)/scripts:$$PATH" \
295310
$(WASI_CXX) $(LD_FLAGS) $(OPENSSL_LIBS) -o $@ $^
296311
$(call cmd_format,WASM_STRIP,$@) $(call WASM_STRIP,$@)
312+
$(call cmd_format,WASM_METADATA,$@) $(call WASM_METADATA,$@)
297313

298314
$(eval $(call compile_cxx,$(FSM_SRC)/impl/main_component.cpp))
299315

0 commit comments

Comments
 (0)