Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom lib name fails to resolve during build. #415

Open
twitchax opened this issue Jan 11, 2025 · 2 comments
Open

Custom lib name fails to resolve during build. #415

twitchax opened this issue Jan 11, 2025 · 2 comments

Comments

@twitchax
Copy link

It appears as though the lib name is just the name of the package.

This has the unfortunate side effect that a custom lib name does not get properly picked up when using serve or build, resulting an error when the front compilation tries to find {package_name}.wasm instead of {lib_name}.wasm.

Example

       Cargo finished cargo build --package=my_pkg--lib --target-dir=... --target=wasm32-unknown-unknown --features=hydrate
       Front compiling WASM
Error: at `...\cargo-leptos-0.2.24\src\command\serve.rs:8:46`

Caused by:
    0: at `...\cargo-leptos-0.2.24\src\compile\front.rs:51:30`
    1: at `...\cargo-leptos-0.2.24\src\compile\front.rs:126:10`
    2: failed reading 'target\front\wasm32-unknown-unknown\debug\my_pkg.wasm'
    3: The system cannot find the file specified. (os error 2)

Meanwhile, the Cargo.toml has:

[lib]
name = "my_lib"
@Boscop
Copy link

Boscop commented Jan 28, 2025

This makes it impossible to use a different name for the lib than for the bin, which makes it very annoying on Windows due to a very verbose filename collision warning when bin and lib have the same name:

The bin target `my-crate-name` in package `my-crate-name v0.1.0 (D:\dev\proj\my-crate-name)` has the same output filename as the lib target `my_crate_name` in package `my-crate-name v0.1.0 (D:\dev\proj\my-crate-name)`.
Colliding filename is: D:\dev\proj\my-crate-name\target\debug\deps\my_crate_name.pdb
The output filenames should be unique.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
If this looks unexpected, it may be a bug in Cargo. Please file a bug report at
https://github.com/rust-lang/cargo/issues/ with as much information as you
can provide.
cargo 1.86.0-nightly (045bf21b3 2025-01-17) running on `x86_64-pc-windows-msvc` target `x86_64-pc-windows-msvc`
First unit: Unit { pkg: Package { id: PackageId { name: "my-crate-name", version: "0.1.0", source: "D:\\dev\\proj\\my-crate-name" }, ..: ".." }, target: TargetInner { name: "my-crate-name", doc: true, ..: with_path("D:\\dev\\proj\\my-crate-name\\src\\main.rs", Edition2021) }, profile: Profile { ..: default_dev() }, kind: Host, mode: Build, features: ["ssr"], rustflags: [], rustdocflags: [], links_overrides: {}, artifact: false, artifact_target_for_features: None, is_std: false, dep_hash: 11289378980986173007 }     
Second unit: Unit { pkg: Package { id: PackageId { name: "my-crate-name", version: "0.1.0", source: "D:\\dev\\proj\\my-crate-name" }, ..: ".." }, target: TargetInner { name_inferred: true, ..: lib_target("my_crate_name", ["cdylib", "rlib"], "D:\\dev\\proj\\my-crate-name\\src\\lib.rs", Edition2021) }, profile: Profile { ..: default_dev() }, kind: Host, mode: Build, features: ["ssr"], rustflags: [], rustdocflags: [], links_overrides: {}, artifact: false, artifact_target_for_features: None, is_std: false, dep_hash: 3781515406898347355 }

@anvlkv
Copy link

anvlkv commented Feb 5, 2025

Hi, think I'm facing the same issue.

Suppose my package is set up like this:

[package]
name = "web"
version = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }

[[bin]]
name = "web_ssr"
path = "src/bin/ssr.rs"
required-features = ["ssr"]

[[bin]]
name = "web_csr"
path = "src/bin/csr.rs"
required-features = ["csr"]


[lib]
name = "web_app"
crate-type = ["cdylib", "rlib"]

[dependencies]
bevy = { workspace = true, optional = true, default-features = false, features = [
    "webgl2",
] }
console_error_panic_hook = "0.1"
cfg-if = "1"
leptos = { version = "0.7.5", features = ["nightly"] }
leptos-bevy-canvas = { version = "0.1.0", optional = true }
leptos-use = "0.15.1"
leptos_meta = { version = "0.7.5" }
leptos_router = { version = "0.7.5" }
leptos_wasi = { version = "0.1.3", optional = true }
spin-sdk = { version = "3", optional = true }
# spin pathc
wasi = { version = "=0.13.2", optional = true }
wasm-bindgen = { version = "=0.2.100", optional = true }

[package.metadata.leptos]
output-name = "web_app"
# bin
bin-target = "web_ssr"
bin-features = ["ssr"]
bin-default-features = false
lib-target = "web_app"
lib-features = ["hydrate"]
lib-default-features = false
# style
style-file = "style/main.scss"
....

As you probably imagine rebuilding things for spin with leptos building hydrate and ssr builds in rust takes not a little while 🙃. At least on my laptop...
Naturally I would want to use trunk during some development iterations.

My spin.toml:

...

[component.web]
source = "./target/wasm32-wasip1/release/web_app.wasm"
allowed_outbound_hosts = []
key_value_stores = ["default"]
[component.web.build]
command = "export LEPTOS_OUTPUT_NAME=web_app && cargo leptos build --release && cargo build -p web_ssr --target wasm32-wasip1 --release --no-default-features --features ssr"
watch = [
    "./web/src/**/*.rs",
    "./web/Cargo.toml",
...
]

...

Sadly I fail like this:


       Front generating JS/WASM with wasm-bindgen
Error: at `/Users/anvlkv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cargo-leptos-0.2.27/src/compile/front.rs:48:30`

Caused by:
    0: at `/Users/anvlkv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cargo-leptos-0.2.27/src/compile/front.rs:125:10`
    1: failed reading 'target/front/wasm32-unknown-unknown/release/web.wasm'
    2: No such file or directory (os error 2)
Error: Build command for component web failed with status Exited(1)

It appears these file names are set here github.com/leptos-rs/cargo-leptos/.../project.rs#L397C2-L404C11 and then here

Would it make sense to change LibPackage::resolve to do the same thing with lib-target as BinPackage::resolve does here with bin-target or would it brake something along the way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants