[fastly compute build] scripts.build ignored with rust lang
fpalmier opened this issue · 5 comments
Version
Fastly CLI version v10.4.0 (4b869ab)
Built with go version go1.21.0 linux/amd64
Viceroy version: viceroy 0.5.1
What happened
I'm trying to use a cargo workspace for my Compute@Edge project.
fastly compute build
fail because of an invalid cargo command
Here is my Cargo.toml
[workspace]
resolver = "2"
members = [
"handler",
"core",
]
Here is my fastly.toml
authors = []
description = "todo"
language = "rust"
manifest_version = 3
name = "handler"
service_id = ""
[scripts]
build = "cargo build --bin handler --release --target wasm32-wasi --color always"
Here are the logs
Fastly API token provided via config file (profile: user)
Fastly API endpoint: https://api.fastly.com
✓ Verifying fastly.toml
✓ Identifying package name
✓ Identifying toolchain
INFO: Creating ./bin directory (for Wasm binary)
Command output for 'cargo locate-project --quiet': {"root":"/Users/francois/fastly-rust/Cargo.toml"}
INFO: The Fastly CLI requires a Rust version '>= 1.56.1'.
Build script to execute:
sh -c cargo build --bin --release --target wasm32-wasi --color always
INFO: Command output:
--------------------------------------------------------------------------------
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /Users/francois/fastly-rust/handler/Cargo.toml
workspace: /Users/francois/fastly-rust/Cargo.toml
error: "--bin" takes one argument.
Available binaries:
handler
--------------------------------------------------------------------------------
✗ Running [scripts.build]
ERROR: error during execution process (see 'command output' above): exit status 101.
It seem that modifyCargoPackageName
in /pkg/commands/compute/language_rust.go
overwrite the build script in fastly.toml with the default script.
Moreover, m.Package.Name
is blank when using a cargo workspace, I think it should fallback to the first binarie
Thanks for opening this issue @fpalmier
I've created a ticket internally to track this and will update the ticket once we have more information or have a resolution.
Hi @fpalmier
Thanks for your patience. I've been off ill the past few days so I've only just managed to circle back around to this issue.
I'm just trying at the moment to reproduce the error you've reported but I'm not having any luck in doing so.
I'm not a big Rust developer so it may be that I'm missing an important detail somewhere in the overall structure/configuration. I've detailed what I'm doing below, if you could take a look and let me know if this aligns with what you've been doing.
Thanks!
The approach I've taken is as follow...
mkdir testing-fastly-cli && cd testing-fastly-cli
mkdir compute && cd compute && fastly compute init --language rust
(and I choose a starter kit)touch ../Cargo.toml
(see below for my workspace Cargo.toml)- I add a build script to my
compute/fastly.toml
(which is basically the same as the default one, see screenshot below) fastly compute build --verbose
(within thecompute/
directory) which builds successfully.
[workspace]
members = ["compute"]
I also tried changing the name of the package to see if there was some unexpected logic bug that would cause a non-standard package name to be deleted (as you were seeing your handler
package name in the fastly.toml build script being deleted), and that didn't happen for me (see below screenshot)...
What's interesting though, is that I can see in your output that cargo locate-project
is picking up the root
as being the 'workspace' Cargo.toml, which of course isn't going to have a package name defined in the same place (in the workspace Cargo.toml all packages are defined in a members
array)...
Command output for 'cargo locate-project --quiet':
{"root":"/Users/francois/fastly-rust/Cargo.toml"}
Where for me, the cargo locate-project
command is picking up the correct Cargo.toml (the package one, not the workspace one) and so it sees the package name in the package Cargo.toml matches what's defined in the fastly.toml build script...
Command output for 'cargo locate-project --quiet':
{"root":"/Users/integralist/Code/test-projects/testing-fastly-cli/compute/Cargo.toml"}
The only thing I wasn't able to do, and which (to me at least) makes sense it wouldn't work, is being able to call cargo build
from the top-level Cargo 'workspace' directory (to build the entire workspace) because the compute/
project has a specific set of build flags that are handled by the Fastly CLI itself.
Hello @Integralist
sorry, I didn't mention that I moved the fastly.toml at the workspace level (I prefer to have it at the project root) and I call fastly compute build -v
from here.
My script.build command specify which member to build with the --bin option and other specific build flags. I tested to run it directly and everything is ok except that it not moving the main.wasm file to the bin folder.
When I call fastly compute build -v
my build.script is ignored.
Here is the process to reproduce the overwrite of the build script (without a workspace)
mkdir test-fastly
cd test-fastly
fastly compute init --language rust
add the a build script that do nothing in the fastly.toml
[scripts]
build = "echo fail"
run the fastly compute build -v
, it should fail to move the file
Change the name in name
in Cargo.toml
Re run the build command, the build will pass because it's using the default command
Sorry, I didn't have the time to look at your PR this weekend.
I'm still a rust beginner, but I think the rust-toolchain.toml file should alway be at workspace level. So, maybe check for the faslty depencie in the Corgo.toml will be safer option.
Anyway, thank you for your work, it will fix my issues with rust workspace.