Code Monkey home page Code Monkey logo

cargo-leptos's Introduction

crates.io Discord

Build tool for Leptos:

Leptos Logo



Features

  • Parallel build of server and client in watch mode for fast developer feedback.
  • CSS hot-reload (no page-reload, only CSS updated).
  • Build server and client for hydration (client-side rendering mode not supported).
  • Support for both workspace and single-package setup.
  • SCSS compilation using dart-sass.
  • CSS transformation and minification using Lightning CSS.
  • Builds server and client (wasm) binaries using Cargo.
  • Generates JS - Wasm bindings with wasm-bindgen
    • Includes support for JS Snippets for when you want to call some JS code from your WASM.
  • Optimises the wasm with wasm-opt from Binaryen
  • watch command for automatic rebuilds with browser live-reload.
  • test command for running tests of the lib and bin packages that makes up the Leptos project.
  • build build the server and client.
  • end-to-end command for building, running the server and calling a bash shell hook. The hook would typically launch Playwright or similar.
  • new command for creating a new project based on templates, using cargo-generate. Current templates include
  • 'no_downloads' feature to allow user management of optional dependencies

Getting started

Install:

cargo install --locked cargo-leptos

If you, for any reason, need the bleeding-edge super fresh version:

cargo install --git https://github.com/leptos-rs/cargo-leptos --locked cargo-leptos

Help:

cargo leptos --help

For setting up your project, have a look at the examples


Dependencies

The dependencies for sass, wasm-opt and cargo-generate are automatically installed in a cache directory when they are used if they are not already installed and found by which. Different versions of the dependencies might accumulate in this directory, so feel free to delete it.

OS Example
Linux /home/alice/.cache/cargo-leptos
macOS /Users/Alice/Library/Caches/cargo-leptos
Windows C:\Users\Alice\AppData\Local\cargo-leptos

If you wish to make it mandatory to install your dependencies, or are using Nix or NixOs, you can install it with the no_downloads feature enabled to prevent cargo-leptos from trying to download and install them.

cargo install --features no_downloads --locked cargo-leptos


Single-package setup

The single-package setup is where the code for both the frontend and the server is defined in a single package.

Configuration parameters are defined in the package Cargo.toml section [package.metadata.leptos]. See the Parameters reference for a full list of parameters that can be used. All paths are relative to the package root (i.e. to the Cargo.toml file)


Workspace setup

When using a workspace setup both single-package and multi-package projects are supported. The latter is when the frontend and the server reside in different packages.

All workspace members whose Cargo.toml define the [package.metadata.leptos] section are automatically included as Leptos single-package projects. The multi-package projects are defined on the workspace level in the Cargo.toml's section [[workspace.metadata.leptos]] which takes three mandatory parameters:

[[workspace.metadata.leptos]]
# project name
name = "leptos-project"
bin-package = "server"
lib-package = "front"

# more configuration parameters...

Note the double braces: several projects can be defined and one package can be used in several projects.


Build features

When building with cargo-leptos, the frontend, library package, is compiled into wasm using target wasm-unknown-unknown and the features --no-default-features --features=hydrate The server binary is compiled with the features --no-default-features --features=ssr


Parameters reference

These parameters are used either in the workspace section [[workspace.metadata.leptos]] or the package, for single-package setups, section [package.metadata.leptos].

Note that the Cargo Manifest uses the word target with two different meanings. As a package's configured [[bin]] targets and as the compiled output target triple. Here, the latter is referred to as target-triple.

Compilation parameters

# Sets the name of the binary target used.
#
# Optional, only necessary if the bin-package defines more than one target. Can also be set with the LEPTOS_BIN_TARGET=name env var
bin-target = "my-bin-name"

# Enables additional file hashes on outputted css, js, and wasm files
#
# Optional: Defaults to false. Can also be set with the LEPTOS_HASH_FILES=false env var (must be set at runtime too)
hash-files = false

# Sets the name for the file cargo-leptos uses to track the most recent hashes
#
# Optional: Defaults to "hash.txt". Can also be set with the LEPTOS_HASH_FILE_NAME="hash.txt" env var
hash-file-name = "hash.txt"

# The features to use when compiling all targets
#
# Optional. Can be extended with the command line parameter --features
features = []

# The features to use when compiling the bin target
#
# Optional. Can be over-ridden with the command line parameter --bin-features
bin-features = ["ssr"]

# If the --no-default-features flag should be used when compiling the bin target
#
# Optional. Defaults to false.
bin-default-features = false

# The profile to use for the bin target when compiling for release
#
# Optional. Defaults to "release".
bin-profile-release = "my-release-profile"

# The profile to use for the bin target when compiling for debug
#
# Optional. Defaults to "debug".
bin-profile-dev = "my-debug-profile"

# The target triple to use when compiling the bin target
#
# Optional. Env: LEPTOS_BIN_TARGET_TRIPLE
bin-target-triple = "x86_64-unknown-linux-gnu"

