Comments (5)
@weihanglo That works, but actually does not solve my issue specifically - but I think it's because the runner script is not what was causing my issue in the first place. I effectively have the following setup:
.
└── workspace_root/
├── .cargo/
│ └── config.toml
├── bin_crate/
│ ├── .cargo/
│ │ └── config.toml
│ ├── src/
│ │ └── main.rs
│ └── Cargo.toml
├── lib_crate/
│ ├── src/
│ │ └── lib.rs
│ └── Cargo.toml
├── scripts/
│ └── run.sh
└── Cargo.toml
In my above structure, the bin crate is a #![no_std]
crate with the following in the .cargo/config.toml:
[build]
target = "x86_64-unknown-uefi"
[unstable]
build-std = ["core", "compiler_builtins"]
build-std-features = ["compiler-builtins-mem"]
[target.x86_64-unknown-uefi]
runner = "../scripts/run.sh"
The lib crate is just a regular crate, no special config except for a #![cfg_attr(not(test), no_std)]
annotation in the lib.rs.
I'm finding that no matter what kind of config I use in the workspace root, I cannot get it to build the project from there. I'm getting errors from other external crates failing to compile, unless the workspace config exactly matches the bin config - but then my issue with the lib crate not being no_std pops up again.
Ideally, what I want is for cargo run
in the workspace root to be identical to cd bin_crate && cargo run
, where bin_crate is either the only bin crate, or one specified as the default in the workspace. That is how I am currently running it and it works for now.
I guess maybe a default runner is not the goal then - as it would seem runners first build the crate, and then pass the crate path as an arg to the runner. If I could specify a custom build command as well, that would be ideal. Then I could wire something up that fits my use case.
Something like this maybe:
[build]
build_command = "cd bin_crate && cargo build && cd .."
Or provide some other kind of configuration option, specifically for workspaces even, that enables building and running from the default crate, honoring its configuration.
from cargo.
Does cargo run --config "target.'cfg(all())'.runner=['echo']"
work for you?
Or within .cargo/config.toml
:
[target.'cfg(all())']
runner = ['echo']
You could also use --config <path-to-a-config-toml-file>
flag to do a one-off config loading.
from cargo.
Thanks for sharing! I can see where you're from. Cargo's configuration discovery always starts from the current working directory, regardless what you're building. This umm… feature, is not going to change anytime soon. However, we have some alternative for this.
- Command-line overrides. Let's say you have a
.cargo/no-std.config.toml
at workspace root. You can read it via--config <path>
. Since it's not named.cargo/config.toml
, it'll never be picked up by Cargo automatically. - You can combine
--config
with user-defined[alias]
, such asSo that can save some keystrokes for you.[alias] build-bin = "build -p bin_crate --config .cargo/bin-crate.config.toml"
- There is an unstable
-C <dir>
flag to switch to a directory. Cargo will start the config discovery from the given<dir>
. - Your proposed solution looks pretty much like #6575, which proposes to extend
alias
to allow arbitrary commands. - There is a plan of moving some project-specific config to manifest (Cargo.toml). This is pretty relevant to this issue.
Granted, things above are not all “alternatives”. Some of them are still in design stages. Yet I think we can instead track those issues and close this one. Do you have any specific request that is not covered by aforementioned issues?
from cargo.
@weihanglo Fair enough! Thanks for your help, and that alias solution and proposal sounds great, it aligns pretty much with what I'm doing anyway which is running a custom script instead of cargo run. The alias solution is cleaner, not sure how I missed that in my research.
from cargo.
Thanks! Closing in favor of #6575. Feel free to comment there or elsewhere :)
from cargo.
Related Issues (20)
- Cargo cannot parse azure devops ssh git urls HOT 3
- `cargo login` encourages disclosure of secret token HOT 10
- Cargo downloads git dependencies very slowly HOT 1
- [Feature Request] Overwrite The Version of a Dependency's Dependency HOT 5
- `cargo doc` fails for bin+lib projects with `-` in the name HOT 1
- Next step for deprecations in Cargo
- Error because I wrote "feature" instead of "features" HOT 2
- having a space in the build path somewhere causes it to error and not run HOT 2
- Add env vars specifying the path for the dependent crate when compiling a dependency HOT 2
- cargo fails to download git package HOT 1
- cargo publish says that the tarball can not be verified after having compiled successfully the crate HOT 2
- Undocumented, inconsisten inheritance of `[badges]`
- `cargo add` deletes comments in TOML unexpectedly under certain conditions HOT 2
- Panic with "already borrowed: BorrowMutError" since nightly-2024-03-26 HOT 5
- cargo add --no-default-features displaying wrong feature selection HOT 3
- `cargo generate-lockfile` panicked when `--offline`
- Already borrowed panic (`BorrowMutErr`) during `cargo update` HOT 5
- cargo clippy error when using compile option --emit=obj, and crate-type = ["staticlib"] HOT 1
- Cargo `vendor` doesn't include dependency's hidden files HOT 3
- better support for generation and installation of associated files HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cargo.