Skip to content

Commit 9a2a95b

Browse files
Reapply "breaking(language.rust): switch Rust builds to wasm32-wasip1 from wasm32-wasi (#1382)" (#1436)
This reverts commit 3d20662.
1 parent 6d88e7f commit 9a2a95b

9 files changed

Lines changed: 76 additions & 37 deletions

File tree

.fastly/config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ toolchain_constraint = ">= 1.21" # Go toolchain constraint for use wit
1818
toolchain_constraint_tinygo = ">= 1.18" # Go toolchain constraint for use with TinyGo.
1919

2020
[language.rust]
21-
toolchain_constraint = ">= 1.56.1, <1.84.0"
22-
wasm_wasi_target = "wasm32-wasi"
21+
toolchain_constraint = ">= 1.78.0"
22+
wasm_wasi_target = "wasm32-wasip1"
2323

2424
[wasm-tools]
2525
ttl = "24h"

.github/workflows/pr_test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: "Checkout code"
2424
uses: actions/checkout@v4
2525
- name: "Install Rust"
26-
uses: dtolnay/rust-toolchain@1.83.0 # to install tq via `make config`
26+
uses: dtolnay/rust-toolchain@stable
2727
- name: "Generate static app config"
2828
run: make config
2929
- name: "Config Artifact"
@@ -37,7 +37,7 @@ jobs:
3737
- name: "Checkout code"
3838
uses: actions/checkout@v4
3939
- name: "Install Rust"
40-
uses: dtolnay/rust-toolchain@1.83.0 # to install tq via `make config`
40+
uses: dtolnay/rust-toolchain@stable
4141
- name: Install Go
4242
uses: actions/setup-go@v5
4343
with:
@@ -89,11 +89,11 @@ jobs:
8989
with:
9090
tinygo-version: ${{ matrix.tinygo-version }}
9191
- name: "Install Rust"
92-
uses: dtolnay/rust-toolchain@1.83.0
93-
- name: "Add wasm32-wasi Rust target"
94-
run: rustup target add wasm32-wasi --toolchain 1.83.0
92+
uses: dtolnay/rust-toolchain@stable
93+
- name: "Add wasm32-wasip1 Rust target"
94+
run: rustup target add wasm32-wasip1 --toolchain stable
9595
- name: "Validate Rust toolchain"
96-
run: rustup show && rustup target list --installed --toolchain 1.83.0
96+
run: rustup show && rustup target list --installed --toolchain stable
9797
shell: bash
9898
- name: "Install Node"
9999
uses: actions/setup-node@v4

.github/workflows/tag_to_draft_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
with:
1818
go-version: '1.23.x'
1919
- name: "Install Rust"
20-
uses: dtolnay/rust-toolchain@1.83.0
20+
uses: dtolnay/rust-toolchain@stable
2121
- name: "Generate static app config"
2222
run: make config
2323
# Passing the raw SSH private key causes an error:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
has been removed; it was only used in combination with the Fastly
99
WAF, which is no longer supported.
1010
[#1419](https://github.com/fastly/cli/pull/1419)
11+
- breaking(language.rust): Switch Rust builds to wasm32-wasip1 instead of wasm32-wasi [#1382](https://github.com/fastly/cli/pull/1382)
1112

1213
**Enhancements:**
1314

Dockerfile-rust

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
FROM rust:latest
22
LABEL maintainer="Fastly OSS <oss@fastly.com>"
33

4-
ENV RUST_TOOLCHAIN=1.83.0
4+
ENV RUST_TOOLCHAIN=stable
55
RUN rustup toolchain install ${RUST_TOOLCHAIN} \
6-
&& rustup target add wasm32-wasi --toolchain ${RUST_TOOLCHAIN} \
6+
&& rustup target add wasm32-wasip1 --toolchain ${RUST_TOOLCHAIN} \
77
&& apt-get update && apt-get install -y curl jq && apt-get -y clean && rm -rf /var/lib/apt/lists/* \
88
&& export FASTLY_CLI_VERSION=$(curl -s https://api.github.com/repos/fastly/cli/releases/latest | jq -r .tag_name | cut -d 'v' -f 2) \
99
GOARCH=$(dpkg --print-architecture) \

TESTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ TEST_COMPUTE_BUILD_RUST=1 make test TEST_ARGS="-run TestBuildRust/fastly_crate_p
4343

4444
When running the tests locally, if you don't have the relevant language ecosystems set-up properly then the tests will fail to run and you'll need to review the code to see what the remediation steps are, as that output doesn't get shown when running the test suite.
4545

46-
> **NOTE**: you might notice a discrepancy between CI and your local environment which is caused by the difference in Rust toolchain versions as defined in .github/workflows/pr_test.yml which specifies the version required to be tested for in CI. Running `rustup toolchain install <version>` and `rustup target add wasm32-wasi --toolchain <version>` will resolve any failing integration tests you may be running locally.
46+
> **NOTE**: you might notice a discrepancy between CI and your local environment which is caused by the difference in Rust toolchain versions as defined in .github/workflows/pr_test.yml which specifies the version required to be tested for in CI. Running `rustup toolchain install <version>` and `rustup target add wasm32-wasip1 --toolchain <version>` will resolve any failing integration tests you may be running locally.
4747
4848
To the run the full test suite:
4949

pkg/commands/compute/build_test.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func TestBuildRust(t *testing.T) {
7373
Profiles: testutil.TokenProfile(),
7474
Language: config.Language{
7575
Rust: config.Rust{
76-
ToolchainConstraint: ">= 1.54.0",
77-
WasmWasiTarget: "wasm32-wasi",
76+
ToolchainConstraint: ">= 1.78.0",
77+
WasmWasiTarget: "wasm32-wasip1",
7878
},
7979
},
8080
},
@@ -102,8 +102,8 @@ func TestBuildRust(t *testing.T) {
102102
Profiles: testutil.TokenProfile(),
103103
Language: config.Language{
104104
Rust: config.Rust{
105-
ToolchainConstraint: ">= 1.54.0",
106-
WasmWasiTarget: "wasm32-wasi",
105+
ToolchainConstraint: ">= 1.78.0",
106+
WasmWasiTarget: "wasm32-wasip1",
107107
},
108108
},
109109
},
@@ -123,6 +123,34 @@ func TestBuildRust(t *testing.T) {
123123
build = "echo no compilation happening"`,
124124
wantRemediationError: compute.DefaultBuildErrorRemediation,
125125
},
126+
{
127+
name: "wasmwasi target error",
128+
args: args("compute build --verbose"),
129+
applicationConfig: &config.File{
130+
Profiles: testutil.TokenProfile(),
131+
Language: config.Language{
132+
Rust: config.Rust{
133+
ToolchainConstraint: ">= 1.78.0",
134+
WasmWasiTarget: "wasm32-wasi",
135+
},
136+
},
137+
},
138+
cargoManifest: `
139+
[package]
140+
name = "fastly-compute-project"
141+
version = "0.1.0"
142+
143+
[dependencies]
144+
fastly = "=0.6.0"`,
145+
fastlyManifest: fmt.Sprintf(`
146+
manifest_version = 2
147+
name = "test"
148+
language = "rust"
149+
150+
[scripts]
151+
build = "%s"`, fmt.Sprintf(compute.RustDefaultBuildCommand, compute.RustDefaultPackageName, compute.RustDefaultWasmWasiTarget)),
152+
wantError: "the default build in .fastly/config.toml should produce a wasm32-wasip1 binary, but was instead set to produce a wasm32-wasi binary",
153+
},
126154
// NOTE: This test passes --verbose so we can validate specific outputs.
127155
{
128156
name: "successful build",
@@ -131,8 +159,8 @@ func TestBuildRust(t *testing.T) {
131159
Profiles: testutil.TokenProfile(),
132160
Language: config.Language{
133161
Rust: config.Rust{
134-
ToolchainConstraint: ">= 1.54.0",
135-
WasmWasiTarget: "wasm32-wasi",
162+
ToolchainConstraint: ">= 1.78.0",
163+
WasmWasiTarget: "wasm32-wasip1",
136164
},
137165
},
138166
},
@@ -149,7 +177,7 @@ func TestBuildRust(t *testing.T) {
149177
language = "rust"
150178
151179
[scripts]
152-
build = "%s"`, fmt.Sprintf(compute.RustDefaultBuildCommand, compute.RustDefaultPackageName)),
180+
build = "%s"`, fmt.Sprintf(compute.RustDefaultBuildCommand, compute.RustDefaultPackageName, compute.RustDefaultWasmWasiTarget)),
153181
wantOutput: []string{
154182
"Creating ./bin directory (for Wasm binary)",
155183
"Built package",

pkg/commands/compute/language_rust.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import (
3030
// NOTE: In the 5.x CLI releases we persisted the default to the fastly.toml
3131
// We no longer do that. In 6.x we use the default and just inform the user.
3232
// This makes the experience less confusing as users didn't expect file changes.
33-
const RustDefaultBuildCommand = "cargo build --bin %s --release --target wasm32-wasi --color always"
33+
const RustDefaultBuildCommand = "cargo build --bin %s --release --target %s --color always"
34+
35+
// RustDefaultWasmWasiTarget is the expected Rust WasmWasi build target
36+
const RustDefaultWasmWasiTarget = "wasm32-wasip1"
3437

3538
// RustManifest is the manifest file for defining project configuration.
3639
const RustManifest = "Cargo.toml"
@@ -145,7 +148,7 @@ func (r *Rust) Dependencies() map[string]string {
145148
// Build compiles the user's source code into a Wasm binary.
146149
func (r *Rust) Build() error {
147150
if r.build == "" {
148-
r.build = fmt.Sprintf(RustDefaultBuildCommand, RustDefaultPackageName)
151+
r.build = fmt.Sprintf(RustDefaultBuildCommand, RustDefaultPackageName, RustDefaultWasmWasiTarget)
149152
r.defaultBuild = true
150153
}
151154

@@ -170,6 +173,11 @@ func (r *Rust) Build() error {
170173
}
171174
}
172175

176+
var wasmWasiTarget = r.config.WasmWasiTarget
177+
if wasmWasiTarget != RustDefaultWasmWasiTarget {
178+
return fmt.Errorf("the default build in .fastly/config.toml should produce a %s binary, but was instead set to produce a %s binary", RustDefaultWasmWasiTarget, wasmWasiTarget)
179+
}
180+
173181
bt := BuildToolchain{
174182
autoYes: r.autoYes,
175183
buildFn: r.Shell.Build,
@@ -204,7 +212,7 @@ type RustToolchain struct {
204212
// modifyCargoPackageName validates whether the --bin flag matches the
205213
// Cargo.toml package name. If it doesn't match, update the default build script
206214
// to match.
207-
func (r *Rust) modifyCargoPackageName(noBuildScript bool) error {
215+
func (r *Rust) modifyCargoPackageName(defaultBuild bool) error {
208216
s := "cargo locate-project --quiet"
209217
args := strings.Split(s, " ")
210218

@@ -244,18 +252,16 @@ func (r *Rust) modifyCargoPackageName(noBuildScript bool) error {
244252
return fmt.Errorf("error reading %s manifest: %w", RustManifest, err)
245253
}
246254

247-
hasCustomBuildScript := !noBuildScript
248-
249255
switch {
250256
case m.Package.Name != "":
251257
// If using standard project structure.
252258
// Cargo.toml won't be a Workspace, so it will contain a package name.
253259
r.packageName = m.Package.Name
254-
case len(m.Workspace.Members) > 0 && noBuildScript:
260+
case len(m.Workspace.Members) > 0 && defaultBuild:
255261
// If user has a Cargo Workspace AND no custom script.
256262
// We need to identify which Workspace package is their application.
257263
// Then extract the package name from its Cargo.toml manifest.
258-
// We do this by checking for a rust-toolchain.toml containing a wasm32-wasi target.
264+
// We do this by checking for a rust-toolchain.toml containing the proper target.
259265
//
260266
// NOTE: This logic will need to change in the future.
261267
// Specifically, when we support linking multiple Wasm binaries.
@@ -270,16 +276,20 @@ func (r *Rust) modifyCargoPackageName(noBuildScript bool) error {
270276
if err != nil {
271277
return fmt.Errorf("failed to unmarshal '%s' data: %w", rustToolchainFile, err)
272278
}
273-
if len(rtm.Toolchain.Targets) > 0 && rtm.Toolchain.Targets[0] == "wasm32-wasi" {
274-
var cm CargoManifest
275-
err := cm.Read(filepath.Join(m, "Cargo.toml"))
276-
if err != nil {
277-
return err
279+
if len(rtm.Toolchain.Targets) > 0 {
280+
if rtm.Toolchain.Targets[0] == RustDefaultWasmWasiTarget {
281+
var cm CargoManifest
282+
err := cm.Read(filepath.Join(m, "Cargo.toml"))
283+
if err != nil {
284+
return err
285+
}
286+
r.packageName = cm.Package.Name
287+
} else {
288+
return fmt.Errorf("please consult https://www.fastly.com/documentation/guides/compute/#install-language-tooling to configure your toolchain correctly")
278289
}
279-
r.packageName = cm.Package.Name
280290
}
281291
}
282-
case len(m.Workspace.Members) > 0 && hasCustomBuildScript:
292+
case len(m.Workspace.Members) > 0 && !defaultBuild:
283293
// If user has a Cargo Workspace AND a custom script.
284294
// Trust their custom script aligns with the relevant Workspace package name.
285295
// i.e. we parse the package name specified in their custom script.
@@ -293,8 +303,8 @@ func (r *Rust) modifyCargoPackageName(noBuildScript bool) error {
293303
}
294304

295305
// Ensure the default build script matches the Cargo.toml package name.
296-
if noBuildScript && r.packageName != "" && r.packageName != RustDefaultPackageName {
297-
r.build = fmt.Sprintf(RustDefaultBuildCommand, r.packageName)
306+
if defaultBuild && r.packageName != "" && r.packageName != RustDefaultPackageName {
307+
r.build = fmt.Sprintf(RustDefaultBuildCommand, r.packageName, RustDefaultWasmWasiTarget)
298308
}
299309

300310
return nil

pkg/config/testdata/config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ version = "0.0.1"
1111

1212
[language]
1313
[language.rust]
14-
toolchain_constraint = ">= 1.49.0 < 2.0.0"
15-
wasm_wasi_target = "wasm32-wasi"
14+
toolchain_constraint = ">= 1.78.0"
15+
wasm_wasi_target = "wasm32-wasip1"
1616

1717
[starter-kits]
1818
[[starter-kits.assemblyscript]]

0 commit comments

Comments
 (0)