如果我.rs在srcCargo包的目录中有多个文件,可见性,导入等规则是什么?
目前,任何额外的(即不是明确标识为Cargo.toml中可执行文件源的文件)都将被忽略.
我需要做些什么来解决这个问题?
我正在编写 rust 宏,但遇到了有关我无法理解的宏的错误。为了更好地理解它,我尝试通过设置-Z macro-backtrace不稳定选项并再次编译来遵循编译器的建议。这是说的建议:
note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
Run Code Online (Sandbox Code Playgroud)
但是这样做:
cargo run -Z macro-backtrace
Run Code Online (Sandbox Code Playgroud)
结果如下:
error: unknown `-Z` flag specified: macro-backtrace
Run Code Online (Sandbox Code Playgroud)
我已经通过rustup override nightly在项目目录中运行并rustup default nightly为将来使用此功能而完全切换到夜间工具链,但错误仍然存在。
在通过网络挖掘时,我找到了一种列出所有-Z选项的方法cargo -Z help:
Available unstable (nightly-only) flags:
-Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
-Z minimal-versions -- Install minimal dependency versions instead of maximum
-Z no-index-update -- Do not update the …Run Code Online (Sandbox Code Playgroud) 我是 solana 和 rust 的新手,最近我从这个仓库安装了 example-helloworld - https://github.com/solana-labs/example-helloworld。每当我尝试使用 npm 脚本构建 rust 程序或转到 rust 程序目录手动运行Cargo build-bpf 时,它都会说 - 没有这样的子命令:+bpf。终端错误图像
我也尝试过命令which Cargo-build-bpf,它没有错误。但是我也尝试使用Cargo build手动构建,它会引发错误。
假设我在 中定义了以下功能Cargo.toml:
[features]
my_feature = []
Run Code Online (Sandbox Code Playgroud)
以下代码位于src/lib.rs:
[features]
my_feature = []
Run Code Online (Sandbox Code Playgroud)
我如何强制功能字符串与显式定义和隐式可用功能的列表相匹配,以便Cargo.toml避免例如拼写错误?
这是我的 Docker 文件:
FROM ubuntu:20.04
RUN apt-get update && apt-get upgrade -y
RUN apt-get install libssl-dev
RUN apt-get install -y -q build-essential curl
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
WORKDIR /command-agent
COPY . /command-agent
RUN cargo build --release
COPY /command-agent/target/release/command-agent /
EXPOSE 8080
ENTRYPOINT command-agent
Run Code Online (Sandbox Code Playgroud)
它成功构建了 docker 映像,但是当我运行该容器时,它给出了错误:
命令代理:/lib/x86_64-linux-gnu/libc.so.6:找不到版本“GLIBC_2.34”(/command-agent/command-agent 需要)
我不明白,我该如何解决这个问题?
我向 Rust 项目添加了依赖项,然后运行了 Cargo Run,这给了我这个错误:
“阻止等待包缓存上的文件锁定”
我尝试了在网上找到的解决方案,即删除 ~/.cargo/.package-cache 文件,但这对我不起作用。当我输入类似“cargo run”和“cargo update”的命令时,我只会收到相同的消息。现在,即使当我转到另一个没有依赖项的 Rust 项目并尝试运行它时,我也会收到相同的“阻止等待包缓存上的文件锁定”消息。我使用的是 M1 MacBook Pro。
当我运行时cargo build,各种库存储在文件夹中/usr/local/lib/rustlib/.
清除这些库的正确方法是什么?我可以rm手动这些文件,但这是正确的做法吗?我注意到这/usr/local/lib/rustlib/manifest是一个包含所有库的填充文件路径列表的文件,因此如果我手动删除这些文件可能会破坏某些内容.
到目前为止,我已经看到三个......
[dependencies]
crate = "1.0.0" # I think this is an exact version match
crate = "^1.0.0" # I think this means "use that latest 1.x.x"
crate = "*" # I think this means "use the latest"
Run Code Online (Sandbox Code Playgroud)
我很想知道如何使用依赖列表.拥有一个记录依赖关系的不同语法的权威来源会很高兴.
我刚刚开始玩Rust,并试图为我编写的代码生成文档.当我发布时cargo doc,我看到了一些有点奇怪的东西.
21:53 $ cargo doc
Compiling regex-syntax v0.2.2
Compiling libc v0.2.2
Compiling memchr v0.1.7
Compiling aho-corasick v0.3.4
Compiling regex v0.1.41
Compiling my_project v0.0.1 (path/to/my_project)
Run Code Online (Sandbox Code Playgroud)
当我打开时my_project/target/doc/my_project/index.html,我注意到所有依赖项都包含在我的文档中:
我希望这些依赖项的文档对用户隐藏,因此我的文档仅显示如何使用我的代码.
我怎样才能做到这一点?
[root]
name = "my_project"
version = "0.0.1"
dependencies = [
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "aho-corasick"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memchr" …Run Code Online (Sandbox Code Playgroud) 将Servo作为二进制文件的一部分嵌入时,我遇到了很长的连续构建时间.例如,使用本教程嵌入Servo,在初始构建完成后,对我的代码的任何修改都需要40s +来重建第4代四核i7上的二进制文件:
以下是Cargo的样本输出:
? cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.1 secs
? touch src/main.rs
? cargo build
Compiling servo-embedding-example v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 57.9 secs
Run Code Online (Sandbox Code Playgroud)
我正在运行一个最近的夜间工具链:
? rustc --version
rustc 1.25.0-nightly (15a1e2844 2018-01-20)
? cargo --version
cargo 0.26.0-nightly (6a8eb71f6 2018-01-13)
Run Code Online (Sandbox Code Playgroud)
增量构建正在进行:
? echo $CARGO_INCREMENTAL
1
Run Code Online (Sandbox Code Playgroud)
我不打算经常更新伺服,但我需要它我的应用程序.有没有办法加快构建时间?
rust ×10
rust-cargo ×10
actix-web ×1
build ×1
compilation ×1
dependencies ×1
linker ×1
linux ×1
macros ×1
parrot-os ×1
rust-crates ×1
rustdoc ×1
rustup ×1
solana ×1
ubuntu ×1