# The features to use when compiling the lib target
#
# Optional. Can be over-ridden with the command line parameter --lib-features
lib-features = ["hydrate"]

# If the --no-default-features flag should be used when compiling the lib target
#
# Optional. Defaults to false.
lib-default-features = false

# The profile to use for the lib target when compiling for release
#
# Optional. Defaults to "release".
lib-profile-release = "my-release-profile"

# The profile to use for the lib target when compiling for debug
#
# Optional. Defaults to "debug".
lib-profile-dev = "my-debug-profile"

# Fixes cargo bug that prevents incremental compilation (see #203)
#
# Optional. Defaults to false prior to 0.2.3, unconditionally enabled (with the setting becoming deprecated) since 0.2.3 and #216
separate-front-target-dir = true

# Pass additional parameters to the cargo process compiling to WASM
#
# Optional. No default
lib-cargo-args = ["--timings"]

# Pass additional parameters to the cargo process to build the server
#
# Optional. No default
bin-cargo-args = ["--timings"]

# The command to run instead of "cargo" when building the server
#
# Optional. No default. Env: LEPTOS_BIN_CARGO_COMMAND
bin-cargo-command = "cross"

Site parameters

These parameters can be overridden by setting the corresponding environment variable. They can also be set in a .env file as cargo-leptos reads the first it finds in the package or workspace directory and any parent directory.

# Sets the name of the output js, wasm and css files.
#
# Optional, defaults to the lib package name or, in a workspace, the project name. Env: LEPTOS_OUTPUT_NAME.
output-name = "myproj"

# The site root folder is where cargo-leptos generate all output.
# NOTE: It is relative to the workspace root when running in a workspace.
# WARNING: all content of this folder will be erased on a rebuild!
#
# Optional, defaults to "/site" in the Cargo target directory. Env: LEPTOS_SITE_ROOT.
site-root = "target/site"

# The site-root relative folder where all compiled output (JS, WASM and CSS) is written.
#
# Optional, defaults to "pkg". Env: LEPTOS_SITE_PKG_DIR.
site-pkg-dir = "pkg"

# The source style file. If it ends with _.sass_ or _.scss_ then it will be compiled by `dart-sass`
# into CSS and processed by lightning css. When release is set, then it will also be minified.
#
# Optional. Env: LEPTOS_STYLE_FILE.
style-file = "style/main.scss"

# The tailwind input file.
#
# Optional, Activates the tailwind build
tailwind-input-file = "style/tailwind.css"

# The tailwind config file.
#
# Optional, defaults to "tailwind.config.js" which if is not present
# is generated for you
tailwind-config-file = "tailwind.config.js"

# The browserlist https://browsersl.ist query used for optimizing the CSS.
#
# Optional, defaults to "defaults". Env: LEPTOS_BROWSERQUERY.
browserquery = "defaults"

# Assets source dir. All files found here will be copied and synchronized to site-root.
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
#
# Optional. Env: LEPTOS_ASSETS_DIR.
assets-dir = "assets"

# JS source dir. `wasm-bindgen` has the option to include JS snippets from JS files
# with `#[wasm_bindgen(module = "/js/foo.js")]`. A change in any JS file in this dir
# will trigger a rebuild.
#
# Optional. Defaults to "src"
js-dir = "src"

# Additional files your application could depends on.
# A change to any file in those directories will trigger a rebuild.
#
# Optional.
watch-additional-files = ["additional_files", "custom_config.json"]

# The IP and port where the server serves the content. Use it in your server setup.
#
# Optional, defaults to 127.0.0.1:3000. Env: LEPTOS_SITE_ADDR.
site-addr = "127.0.0.1:3000"

# The port number used by the reload server (only used in watch mode).
#
# Optional, defaults 3001. Env: LEPTOS_RELOAD_PORT
reload-port = 3001

# The command used for running end-to-end tests. See the section about End-to-end testing.
#
# Optional. Env: LEPTOS_END2END_CMD.
end2end-cmd = "npx playwright test"

# The directory from which the end-to-end tests are run.
#
# Optional. Env: LEPTOS_END2END_DIR
end2end-dir = "integration"

Environment variables

The following environment variables are set when compiling the lib (front) or bin (server) and when the server is run.

Echoed from the Leptos config:

  • LEPTOS_OUTPUT_NAME
  • LEPTOS_SITE_ROOT
  • LEPTOS_SITE_PKG_DIR
  • LEPTOS_SITE_ADDR
  • LEPTOS_RELOAD_PORT

Directories used when building:

  • LEPTOS_LIB_DIR: The path (relative to the working directory) to the library package
  • LEPTOS_BIN_DIR: The path (relative to the working directory) to the binary package

