2016-01-31 13 views
5

Jestem nowy w Rust i chcę zbudować i uruchomić mój projekt. Używam coś jak:Jak określić ścieżkę do Cargo.toml

cd %project_path% 
cargo run 

Chcę móc napisać cargo run -path %project_path% w jednej linii, ponieważ chcę, aby utworzyć skrypt kompilacji, który nie pozwala zmienić katalog roboczy. Wydaje się, że ładunek nie ma żadnych -path lub -target klucze, które definiują katalog docelowy, a ja zawsze dostaję komunikat

Nie znaleziono Cargo.toml w C:\WINDOWS\system32 ani żadnego nadrzędnego katalogu

+0

Może chcesz opcję '--manifest-path'? (Argument "--help" będzie wyświetlał ich argumenty i opisy.) – huon

+0

Chcę móc skompilować i uruchomić projekt umieszczony nie w bieżącym katalogu roboczym, ale w ścieżce, którą określam jako –

+0

In * nix terminologia powłoki, możesz użyć '(cd $ project_path; cargo run)': uruchom nową podpowłokę, w której zmienisz katalog, a następnie wykonasz żądane zadanie. W systemie Windows wydaje mi się, że byłoby to trochę niejasno podobne do 'cmd -c" cd% project_path%, cargo run "'. –

Odpowiedz

9

The --manifest-path path/to/Cargo.toml Opcja do prawie wszystkich podkomend cargo pozwala wskazać konkretny plik Cargo.toml, zastępując domyślne wyszukiwanie bieżącego katalogu i jego rodziców dla pliku o nazwie Cargo.toml (ten plik jest "manifestem").

Nawiasem mówiąc, UNIX-y polecenia zwykle do -h lub --help argumentu drukuje informację o ich parametry wywołania cargo i rustc nie stanowią wyjątku. Na przykład.

$ cargo run --help 
Run the main binary of the local package (src/main.rs) 

Usage: 
    cargo run [options] [--] [<args>...] 

Options: 
    -h, --help    Print this message 
    --bin NAME    Name of the bin target to run 
    --example NAME   Name of the example target to run 
    -j N, --jobs N   The number of jobs to run in parallel 
    --release    Build artifacts in release mode, with optimizations 
    --features FEATURES  Space-separated list of features to also build 
    --no-default-features Do not build the `default` feature 
    --target TRIPLE   Build for the target triple 
    --manifest-path PATH Path to the manifest to execute 
    -v, --verbose   Use verbose output 
    -q, --quiet    No output printed to stdout 
    --color WHEN   Coloring: auto, always, never 

If neither `--bin` nor `--example` are given, then if the project only has one 
bin target it will be run. Otherwise `--bin` specifies the bin target to run, 
and `--example` specifies the example target to run. At most one of `--bin` or 
`--example` can be provided. 

All of the trailing arguments are passed to the binary to run. If you're passing 
arguments to both Cargo and the binary, the ones after `--` go to the binary, 
+0

Wiem, co robi komenda '-h', ale nie oczekiwałem, że' manifest to execute' to 'cargo.toml'. Tylko nieporozumienie. Myślałem, że to dodatkowy plik metadanych (jak manifest aplikacji w '.Net'), dlatego nie użyłem tego klucza. Dzięki za odpowiedź. –

Powiązane problemy