cloudflare / workers-rs

Write Cloudflare Workers in 100% Rust via WebAssembly
Apache License 2.0
2.53k stars 269 forks source link

[Feature] Add custom build commands #647

Open joshka opened 6 days ago

joshka commented 6 days ago

Is there an existing issue for this?

Description

Custom build commands to support building on cloudflare should be something like:

build = { command = """\
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
    | sh -s -- -y \
        && . $HOME/.cargo/env \
        && rustup target add wasm32-unknown-unknown \
        && cargo install -q worker-build \
        && worker-build --release\
""" }

Note, this causes the same command to be run when using wrangler dev locally, which is a bit of a pain because you usually don't want to reinstall rustup etc. These are noops (at least in my own environment), but maybe not noops everywhere.

What I've actually done is added these to a prod environment and used that, but I'm not certain this is the right way to handle this either.

kflansburg commented 6 days ago

I'm not sure what this is asking for, we do support custom builds with exactly this syntax (not sure about multi-line, but that is a TOML thing). Are you saying that Workers CI should respect this configuration and doesn't today?

joshka commented 6 days ago

Sorry, I was a little ambiguous in my ask. I meant that these build commands should be documented, vetted for correctness, and added to the templates so that users don't have to search to work out how to make the applications generated from templates work with the cloudflare build. It was surprising to see a failure immediately when hooking up my github repo for the first time, and to have no documentation about what was necessary to make it work. After searching github issues, docs, etc. I eventually found guidance in a discord comment on how to get this working. I don't yet know what's the right way to only run this when building on cloudflare and not when building locally.

So to be more clear:

  1. Document the integration with rust apps and workers build (perhaps this is available, but my search didn't turn up anything relevant in the docs site).
  2. Include this by default in the templates (or include a link to how to configure this)
  3. Document the errors better in cloudflare build when this fails
  4. Consider adding rust to the build server setup so this isn't a problem generally
kflansburg commented 6 days ago

I was planning to have Rust and worker-build added to the default build image which will hopefully eliminate this issue.