Note when using directories:

  • cargo-leptos changes the working directory to the project root or if in a workspace, the workspace root before building and running.
  • the two are set to the same value when running in a single-package config.
  • Avoid using them at run-time unless you can guarantee that the entire project struct is available at runtime as well.

Internally the versions of the external tools called by cargo-leptos are hardcoded. Use these environment variables to override the versions cargo-leptos should use (e.g. LEPTOS_SASS_VERSION=1.69.5):

  • LEPTOS_CARGO_GENERATE_VERSION
  • LEPTOS_TAILWIND_VERSION
  • LEPTOS_SASS_VERSION
  • LEPTOS_WASM_OPT_VERSION

End-to-end testing

cargo-leptos provides end-to-end testing support for convenience. It is a simple wrapper around a shell command end2end-cmd that is executed in a specific directory end2end-dir.

The end2end-cmd can be any shell command. For running Playwright it would be npx playwright test.

What it does is equivalent to running this manually:

  • in a terminal, run cargo leptos watch
  • in a separate terminal, change to the end2end-dir and run the end2end-cmd.

When testing the setup, please try the above first. If that works but cargo leptos end-to-end doesn't then please create a GitHub ticket.

cargo-leptos's People

Contributors

akesson avatar aperepel avatar aqrln avatar baptistemontan avatar benwis avatar chrisp60 avatar christopherbiscardi avatar crapstone avatar emilgardis avatar gbj avatar indrazar avatar lephyrius avatar maccesch avatar maneren avatar martinfrances107 avatar michalvavra avatar morenol avatar mtsr avatar niclas-ahden avatar nim65s avatar pati08 avatar paul-hansen avatar phillipbaird avatar prscoelho avatar ptillemans avatar rakshith-ravi avatar raniz85 avatar rdbo avatar stewartadam avatar tyoeer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cargo-leptos's Issues

cargo leptos test - not running integration tests.

Problem Description

Given, a workspace project structure where the server contains integration tests in a tests directory...

/app
/front
/server
    /src
    /test
        integration.rs

when, you run cargo leptos test
then, the integration tests are not run.

Cause

The build_cargo_server_cmd() function in compiler/server.rs always includes the --bin option.
For tests this restricts us to unit tests in the server binary.

Possible Solution

One possible solution would be to change build_cargo_server_cmd() so that --bin is not included when running tests.

Thoughts?

Windows warning: output filename collision

Summary of discord exchange

Full error mesage
PS [project_dir]> cargo leptos watch --release
warning: output filename collision.
The bin target `leptos_start` in package `leptos_start v0.1.0 ([project_dir])` has the same output filename as the lib target `leptos_start` in package `leptos_start v0.1.0 ([project_dir])`.
Colliding filename is: [project_dir]\target/server\release\deps\leptos_start.pdb
The targets should have unique names.
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>.
    Finished release [optimized] target(s) in 0.20s
       Cargo finished cargo build --package=leptos_start --bin=leptos_start --target-dir=target/server --no-default-features --features=ssr --release
    Finished release [optimized] target(s) in 0.15s
       Cargo finished cargo build --package=leptos_start --lib --target-dir=target/front --target=wasm32-unknown-unknown --no-default-features --features=hydrate --release
      Notify watching folders .\src, style
2023-01-08T23:22:33.066Z INFO  [leptos_start] serving at http://127.0.0.1:3000
2023-01-08T23:22:33.067Z INFO  [actix_server::builder] Starting 16 workers
2023-01-08T23:22:33.067Z INFO  [actix_server::server] Actix runtime found; starting in Actix runtime
      Leptos ctrl-c received
PS [project_dir]>

file list from a cargo build on linux:

leptos_start
libleptos_start.rlib
libleptos_start.so

file list from a cargo build on windows:

leptos_start.exe
leptos_start.pdb
leptos_start.dll
libleptos_start.rlib

rust-lang/cargo#8519

so the pdb is the debug info for the .exe
and for the .dll
so yeah, confirmed cargo bug
not sure why the linux version outputs lib prefixed files
but the windows one doesn't

Running `cargo leptos build` on a new project fails

