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

Wrong path for distDir in templates #584

Closed
paulmueller opened this issue Jan 22, 2024 · 5 comments
Closed

Wrong path for distDir in templates #584

paulmueller opened this issue Jan 22, 2024 · 5 comments

Comments

@paulmueller
Copy link

Hello, I am new to rust.

I believe there is something wrong with the templating. I could not get my project to build properly, because I ran into this issue: tauri-apps/tauri#3082

After changing the path of distDir from the default ../dist to ../, everything worked. The error message Asset `index.html` not found; fallback to index.html.html kind of hinted towards a path issue.

To reproduce, you can use this shell.nix:

let
  nixpkgs = fetchTarball "https://github.com/nixos/nixpkgs/archive/nixpkgs-unstable.tar.gz";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in

pkgs.mkShell {
  packages = with pkgs; [
    # rust
    cargo
    clippy
    rustc
    rustfmt
    rust-analyzer
    rustup
    # build dependencies
    cargo-tauri
    trunk
    libsoup
    webkitgtk
  ];

  nativeBuildInputs = with pkgs; [
    pkg-config
  ];

  shellHook = ''
    touch dist
    rustup target add wasm32-unknown-unknown
  '';
}

Then, run

nix-shell
cargo install create-tauri-app --locked
cargo create-tauri-app

And select "Rust" language and "Leptos" UI template.

Then, run cargo tauri build -b deb, which will succeed, but installing the .deb and running it will fail:

cargo tauri build -b deb
sudo dpkg -i target/release/bundle/deb/software-name_0.0.0_amd64.deb
software-name

The app then opens, showing only Could not get requested file. and on the terminal prints (amongst other messages): Asset `index.html` not found; fallback to index.html.html

The fix is (as stated above), to set the correct distDir location to where index.html is located.

@amrbashir
Copy link
Member

../dist is the correct value, I am not sure if your nix environment somehow conflicts with it, but the default layout of the project should look like this:

dist/
  |_index.html
  |...
src/
  |_main.rs
  |...
src-tauri/
  |_tauri.conf.json
  |...
Trunk.toml

can you do trunk build in the root of the project and show the layout of your project?

@paulmueller
Copy link
Author

paulmueller commented Jan 23, 2024

OK, I will try to be as thorough as possible. Yes, it could be that nix is interfering with the environment.

nix-shell:~/repos/SoftwareCenter]$ cargo tauri --version
tauri-cli 1.5.9
Setup project

$nix-shell
info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date

[nix-shell:/tmp/rust]$ cargo install create-tauri-app --locked
    Updating crates.io index
     Ignored package `create-tauri-app v3.12.2` is already installed, use --force to override
warning: be sure to add `/home/paul/.cargo/bin` to your PATH to be able to run the installed binaries

[nix-shell:/tmp/rust]$ cargo create-tauri-app
✔ Project name · tauri-app
✔ Choose which language to use for your frontend · Rust - (cargo)
✔ Choose your UI template · Leptos - (https://github.com/leptos-rs/leptos)

Template created!

Your system is missing dependencies (or they do not exist in $PATH):
╭───────┬──────────────────────────────────────────────────────────────────────────────────╮
│ rsvg2 │ Visit https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux │
╰───────┴──────────────────────────────────────────────────────────────────────────────────╯

Make sure you have installed the prerequisites for your OS: https://tauri.app/v1/guides/getting-started/prerequisites, then run:
  cd tauri-app
  cargo tauri dev

[nix-shell:/tmp/rust]$ tree
.
├── shell.nix
└── tauri-app
    ├── Cargo.toml
    ├── index.html
    ├── public
    │   ├── leptos.svg
    │   └── tauri.svg
    ├── README.md
    ├── src
    │   ├── app.rs
    │   └── main.rs
    ├── src-tauri
    │   ├── build.rs
    │   ├── Cargo.toml
    │   ├── icons
    │   │   ├── 128x128@2x.png
    │   │   ├── 128x128.png
    │   │   ├── 32x32.png
    │   │   ├── icon.icns
    │   │   ├── icon.ico
    │   │   ├── icon.png
    │   │   ├── Square107x107Logo.png
    │   │   ├── Square142x142Logo.png
    │   │   ├── Square150x150Logo.png
    │   │   ├── Square284x284Logo.png
    │   │   ├── Square30x30Logo.png
    │   │   ├── Square310x310Logo.png
    │   │   ├── Square44x44Logo.png
    │   │   ├── Square71x71Logo.png
    │   │   ├── Square89x89Logo.png
    │   │   └── StoreLogo.png
    │   ├── src
    │   │   └── main.rs
    │   └── tauri.conf.json
    ├── styles.css
    └── Trunk.toml

6 directories, 30 files

The index.html is at the root of the project.

$ cat Trunk.toml                                                                            
[build]
target = "./index.html"

[watch]
ignore = ["./src-tauri"]

[serve]
address = "127.0.0.1"
port = 1420
open = false

It turns out that I actually cannot do trunk build, because of a Could not find tool: lld error that I have not been able to fully understand yet.

Let me know if there is anything else I can do. I will attempt to build this without nix as well.

@amrbashir
Copy link
Member

So from the layout you provided, it seems like your leptos app has not been built, and that's probably because of trunk build failing, I have never used nix so I can't really help that much but Could not find tool: lld means you're missing a tool to compile Rust to wasm which is lld, this maybe related rust-lang/rust#98340 ?

Anyways, since this is not an issue in the template, I will go ahead and close this for now but feel free to ping me if the issue persists.

@amrbashir amrbashir closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
@paulmueller
Copy link
Author

paulmueller commented Jan 24, 2024

@amrbashir

Meanwhile, I have installed rust via snap/rustup and can compile the project on Ubuntu 22.04.

Details

sudo snap install rustup --classic
rustup default stable
cargo install create-tauri-app
# This creates the template:
cargo create-tauri-app

# These are additional things I found needed to be set up
rustup target add wasm32-unknown-unknown
export PATH=$PATH:$HOME/.cargo/bin
cargo install tauri-cli trunk

# enter the project directory (note that it does not contain `dist` and `index.html` is at the root of the project)
cd tauri-app
rustup target add wasm32-unknown-unknown

# This runs through without errors
trunk build
# This also runs
cargo tauri build -b deb

I noticed that trunk build creates a dist/index.html which is created from index.html (created via create-tauri-app) file in the root of the project. I believe this is where my confusion came from.
Thanks!

@amrbashir
Copy link
Member

Thanks for clarifying the situation ❤️, hope this helps someone in the future.

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

2 participants