fermyon / leptos-spin

Integration library for running server-side Leptos apps on Spin
31 stars 6 forks source link

spin build --up fails because project-name in template wasn't instantiated #12

Open Boscop opened 8 months ago

Boscop commented 8 months ago
$ spin build --up
Building component my-leptos-app with `cargo leptos build --release && LEPTOS_OUTPUT_NAME=my_leptos_app cargo build --lib --target wasm32-wasi --release --no-default-features --features ssr`
error: invalid character `{` in package name: `{{project-name | kebab_case}}`, the first character must be a Unicode XID start character (most letters or `_`)
 --> C:\Users\me\scoop\persist\rustup\.cargo\git\checkouts\leptos-spin-8ab45c2d3a8bc267\fe67739\templates\leptos-ssr\content\Cargo.toml:2:8
  |
2 | name = "{{project-name | kebab_case}}"
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
    Finished release [optimized] target(s) in 0.14s
       Cargo finished cargo build --package=my-leptos-app --lib --target-dir=D:\dev\proj\my-leptos-app\target\front --target=wasm32-unknown-unknown --no-default-features --features=hydrate --release
       Front compiling WASM
error: invalid character `{` in package name: `{{project-name | kebab_case}}`, the first character must be a Unicode XID start character (most letters or `_`)
 --> C:\Users\me\scoop\persist\rustup\.cargo\git\checkouts\leptos-spin-8ab45c2d3a8bc267\fe67739\templates\leptos-ssr\content\Cargo.toml:2:8
  |
2 | name = "{{project-name | kebab_case}}"
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
    Finished release [optimized] target(s) in 0.15s
       Cargo finished cargo build --package=my-leptos-app --bin=my-leptos-app --no-default-features --features=ssr --release
'LEPTOS_OUTPUT_NAME' is not recognized as an internal or external command,
operable program or batch file.
Error: Build command for component my-leptos-app failed with status Exited(1)
itowlson commented 8 months ago

I'm not quite sure what's going on here. It seems like some people are seeing that when Cargo tries to build a Git reference it picks up files that are not part of the crate. @benwis mentioned he saw the message but it didn't prevent the build. And I'm not seeing it at all.

@Boscop Could you share what version of Cargo you're running please?

@dicej @rylev Do you have any idea why this might be happening?

rylev commented 8 months ago

I think we'll need a more consistent way to reproduce this before being able to say what the root cause is.

benwis commented 8 months ago

I'll try to give more details Rust: 1.77.0-nightly(latest as of Jan 18) Spin spin 2.2.0-pre0 (b435f831 1980-01-01) spin-cloud 0.5.1 (7c32d40 1980-01-01) Nixos 24.05 Building the repo here: https://github.com/benwis/benwis_spin and here's the build log of spin build build_log.txt

As he said, everything still builds and deploys fine for me, those messages just seem odd. My rudimentary theory is that they're coming from rust itself, and may be an issue with nightly?

Boscop commented 8 months ago

For me it's also failing because this syntax of setting env vars doesn't work on windows:

command = "cargo leptos build --release && LEPTOS_OUTPUT_NAME=benwis_spin cargo build --lib --target wasm32-wasi --release --no-default-features --features ssr"

Is there a platform-agnostic way to write this build command?

Or is it possible to remove the need for having this env var in the first place? :)


Btw, I see watch = ["src/**/*.rs", "Cargo.toml"], is this supposed to support hot reload? I'm asking because it's not hot-reloading when I modify the app.rs file..

Boscop commented 8 months ago

Btw, spin up --build worked when I set the env var outside (in cmd.exe) and then removed it from spin.toml.

But calling spin deploy directly afterwards failed:

>spin deploy
Error: Failed to load Spin app from "spin.toml"

Caused by:
    0: Failed to load component `pkg`
    1: Failed to load Wasm source "https://github.com/fermyon/spin-fileserver/releases/download/v0.1.0/spin_static_fs.wasm" with digest "sha256:96c76d9af86420b39eb6cd7be5550e3cb5d4cc4de572ce0fd1f6a29471536cb4"
    2: Error fetching source URL "https://github.com/fermyon/spin-fileserver/releases/download/v0.1.0/spin_static_fs.wasm"
    3: failed to persist temporary file path: The filename, directory name, or volume label syntax is incorrect. (os error 123)
    4: The filename, directory name, or volume label syntax is incorrect. (os error 123)

Learn more at https://developer.fermyon.com/cloud/faq

Could it be that the downloaded file's target path contains chars that are invalid in a windows path?

itowlson commented 8 months ago

@Boscop Yes, I'm afraid that spin build expression is not portable. This is all still very much in development and I'm sorry for the rough edges. Glad to hear you were able to work around it.

Re the error when deploying from Windows: this was meant to be fixed by https://github.com/fermyon/spin/pull/2159 but the cloud plugin (which spin deploy uses under the hood) might not have updated with that fix yet. I will test and confirm. Sorry for the bumpy experience and thanks for letting us know the problems you're running into.

itowlson commented 8 months ago

@Boscop I've reproduced your problem - the cloud plugin is using download code from before the Windows fix. I know we've already updated it but not done a release - I will see if we can get one out today.

itowlson commented 8 months ago

@Boscop cloud deploy fix is out. Please run

spin plugins update
spin plugins upgrade cloud

You should then have cloud plugin 0.6.1 and your Windows deploys should work! Sorry for the inconvenience.

Boscop commented 8 months ago

Thanks, it worked :) Btw, is there a way right now to make the command work in a cross-platform way?

itowlson commented 8 months ago

Not yet I'm afraid. We've chatted about allowing command to be an array, which would solve the && problem; maybe we need a way to specify environment variables for the build process too.