I'm having the following issue when running cargo leptos build:

 Compiling leptos_router v0.0.6 (https://github.com/gbj/leptos#0b448daf)
error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/lib.rs:141:38
    |
141 | #![cfg_attr(not(feature = "stable"), feature(auto_traits))]
    |                                      ^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/lib.rs:142:38
    |
142 | #![cfg_attr(not(feature = "stable"), feature(negative_impls))]
    |                                      ^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/lib.rs:143:38
    |
143 | #![cfg_attr(not(feature = "stable"), feature(type_name_of_val))]
    |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/lib.rs:143:46
    |
143 | #![cfg_attr(not(feature = "stable"), feature(type_name_of_val))]
    |                                              ^^^^^^^^^^^^^^^^

error[E0277]: expected a `FnMut<()>` closure, found `leptos::Memo<std::option::Option<leptos::Child>>`
  --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/components/routes.rs:31:49
   |
31 | pub fn Routes(cx: Scope, props: RoutesProps) -> impl IntoChild {
   |                                                 ^^^^^^^^^^^^^^ expected an `FnMut<()>` closure, found `leptos::Memo<std::option::Option<leptos::Child>>`
   |
   = help: the trait `FnMut<()>` is not implemented for `leptos::Memo<std::option::Option<leptos::Child>>`
   = note: wrap the `leptos::Memo<std::option::Option<leptos::Child>>` in a closure with no arguments: `|| { /* code */ }`
   = help: the trait `leptos::IntoChild` is implemented for `leptos::Memo<Vec<web_sys::Element>>`
   = note: required for `leptos::Memo<std::option::Option<leptos::Child>>` to implement `leptos::IntoChild`

error[E0599]: the method `into_attribute` exists for struct `leptos::Memo<std::option::Option<std::string::String>>`, but its trait bounds were not satisfied
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/components/form.rs:146:21
    |
146 |                     action=action
    |                     ^^^^^^ method cannot be called on `leptos::Memo<std::option::Option<std::string::String>>` due to unsatisfied trait bounds
    |
   ::: /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/leptos_reactive/src/memo.rs:118:1
    |
118 | pub struct Memo<T>(pub(crate) ReadSignal<Option<T>>)
    | ------------------
    | |
    | doesn't satisfy `<_ as FnOnce<()>>::Output = _`
    | doesn't satisfy `_: leptos::IntoAttribute`
    | doesn't satisfy `_: std::ops::Fn<()>`
    |
    = note: the following trait bounds were not satisfied:
            `<leptos::Memo<std::option::Option<std::string::String>> as FnOnce<()>>::Output = _`
            which is required by `leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
            `leptos::Memo<std::option::Option<std::string::String>>: std::ops::Fn<()>`
            which is required by `leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
            `<&leptos::Memo<std::option::Option<std::string::String>> as FnOnce<()>>::Output = _`
            which is required by `&leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
            `&leptos::Memo<std::option::Option<std::string::String>>: std::ops::Fn<()>`
            which is required by `&leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
            `<&mut leptos::Memo<std::option::Option<std::string::String>> as FnOnce<()>>::Output = _`
            which is required by `&mut leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`
            `&mut leptos::Memo<std::option::Option<std::string::String>>: std::ops::Fn<()>`
            which is required by `&mut leptos::Memo<std::option::Option<std::string::String>>: leptos::IntoAttribute`

error[E0631]: type mismatch in closure arguments
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/components/form.rs:148:31
    |
68  |     let on_submit = move |ev: web_sys::SubmitEvent| {
    |                     ------------------------------- found signature defined here
...
148 |                     on:submit=on_submit
    |                     --        ^^^^^^^^^ expected due to this
    |                     |
    |                     required by a bound introduced by this call
    |
    = note: expected closure signature `fn(Event) -> _`
               found closure signature `fn(SubmitEvent) -> _`
note: required by a bound in `add_event_listener`
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/leptos_dom/src/operations.rs:290:22
    |
290 |             cb: impl FnMut(web_sys::Event) + 'static,
    |                      ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `add_event_listener`

error[E0631]: type mismatch in closure arguments
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/router/src/components/form.rs:318:23
    |
288 |     let on_submit = move |ev: web_sys::SubmitEvent| {
    |                     ------------------------------- found signature defined here
...
318 |             on:submit=on_submit
    |             --        ^^^^^^^^^ expected due to this
    |             |
    |             required by a bound introduced by this call
    |
    = note: expected closure signature `fn(Event) -> _`
               found closure signature `fn(SubmitEvent) -> _`
note: required by a bound in `add_event_listener`
   --> /home/joseda/.cargo/git/checkouts/leptos-852582868f14a87e/0b448da/leptos_dom/src/operations.rs:290:22
    |
290 |             cb: impl FnMut(web_sys::Event) + 'static,
    |                      ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `add_event_listener`

Some errors have detailed explanations: E0277, E0554, E0599, E0631.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `leptos_router` due to 8 previous errors
       Cargo build failed
Error: at `/home/joseda/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.0.8/src/main.rs@147:33`

Caused by:
    0: at `/home/joseda/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.0.8/src/main.rs@163:36`
    1: at `/home/joseda/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.0.8/src/run/wasm.rs@20:34`
    2: cargo build --no-default-features --features=hydrate --lib --target=wasm32-unknown-unknown at `/home/joseda/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.0.8/src/run/cargo.rs@21:10`
    3: Process exited with code exit status: 101
    ```

I'm new to Rust and I know leptos is in it's early stages, but maybe somebody could tell me what I'm doing wrong. I can share whatever code or configuration you'll need, but my Cargo.toml is exactly the same than the example project.

Issue installing `cargo-generate` on arm64 macos

When I tried to run cargo leptos new --name example for the first time it gave me the error

Error: Unable to download cargo-generate for macos x86_64 due to: failed to download from https://github.com/cargo-generate/cargo-generate/releases/download/0.17.3/cargo-generate-0.17.3-x86_64-apple-darwin.tar.gz

I'm on arm64 macos. I was able to install cargo-generate manually using cargo install cargo-generate

Not linking agains lib ssl on MacOS with brew

I've used rustup to install nightly as well as nightly-2022-12-25 and then ran cargo install cargo-leptos which seemed to install correctly.
However, when I try to make a project with cargo leptos new --git https://github.com/leptos-rs/start I get the following error:

dyld[60719]: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: <F3BD0A25-637A-30F9-9119-86A51CAFE7ED> /Users/mclark4386/.cargo/bin/cargo-generate
  Reason: tried: '/Users/me/.rustup/toolchains/nightly-2022-12-25-x86_64-apple-darwin/lib/libssl.1.0.0.dylib' (no such file), '/usr/local/opt/openssl/lib/libssl.1.0.0.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/openssl/lib/libssl.1.0.0.dylib' (no such file), '/usr/local/opt/openssl/lib/libssl.1.0.0.dylib' (no such file), '/usr/local/lib/libssl.1.0.0.dylib' (no such file), '/usr/lib/libssl.1.0.0.dylib' (no such file, not in dyld cache), '/Users/me/.rustup/toolchains/nightly-2022-12-25-x86_64-apple-darwin/lib/libssl.1.0.0.dylib' (no such file), '/usr/local/Cellar/[email protected]/1.1.1s/lib/libssl.1.0.0.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/Cellar/[email protected]/1.1.1s/lib/libssl.1.0.0.dylib' (no such file), '/usr/local/Cellar/[email protected]/1.1.1s/lib/libssl.1.0.0.dylib' (no such file), '/usr/local/lib/libssl.1.0.0.dylib' (no such file), '/usr/lib/libssl.1.0.0.dylib' (no such file, not in dyld cache)

I have both openssl 3.0.7 and 1.1.1 install via homebrew (I tried symlinking both to the above dylib file/location but then it gets a runtime error after putting the project name in... I'm guessing when it tries to pull some files).

cargo-leptos can't find sass binaries

I am using Windows 10 with rust nightly and this problem occurs with a fresh project created using "cargo leptos new --git https://github.com/leptos-rs/start"

error

I think it happens because the extracted content actually has a "dart-sass" folder instead of the sass binaries:
folder
The build process runs just fine if i move the files from the "dart-sass" folder to the sass folder
folder2

The same problem also occurs with "wasm-opt-version_111" when building the project

Windows: error auto-installing `dart-sass`

On windows, when running cargo leptos watch without sass installed:

Leptos rebuild stopped due to error: at `src\main.rs@147:33`

Caused by:
    0: at `src\main.rs@155:30`
    1: compile sass/scss: style/main.scss at `src\run\sass.rs@24:14`
    2: Try manually installing sass: https://sass-lang.com/install at `src\run\sass.rs@45:26`
    3: Unable to download sass for windows x86_64 due to: failed to download from https://github.com/sass/dart-sass/releases/download/1.56.1/dart-sass-1.56.1-windows-x64.zip

The error is thrown by the binary-install crate.

Preliminary investigation shows that the cache dir AppData/Local/.cargo-leptos is created, but nothing is extracted to it.

Any help solving this would be appreciated as I don't have Windows myself.

`cargo leptos watch` crashes on hot module reloading

Tried the cargo-leptos setup today, and really liked it, but the hot-module-reloading crashed the page for me. See the video for what happened.

hmr-crash.mp4

If it helps, here is my environment

System:
    OS: macOS 12.0.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 521.48 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Browsers:
    Firefox: 107.0.1

Replace `binary-install`

Hello Henrik,

when I do cargo leptos build -r I got:

    Finished release [optimized] target(s) in 18.61s
       Cargo finished cargo build --no-default-features --features=hydrate --lib --target=wasm32-unknown-unknown --release
Error: at `src/main.rs@147:33`

Caused by:
    0: at `src/main.rs@163:36`
    1: at `src/run/wasm.rs@20:34`
    2: at `src/run/wasm.rs@52:41`
    3: at `src/run/wasm.rs@77:35`
    4: Unable to download wasm-opt for macos aarch64 due to: failed to extract tarball from https://github.com/WebAssembly/binaryen/releases/download/version_111/binaryen-version_111-arm64-macos.tar.gz

I installed the latest cargo-leptos, and without -r, the build woks.

Impossible to compile on fresh git clone

The compiler leaves me this message:

Compiling cargo-leptos v0.0.8 (C:\Users\Theo\Workspace\cargo-leptos)
error[E0063]: missing fields filter and map in initializer of ExtractOpts
--> src\ext\exe.rs:113:18
|
113 | &decompress::ExtractOpts { strip: 1 },
| ^^^^^^^^^^^^^^^^^^^^^^^ missing filter and map

For more information about this error, try rustc --explain E0063.
error: could not compile cargo-leptos due to previous error
error: failed to compile cargo-leptos v0.0.8 (C:\Users\Theo\Workspace\cargo-leptos), intermediate artifacts can be found at

Cargo version: cargo 1.68.0-nightly (70898e522 2022-12-05)

[feature] add option to build client files first

It seems cargo-leptos (which is amazing btw!) builds the server and client files in parallal. While this is generally desired for speed, I would like in my project to bundle the js, wasm and css files directly into the binary with rust-embed which requires that the files exist when the server binary is compiled.

Would it be possible to add an option to force the client assets to be finished writing before the server is allowed to compile?

Thanks a bunch

Add i18n

Possibly integrating with:

  • Fluent: The core translation syntax.
  • cargo i18n: This crate is a Cargo sub-command cargo i18n which can be used to extract and build, and verify localization resources at compile time for your crate.
  • Rust I18n: Rust I18n is a crate for loading localized text from a set of YAML mapping files. The mappings are converted into data readable by Rust programs at compile time, and then localized text can be loaded by simply calling the provided t! macro.

WIP: This needs further investigation.

External JS modules not being imported properly

Currently external modules with more than one function declared are converted into snippets.

If I were to add the following

#[wasm_bindgen(module = "/truffle-wrapper.js")]
extern "C" {
    #[wasm_bindgen(js_name = "setCallback")]
    pub fn set_callback(c: &Closure<dyn Fn(String)>);
    pub fn minimize();
}

an import statement is generated within wasm_bindgen considering it as an extra module and the following import statement is generated: import * as __wbg_star0 from './snippets/showdown-hunter-37b34b7f5200334f/truffle-wrapper.js';

If the module only lists one function like so

#[wasm_bindgen(module = "/truffle-wrapper.js")]
extern "C" {
    #[wasm_bindgen(js_name = "setCallback")]
    pub fn set_callback(c: &Closure<dyn Fn(String)>);
}

this import statement is not generated.

In both situations, the module information can be found in the local_modules from bindgen as it is retrieved here.

I am not sure but this is possibly an issue on wasm_bindgen's end related to targeting web but I am unsure at this point in time.

Watch fails to reload server

Sometimes cargo leptos watch does not start the server. There are logs that seem to indicate that it was attempted.

From discord thread

Issue tracked down to commit 94ba14b

Trying to summarise:

  • doesn't seem to be a server binary permissions issue.
  • unlikely to be a firewall issue
  • doesn't output println's from the server, indicating that the binary is never run.
  • only happens on Mac
  • possibly an ADDRINUSE issue, see this

nixos build failure

I am trying to build a leptos site to run on Nixos.

The project tries to create a cache folder when compiling the front even with "no_downloads" feature enabled.

I think the solution is to decouple ExeMeta from the cach dir. Where we can access the ExeMeta but not do any cach dir checks.

Thoughts or other paths I can look into, willing to make the changes just want to get your thoughts on fixing it

Separate profiles for front and server

Today the same release, dev and test profiles are used both for the front and server.

cargo-leptos should be able to set the profiles to use for front and server independently for release, dev and test.

This implies more configuration options:

[[workspace.metadata.leptos]]
front-dev-profile = "myprofile"
front-release-profile = "myprofile"
front-test-profile = "myprofile"

server-dev-profile = "myprofile"
server-release-profile = "myprofile"
server-test-profile = "myprofile"

cargo leptos serve failes: Could not create "/pkg/pkg"

  • cargo leptos new -g https://github.com/leptos-rs/start
  • cargo leptos watch
Cargo finished cargo build --package=leptos-start --bin=leptos-start --target-dir=target/server --no-default-features --features=ssr
Error: at `/Users/joep/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.1.0/src/command/serve.rs:8:42`

Caused by:
    0: Could not create "/pkg/pkg" at `/Users/joep/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.1.0/src/ext/fs.rs:58:10`
    1: Read-only file system (os error 30)
  • cargo-leptos 0.1.0
  • rustc 1.67.0-nightly (85f4f41de 2022-11-08)
  • MacOS 13.1, m1 pro

cargo leptos watch stop compiling when there is an error in the compiled rust code

Step to reproduce:

  1. start a new project using cargo leptos --git ...
  2. run the project using cargo leptos watch
  3. once the project is running, cause a compile error in any *.rs files
  4. fix the error (the project does not recompile)

I can reproduce with the --locked version and the bleeding edge.
I am on Windows 11 with the latest version of rust.

The code seems to stop responding at the following line in src/command/watch.rs

int.recv().await.dot()?;

Panic when `CARGO_TARGET_DIR` is not "target"

Panic:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Could not remove base "/tmp/start" from "/tmp/it_doesnt_really_matter"', /home/aru/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-leptos-0.1.7/src/ext/cargo.rs:73:68
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Simple reproduction on linux:

git clone https://github.com/leptos-rs/start /tmp/start
cd !$
CARGO_TARGET_DIR=/tmp/it_doesnt_really_matter cargo leptos build

Compile Error when installing on MacOS Ventura 13.1

I tried installing cargo-leptos on my MacBook Air M2 and got the following error:-

image

I tried updating the compiler and cargo too but no success.

rustc version = rustc 1.69.0-nightly (c8e6a9e8b 2023-01-23)
cargo version = cargo 1.69.0-nightly (985d561f0 2023-01-20)
mac os version = Ventura 13.1
device = Macbook Air M2 (2022)

Doesn't reload on ports other than 3000

Hello!

Thanks for your tool - it's really convenient way to develop Leptos apps and I really like.

Recently I changed server port in Cargo.toml to 8080

site-address = "127.0.0.1:8080"
# The port to use for automatic reload monitoring
reload-port = 3001

and got the following in the console

 Cargo finished cargo build --package=san_analyzer --bin=san_analyzer --target-dir=target/server --no-default-features --features=ssr
 Watch updated Front
Reload timed out waiting for port 127.0.0.1:3000
Reload could not send "reload all" to websocket

It seems like cargo-leptos doesn't respect this change as 3000 seems hardcoded in src/service/reload.rs :

static ref SITE_ADDR: RwLock<SocketAddr> = RwLock::new(SocketAddr::new([127,0,0,1].into(), 3000));

....

async fn send(stream: &mut WebSocket, msg: BrowserMessage) {
    let site_addr = *SITE_ADDR.read().await;
    if !wait_for_socket("Reload", site_addr).await {
        log::warn!(r#"Reload could not send "{msg}" to websocket"#);
    }
 ....

Could you be so kind to add support of other ports than 3000?

Cloudflare Wrangler Integration

Cloudflare workers runtime tool (wrangler) performs build, dev and publish tasks but doesn't produce an executable binary.

The Rust worker-rs bindings also require a lib to run vs a bin.

Folder structure and related Cargo.toml changes could be made to accommodate a different more desirable structure but an example project can be found here:
https://github.com/perry-birch/leptos-cloudflare

Changes by Tailwind not being actioned.

Hi there,

Thank you for creating this cargo plug. I suspect there is an issue with it working with Tailwinds watch mode.

Background

TailwindCSS is a utility-first css framework. It reads the class names referenced in your source files and generates a css file for your site. Essentially its just a css file generator. You can run it in watch mode and each time you save a change to your source it updates your css file to match.

What I'm doing...

I've created a simple starter template for Leptos + Axum + Tailwind that can be found at https://github.com/phillipbaird/leptos-axum-start

  1. Tailwind is started with tailwindcss -w -i ./tailwind.css -o ./css/main.css
  2. cargo-leptos is started with cargo leptos watch
  3. Open a browser to localhost:3000.
  4. Edit file app/src/lib.rs to change a color, e.g. bg-green-300 is changed to bg-blue-300.

What I expected...

  • cargo-leptos observes the change in app/src/lib.rs and rebuilds the front end and server.
  • Tailwind observes the change and adds bg-blue-300 to css/main.css.
  • cargo-leptos observes the change in css/main.css and redeploys the file to target/site/pkg.
  • cargo-leptos notifies the browser of the changes so it can auto reload the changes.

What actually happened...

It appears as though cargo-leptos is observing the changes but is not actioning them. Neither the Rust code was rebuilt nor was the css redeployed.

Using cargo leptos watch -vv produced the following log when the change was saved...

listening on 127.0.0.1:3000
      Reload websocket connected
      Notify not handled NoticeWrite("/home/phillipb/Repositories/leptos-experiments/leptos-axum-start/app/src/lib.rs")
      Notify not handled NoticeWrite("/home/phillipb/Repositories/leptos-experiments/leptos-axum-start/css/main.css")
      Notify handle Some("app/src/lib.rs")
      Notify lib source change write "app/src/lib.rs"
      Notify bin source change write "app/src/lib.rs"
   Interrupt send done
          FS create_dir_all "target/site/pkg"
      Assets finished (no changes)
       Style no build needed ChangeSet([LibSource, BinSource])
      Notify handle Some("css/main.css")
      Notify style change write "css/main.css"
   Interrupt send done
       Cargo process interrupted
       Cargo process interrupted
       Build step done with no changes
   Interrupt source changed cleared
       Watch waiting for changes
       Front no changes to rebuild
      Assets finished (no changes)
       Style no build needed ChangeSet([])
       Build step done with no changes
   Interrupt source changed cleared
       Watch waiting for changes

If instead of running Tailwind in watch mode I run it manually (using tailwindcss -i ./tailwind.css -o ./css/main.css) after saving the edit to the app/src/lib.rs file, everything appears to work correctly. The log produced looks like this...

listening on 127.0.0.1:3000
      Reload websocket connected
      Notify not handled NoticeWrite("/home/phillipb/Repositories/leptos-experiments/leptos-axum-start/app/src/lib.rs")
      Notify handle Some("app/src/lib.rs")
      Notify lib source change write "app/src/lib.rs"
      Notify bin source change write "app/src/lib.rs"
   Interrupt send done
          FS create_dir_all "target/site/pkg"
      Assets finished (no changes)
       Style no build needed ChangeSet([LibSource, BinSource])
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
   Compiling app-package v0.1.0 (/home/phillipb/Repositories/leptos-experiments/leptos-axum-start/app)
   Compiling app-package v0.1.0 (/home/phillipb/Repositories/leptos-experiments/leptos-axum-start/app)
   Compiling front-package v0.1.0 (/home/phillipb/Repositories/leptos-experiments/leptos-axum-start/front)
   Compiling server-package v0.1.0 (/home/phillipb/Repositories/leptos-experiments/leptos-axum-start/server)
    Finished dev [unoptimized + debuginfo] target(s) in 0.85s
       Cargo process finished with success
       Cargo envs: LEPTOS_OUTPUT_NAME=project LEPTOS_SITE_ROOT=target/site LEPTOS_SITE_PKG_DIR=pkg LEPTOS_SITE_ADDR=127.0.0.1:3000 LEPTOS_RELOAD_PORT=3001 LEPTOS_LIB_DIR=front LEPTOS_BIN_DIR=server LEPTOS_WATCH=ON
       Cargo finished cargo build --package=front-package --lib --target-dir=target/front --target=wasm32-unknown-unknown --no-default-features
       Front wrote wasm to "target/site/pkg/project.wasm"
          FS create_dir_all "target/site/pkg"
       Front js changed
       Front wasm changed
    Finished dev [unoptimized + debuginfo] target(s) in 1.60s
       Cargo process finished with success
       Cargo envs: LEPTOS_OUTPUT_NAME=project LEPTOS_SITE_ROOT=target/site LEPTOS_SITE_PKG_DIR=pkg LEPTOS_SITE_ADDR=127.0.0.1:3000 LEPTOS_RELOAD_PORT=3001 LEPTOS_LIB_DIR=front LEPTOS_BIN_DIR=server LEPTOS_WATCH=ON
       Cargo finished cargo build --package=server-package --bin=server-package --target-dir=target/server --no-default-features
        Site update hash for target/server/debug/server-package to 10101298684753574922
       Cargo server bin changed
       Build step done with changes: Server, Front
      Server restart sent
       Watch updated Server, Front. Server restarting
   Interrupt source changed cleared
       Watch waiting for changes
       Serve stopped
       Serve running target/server/debug/server-package
       Serve restarted
listening on 127.0.0.1:3000
      Reload server port 127.0.0.1:3000 open
      Reload sent "reload all" to browser
      Reload websocket closed
      Reload websocket connected
      Notify not handled NoticeWrite("/home/phillipb/Repositories/leptos-experiments/leptos-axum-start/css/main.css")
      Notify handle Some("css/main.css")
      Notify style change write "css/main.css"
   Interrupt send done
       Front no changes to rebuild
      Assets finished (no changes)
          FS create_dir_all "target/site/pkg"
       Style found: css/main.css -> @pkg/project.css
          FS create_dir_all "target/site/pkg"
       Style finished with changes css/main.css -> @pkg/project.css
       Build step done with changes: Style
       Watch updated style
   Interrupt source changed cleared
       Watch waiting for changes
      Reload server port 127.0.0.1:3000 open
      Reload sent "reload pkg/project.css" to browser 

Environment

cargo-leptos: 0.1.4
OS: Linux Arch 6.1.7
rustc: 1.68.0-nightly (52372f9c7 2023-01-21)
Tailwind CSS: 3.2.4 (binary cli from https://github.com/tailwindlabs/tailwindcss/releases)

Is anyone else able to reproduce this?

Testing Note

When testing this do not toggle back and forth between two colors, e.g. bg-blue-300 and bg-green-300. The reason for this is that when Tailwind is running in watch mode, it will only add classes to the generated .css file. If you toggle back and forth between two values the .css file may contain both colors so may not change. Either always use a new color or restart Tailwind and cargo-leptos before doing the test.

cargo leptos watch doesn't restart the server on error

I wonder if this is because im on arch linux but, in a new project, if i run cargo leptos watch everything works correctly when I make a change that doesn't error.

but if i make a change that errors, what leptos watch outputs is
Watch interrupted. Restarting build step.
but it doesn't actually restart.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.