rust-cargo

How to import a crate dependency when the library name is different from the package name?

自闭症网瘾萝莉.ら 提交于 2020-05-13 05:39:06
问题 I have a crate that is imported straight off of GitHub, as per Cargo's documentation: [dependencies] libfoo = { git = "ssh://git@github.com/me/libfoo", branch = "dev" } [lib] path = "src/rust/lib.rs" name = "myprj" crate-type = ["cdylib"] Running cargo build works fine here, Cargo fetches libfoo and builds it in the ~/.cargo directory. When I try to use (import) it in lib.rs : extern crate libfoo; //also tried foo Cargo chokes: error[E0463]: can't find crate for `libfoo` --> src/rust/lib.rs:1

Cargo, workspace and temporary local dependency

人走茶凉 提交于 2020-03-21 19:19:14
问题 I have two projects my_project and my_inner_project in one cargo workspace. They both depend on gfx (and gfx_core and gfx_device_gl). I've found a bug in gfx_device_core, so I've forked it, cloned, patched locally and want to test it before commit. Projects structure: -my_project --my_inner_project ---Cargo.toml --Cargo.toml -gfx --src ---core ----Cargo.toml #package gfx_core ---backend ----gl -----Cargo.toml #package gfx_device_gl ---render ----Cargo.toml #package gfx --Cargo.toml Now I want

Do optional dependencies get enabled by default?

戏子无情 提交于 2020-03-17 03:12:06
问题 If I define a dependency like foo = { version = "1.0.0", optional = true } , will it be available when I do "cargo run"? Can I check if it is enabled in the code? if cfg!(feature = "foo") {} Doesn't seem to be working, like the feature is missing all the time. 回答1: Moving answer to 60258216 here: Optional dependencies do double as features: https://stackoverflow.com/a/39759592/8182118 They will not be enabled by default unless they're listed in the default feature, though you can enable the

Do optional dependencies get enabled by default?

十年热恋 提交于 2020-03-17 03:10:51
问题 If I define a dependency like foo = { version = "1.0.0", optional = true } , will it be available when I do "cargo run"? Can I check if it is enabled in the code? if cfg!(feature = "foo") {} Doesn't seem to be working, like the feature is missing all the time. 回答1: Moving answer to 60258216 here: Optional dependencies do double as features: https://stackoverflow.com/a/39759592/8182118 They will not be enabled by default unless they're listed in the default feature, though you can enable the

Can I force the use of my dependencies' Cargo.lock when resolving package versions?

让人想犯罪 __ 提交于 2020-02-16 00:26:59
问题 The Cargo FAQ states that Cargo.lock is not used for libraries, instead using dependency version ranges found in Cargo.toml , to reduce lib duplication among shared dependencies. However, I think there are instances where using a known successful build of a lib dependency is preferable. Namely, when a dependency no longer builds due to updates of its own dependencies. Is it possible to configure Cargo to favour a library's Cargo.lock , over Cargo.toml , if it's available? Preferably on a by

Can I force the use of my dependencies' Cargo.lock when resolving package versions?

柔情痞子 提交于 2020-02-16 00:26:13
问题 The Cargo FAQ states that Cargo.lock is not used for libraries, instead using dependency version ranges found in Cargo.toml , to reduce lib duplication among shared dependencies. However, I think there are instances where using a known successful build of a lib dependency is preferable. Namely, when a dependency no longer builds due to updates of its own dependencies. Is it possible to configure Cargo to favour a library's Cargo.lock , over Cargo.toml , if it's available? Preferably on a by

How to get executable's full target triple as a compile-time constant without using a build script?

自古美人都是妖i 提交于 2020-02-04 00:56:10
问题 I'm writing a Cargo helper command that needs to know the default target triple used by Rust/Cargo (which I presume is the same as host's target triple). Ideally it should be a compile-time constant. There's ARCH constant, but it's not a full triple. For example, it doesn't distinguish between soft float and hard float ARM ABIs. env!("TARGET") would be ideal, but it's set only for build scripts, and not the lib/bin targets. I could pass it on to the lib with build.rs and dynamic source code

How to import a module from a directory outside of the `src` directory?

一个人想着一个人 提交于 2020-02-03 01:43:26
问题 I'm stuck when learning how to access a module. I'm trying to insert a folder other than src into src . It's not working and it gives me an error. Here this is my project tree. $ Project1 . |-- src | |-- main.rs | |--FolderinSrcFolder | |--folderinsrcmodule.rs | |--anothersrc | |--mod.rs | |-- rootmodule.rs |-- Cargo.toml |-- Cargo.lock How can I access anothersrc/mod.rs src/main.rs ? How can I access rootmodule.rs from src/main.rs ? I already read the Rust documentation. 回答1: Don't . Put all

Why does solicit 0.4.4 attempt to use openssl 0.9.12 even though I have openssl 0.7.14 in my Cargo.toml?

被刻印的时光 ゝ 提交于 2020-01-24 20:48:05
问题 I have a simple project using the Solicit example to make a request with HTTPS. My Cargo.toml has: [package] name = "test" version = "0.1.0" authors = ["einchear"] [dependencies.openssl] version = "0.7.14" features = ["tlsv1_2", "npn"] [dependencies.solicit] version = "0.4.4" features = ["tls"] When I tried to run cargo build , the error is: error: Package `openssl v0.9.12` does not have these features: `npn, tlsv1_2` Why 0.9.12 instead 0.7.14? 回答1: Solicit hasn't released a new version in

How to tell what “features” are available per crate?

空扰寡人 提交于 2020-01-23 13:03:49
问题 Is there a standard way to determine what features are available for a given crate? I'm trying to read Postgres timezones, and this says to use the crate postgres = "0.17.0-alpha.1" crate's with-time or with-chrono features. When I try this in my Cargo.toml: [dependencies] postgres = { version = "0.17.0-alpha.1", features = ["with-time"] } I get this error: error: failed to select a version for `postgres`. ... required by package `mypackage v0.1.0 (/Users/me/repos/mypackage)` versions that