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

add a way to set a default --target #2332

Closed
japaric opened this issue Jan 29, 2016 · 3 comments
Closed

add a way to set a default --target #2332

japaric opened this issue Jan 29, 2016 · 3 comments

Comments

@japaric
Copy link
Member

japaric commented Jan 29, 2016

For example, if for your project you always cross compile using cargo build --target=thumbv6m-none-eabi. This feature would let you add a key value pair to your cargo config file:

# .cargo/config
[target]
default = "thumbv6m-none-eabi"

That will let you simply call cargo build to cross compile your project for thumbv6m-none-eabi. This would also extend to cargo doc.

Originally reported here.

@alexcrichton
Copy link
Member

This seems pretty reasonable to me, although I might go as far as to say that it should be in Cargo.toml as it's likely a per-project thing if it's a thing to start out with.

@japaric
Copy link
Member Author

japaric commented Jan 30, 2016

One downside (?) of making it a project setting is that the setting will always be ignored for dependencies. Example: If my project P depends on crate D and D has set T as its default target, that setting will always be ignored because D will always be compiled for the target I choose for P.

One advantage of using .cargo/config is that if I'm developing several crates locally, then I can have a setup like this:

$ tree .
my-RTOS-project
├── .cargo
│   └── config
├── allocator
│   └── (...)
├── hal
│   └── (...)
├── RusTOS
│   └── (...)
└── scheduler
    └── (...)

And I can jump from one crate directory to another and run cargo test. At some point I can edit a single line in .cargo/config and start testing my crates for a different target.

@alexcrichton
Copy link
Member

Aha yes indeed! That somewhat falls under the purview of #2122 where that shouldn't be a downside, but there's still some design work to do there as well.

bors added a commit that referenced this issue Feb 5, 2016
Fixed #2332.

This PR adds `build.target` to the Cargo config file, which behaves in the same way as passing `--target` to Cargo.  Example `.cargo/config`:

```
[build]
target = "thumbv6m-none-eabi"
```

Similar to how `--jobs` overrides `build.jobs`, `--target` will override `build.target`.

I added documentation to `config.md`, and a test to `test_cargo_cross_compile.rs`.  I couldn't get cross compile working on my machine for `cargo test`.  Hopefully travis passes it.

This is my first PR against Cargo; sorry if I missed any procedures.
@bors bors closed this as completed in #2335 Feb 5, 2016
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