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

cli.rs misidentifies target out directory for Cargo workspaces #2614

Closed
kofigumbs opened this issue Sep 20, 2021 · 0 comments
Closed

cli.rs misidentifies target out directory for Cargo workspaces #2614

kofigumbs opened this issue Sep 20, 2021 · 0 comments

Comments

@kofigumbs
Copy link

Describe the bug

tauri build fails to detect that my src-tauri directory was part of a Cargo workspace. I realized the reason that function didn't work for me is because I use a glob to identify my workspace members, and Tauri CLI checks for exact matches. Directory structure that reproduces issue:

~/Documents/src-tauri-workspace/a-workspace (master)
$ tree -L 2
.
├── Cargo.lock
├── Cargo.toml
├── src
│   └── main.rs
├── src-tauri
│   ├── Cargo.toml
│   ├── icons
│   ├── rustfmt.toml
│   ├── src
│   └── tauri.conf.json
└── target
    ├── CACHEDIR.TAG
    ├── debug
    └── release

~/Documents/src-tauri-workspace/a-workspace (master)
$ cat Cargo.toml
[package]
name = "a-workspace"
version = "0.1.0"
edition = "2018"

[workspace]
members = ["src-tauri"]

[dependencies]

To Reproduce

  1. Clone https://github.com/kofigumbs/src-tauri-workspace
  2. cd a-workspace
  3. cargo tauri build
~/Documents/src-tauri-workspace/a-workspace (master)
$ cargo tauri build
   Compiling app v0.1.0 (/Users/kofi/Documents/src-tauri-workspace/a-workspace/src-tauri)
    Finished release [optimized] target(s) in 1m 20s
Error: failed to rename `/Users/kofi/Documents/src-tauri-workspace/a-workspace/src-tauri/target/release/a
pp` to `/Users/kofi/Documents/src-tauri-workspace/a-workspace/src-tauri/target/release/a-workspace`

Caused by:
    No such file or directory (os error 2)

Expected behavior

Tauri's target directory detection should always match that of cargo metadata:

~/Documents/src-tauri-workspace (master)
$ bash -c 'cd a-workspace && cargo metadata --format-version=1 | jq .target_directory'
"/Users/kofi/Documents/src-tauri-workspace/a-workspace/target"

~/Documents/src-tauri-workspace (master)
$ bash -c 'cd a-workspace/src-tauri && cargo metadata --format-version=1 | jq .target_directory'
"/Users/kofi/Documents/src-tauri-workspace/a-workspace/target"

Screenshots

N/A

Platform and Versions (required):

$ cargo tauri info

Operating System - Mac OS, version 11.5.2 X64

Node.js environment
  Node.js - 16.9.1
  @tauri-apps/cli - 1.0.0-beta.10

Global packages
  npm - 7.21.1
  yarn - Not installed

Rust environment
  rustc - 1.56.0-nightly
  cargo - 1.55.0-nightly

Additional context

I was pretty curious, since there seems to be workspace-specific code in interface/rust.rs#get_target_dir. I'm able to workaround this issue by explicitly setting CARGO_TARGET_DIR. My 2 cents is that Tauri should call cargo metadata directly, which would ensure that it uses the same resolution mechanism as Cargo itself. I think that approach would also resolve #2515, since you could also use the error message that Cargo uses for the same problem. My reproduction repo has a few more example project layouts and their cargo metadata output: https://github.com/kofigumbs/src-tauri-workspace.

Stack Trace

N/A

kofigumbs added a commit to kofigumbs/typebeat that referenced this issue Sep 23, 2021
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

1 participant