rust-cargo

How to emit LLVM-IR from Cargo

六眼飞鱼酱① 提交于 2019-12-06 19:24:00
问题 How can I get cargo to emit LLVM-IR instead of a binary for my project? I know that you can use the --emit=llvm-ir flag in rustc , but I've read some Github issues that show it's impossible to pass arbitrary compiler flags to cargo. Is there any way I can get cargo to emit LLVM-IR directly? 回答1: There is cargo rustc to pass arbitrary compiler flags through Cargo to rustc . So I think: cargo rustc -- --emit=llvm-ir is what you want! 回答2: EDIT: You should use Jacob's answer instead; a lot

How to execute cargo test using the nightly channel?

旧街凉风 提交于 2019-12-06 19:06:22
问题 I'm trying to run my tests with nightly Rust using Windows Powershell. I run cargo test in the directory, and I get Compiling rustcraft v0.1.0 (file:///C:/Users/Phoenix/Desktop/Rust/rustcraft) error[E0554]: #![feature] may not be used on the stable release channel --> C:\Users\Phoenix\Desktop\Rust\rustcraft\src\main.rs:1:1 | 1 | #![feature(integer_atomics)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0554]: #![feature] may not be used on the stable release channel --> C:\Users\Phoenix\Desktop\Rust

Should end user utilities/applications be registered on crates.io?

血红的双手。 提交于 2019-12-06 03:31:09
问题 Is it acceptable to register generally useful (utilities / applications) on crates.io? The FAQ doesn't address this and from browsing, there are examples of end-user applications (mostly command line tools). Or is crates.io? meant only for libraries? I'm asking this because the documentation hints at library use, semantic versioning for API's etc. but doesn't reference the case for packaging applications explicitly. 回答1: Yes, because you can use cargo install to install and manage those

How can I force `build.rs` to run again without cleaning my whole project?

坚强是说给别人听的谎言 提交于 2019-12-06 02:56:24
问题 How can I force build.rs to run again without cleaning my whole project? I checked cargo build --help but I couldn't find anything related to build.rs . 回答1: If you print "cargo:rerun-if-changed=<FILE>" the build will be triggered every time the file has changed. rerun-if-changed=PATH is a path to a file or directory which indicates that the build script should be re-run if it changes (detected by a more-recent last-modified timestamp on the file). Normally build scripts are re-run if any

Unable to override Rustup toolchain for custom build of iOS Toolchain

五迷三道 提交于 2019-12-05 18:48:33
I am creating my own toolchain with my build of Rust. I need this to cross compile with iOS architectures. When trying to set the default toolchain or override the current directory's toolchain, I'm getting an error regarding the name of my toolchain. These are the steps I took to create this new toolchain: Create Rustup Toolchain rustup toolchain link ios $HOME/rustc-ios Override current directory toolchain rustup override set ios $ rustup show Default host: x86_64-apple-darwin error: toolchain 'ios' does not support components info: caused by: invalid toolchain name: 'ios' I've tried other

How can I locate resources for testing with Cargo?

懵懂的女人 提交于 2019-12-05 16:48:19
问题 I'm on a project interacting with files, and I would like to use text files to test my work. However tests aren't run from the tests/ directory, and thus I cannot reliably find them when running cargo run . Does Cargo handle this by always running test from the root directory (which seems to be the case but I didn't find anything attesting it)? 回答1: The environment variable CARGO_MANIFEST_DIR can give you a stable base point to reference other files. Here, we assume that there's a resources

How to have different dependencies depending on OS family

£可爱£侵袭症+ 提交于 2019-12-05 13:34:56
问题 I'm writing a cross-platform library that has platform specific dependencies, one for unix-like platforms, and one for windows. These crates only compile on specific platforms, wherefore I can't just add them all under dependencies normally. In the actual rust code I use cfg attributes, like #[cfg(unix)] to compile certain code for certain platforms, and I want to do something similar in the Cargo.toml, or in a build script, for the dependencies. Currently, I'm using target triplets like

Is it possible to have Cargo fetch dependencies from a private remote git?

∥☆過路亽.° 提交于 2019-12-05 13:34:50
问题 I have an account on an ssh-friendly lab machine where I store a lot of private projects so I can access them from multiple computers (and it allows me to only use my few private Github repos for things multiple people will work on). It seems like Rust is well-equipped to fetch local and public data by using things like [dependencies.foo] git = "https://github.com/bar/foo" [dependencies.baz] path = "/path/to/baz" But I haven't found a way to get it to work using ssh git (e.g. git = "git

Is it possible to change the log level for an application at compile time?

喜欢而已 提交于 2019-12-05 08:58:41
Rather than rely on environment variables at runtime, I'd like to compile a debug or release version with non-error log messages stripped out completely. Is it possible to change the log level for an application in the Cargo.toml or via cargo / rustc command line arguments? I don't believe that the log crate has exactly the requested functionality built in. There is a way to statically set the logging level . If you compile the log crate with any of these Cargo features, the log level will be capped at that point: release_max_level_off release_max_level_error release_max_level_warn release_max

How to set logging level while running cargo test? [duplicate]

纵饮孤独 提交于 2019-12-05 05:48:51
This question already has answers here : How to initialize the logger for integration tests? (5 answers) Closed 3 years ago . I need to change the logging level while running the unit tests for a library. I am using the cargo test command to run the tests. Is there any way to specify the logging level on the command line? From the documentation of the log crate, it seems like I need to define an environment variable separately. That may not be convenient as I would like to change the logging level to debug only when a test case fails. Manishearth Cargo doesn't support this yet, but you are