Rust 增量构建在 vscode devcontainer 中不起作用
Rust incremental build not working in vscode devcontainer
简介:
我对 Rust 一无所知,我只是想开始学习它。每次我开始学习新语言时,我都会在 docker 容器中创建隔离环境。 VSCode + devcontainers 确实符合我的需要。
但是我无法让它工作 w/o Rust 语言的问题...
配置:
Docker 文件:
ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT}
devcontainer.json:
{
"name": "Rust",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "buster"
}
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
"settings": {
"lldb.executable": "/usr/bin/lldb",
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy"
},
"extensions": ["vadimcn.vscode-lldb", "mutantdino.resourcemonitor", "rust-lang.rust-analyzer", "tamasfe.even-better-toml", "serayuzgur.crates"],
"remoteUser": "vscode"
}
步骤:
- 项目初始化-
cargo init --lib
;里面 src/lib.rs
:
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
- 构建和运行测试;在终端 -
cargo test
。工作正常
- 修改
src/lib.rs
中的源代码:
let result = 1 + 3;
- 再次尝试构建和测试
vscode ➜ /workspaces/rust (master ✗) $ cargo test
Compiling rust v0.1.0 (/workspaces/rust)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-5d327a17108921ba.13ffvsr0glsfe42f.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-gxppmkfewicn/s-gaal4g2el0-hq3lv3-working/13ffvsr0glsfe42f.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-gxppmkfewicn/s-gaal4g2el0-hq3lv3-working/13ffvsr0glsfe42f.o`: No such file or directory (os error 2)
error: failed to build archive: No such file or directory
warning: `rust` (lib) generated 2 warnings
error: could not compile `rust` due to previous error; 2 warnings emitted
warning: build failed, waiting for other jobs to finish...
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.10m7tz863ds16j5r.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/10m7tz863ds16j5r.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2g1dgkuj4iwo1dpd.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/2g1dgkuj4iwo1dpd.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2mlne7zmh6r0bbaz.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/2mlne7zmh6r0bbaz.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.34ce50mpm70vg2xp.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/34ce50mpm70vg2xp.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3jboau2gf9iotth5.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/3jboau2gf9iotth5.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4kludynsasaig1p8.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4kludynsasaig1p8.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4mgjk9xqfrl59h15.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4mgjk9xqfrl59h15.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4x66u4glhx5zajo6.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4x66u4glhx5zajo6.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.53xipwa889tr5l36.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/53xipwa889tr5l36.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.kijxc3ir8m0c4lu.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/kijxc3ir8m0c4lu.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.uh788nff365zzlt.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/uh788nff365zzlt.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4mgjk9xqfrl59h15.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/53xipwa889tr5l36.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/2mlne7zmh6r0bbaz.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/kijxc3ir8m0c4lu.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/10m7tz863ds16j5r.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/uh788nff365zzlt.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4kludynsasaig1p8.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/3jboau2gf9iotth5.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4x66u4glhx5zajo6.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/34ce50mpm70vg2xp.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/2g1dgkuj4iwo1dpd.o`: No such file or directory (os error 2)
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.10m7tz863ds16j5r.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2g1dgkuj4iwo1dpd.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2mlne7zmh6r0bbaz.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.34ce50mpm70vg2xp.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3jboau2gf9iotth5.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3w9uardnsemqbo8z.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4kludynsasaig1p8.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4mgjk9xqfrl59h15.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4p7ra8ebuf15pp70.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4royndzdbhzs52e2.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4x66u4glhx5zajo6.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.53xipwa889tr5l36.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.kijxc3ir8m0c4lu.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.uh788nff365zzlt.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.19ahr4r5v6berd9h.rcgu.o" "-Wl,--as-needed" "-L" "/workspaces/rust/target/debug/deps" "-L" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-b6a068090bf40c71.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-1c1e08c768cd8903.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-3f4474e7a3a1f53f.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-ec55ab174918e77a.rlib" "-Wl,--start-group" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f2400674c7513725.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-605c3a7d1a5d300d.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-3d4fb4efa907e4e8.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-65207f030ab23308.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-76ca199cb0186109.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-1e3e01ed4f561dc1.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-dd8dddcba7c13fee.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-00b13d31c3420656.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e4c8460b81557bd5.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-600d46e5f0005455.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-e4a08a2585b62d37.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fbc21ec567cb9dc7.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-10b3fa8e49bd978f.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-64625b73694ffce7.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-fb6b78ac543a58ee.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-1d1f2d1bec6f51b8.rlib" "-Wl,--end-group" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-acf5ff6e9595d982.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
= note: /usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.10m7tz863ds16j5r.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2g1dgkuj4iwo1dpd.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2mlne7zmh6r0bbaz.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.34ce50mpm70vg2xp.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3jboau2gf9iotth5.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4kludynsasaig1p8.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4mgjk9xqfrl59h15.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4x66u4glhx5zajo6.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.53xipwa889tr5l36.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.kijxc3ir8m0c4lu.rcgu.o: No such file or directory
collect2: error: ld returned 1 exit status
- 又一次
Compiling rust v0.1.0 (/workspaces/rust)
error: unable to copy /workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4kvted-13shv61-working/3w9uardnsemqbo8z.o to /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3w9uardnsemqbo8z.rcgu.o: No such file or directory (os error 2)
error: could not compile `rust` due to previous error
即在任何次要代码编辑测试后不 compiled/launched
如果我执行 cargo clean && cargo test
- 它确实有效,但我认为一直重建所有内容是无效的。
问题:
有人可以向我解释如何消除这些错误并在我进行每次小改动后使其正常工作 w/o cargo clean
吗?
好的,我找到了一些可行的选项。问题出在目标文件夹周围,所以我只是对其进行了一些操作。
- 在工作区外使用
target
文件夹并 运行 使用 CARGO_TARGET_DIR
环境变量进行测试
sudo mkdir ../target
sudo chown vscode:vscode ../target
CARGO_TARGET_DIR=../target cargo test
- 相同的想法,但
config.toml
。在项目文件夹或根文件夹中添加 .cargo/config.toml
。
[build]
target-dir = "/tmp/target"
- 在此blog post中窥见了解决方案。将目标文件夹挂载为卷。刚刚向
devcontainer.json
添加了一些配置
"workspaceFolder": "/workspace",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated",
"mounts": ["source=rust-target-volume,target=/workspace/target,type=volume"],
"postCreateCommand": "sudo chown vscode:vscode /workspace/target",
但是cargo clean
会产生错误输出(不是什么大问题,就是烦人)
error: could not remove build directory
Caused by:
failed to remove directory `/workspace/target`
Caused by:
Device or resource busy (os error 16)
所以我完成了 post-create.sh
脚本
#! /bin/bash/
# grant permissions to mounted rust volume
chown vscode:vscode /rust-volume
# create /.cargo/config.toml in root folder
mkdir /.cargo/
touch /.cargo/config.toml
cat << EOF > /.cargo/config.toml
[build]
target-dir = "/rust-volume/target"
EOF
并更新了 devcontainer.json
"mounts": ["source=rust-volume,target=/rust-volume,type=volume"],
"postCreateCommand": "sudo sh ./.devcontainer/post-create.sh",
但是,我只找到了一个可行的选项,但我不明白为什么不进行一些额外的调整它就不起作用。如果有人可以用技术语言解释这一点,欢迎您。以防万一 - 我使用 macOS 作为主机。
得到正确答案on Github Issues
问题是因为在 macOS 12.2
上启用了 VirtioFS
如果 VirtioFS 在 macOS 12.2 上的 docker 设置中禁用,- 工作 w/o 额外配置(但非常慢)
- 也适用于在 macOS 12.4
上启用的 VirtioFS
简介:
我对 Rust 一无所知,我只是想开始学习它。每次我开始学习新语言时,我都会在 docker 容器中创建隔离环境。 VSCode + devcontainers 确实符合我的需要。
但是我无法让它工作 w/o Rust 语言的问题...
配置:
Docker 文件:
ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT}
devcontainer.json:
{
"name": "Rust",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "buster"
}
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
"settings": {
"lldb.executable": "/usr/bin/lldb",
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy"
},
"extensions": ["vadimcn.vscode-lldb", "mutantdino.resourcemonitor", "rust-lang.rust-analyzer", "tamasfe.even-better-toml", "serayuzgur.crates"],
"remoteUser": "vscode"
}
步骤:
- 项目初始化-
cargo init --lib
;里面src/lib.rs
:
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
- 构建和运行测试;在终端 -
cargo test
。工作正常 - 修改
src/lib.rs
中的源代码:
let result = 1 + 3;
- 再次尝试构建和测试
vscode ➜ /workspaces/rust (master ✗) $ cargo test
Compiling rust v0.1.0 (/workspaces/rust)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-5d327a17108921ba.13ffvsr0glsfe42f.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-gxppmkfewicn/s-gaal4g2el0-hq3lv3-working/13ffvsr0glsfe42f.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-gxppmkfewicn/s-gaal4g2el0-hq3lv3-working/13ffvsr0glsfe42f.o`: No such file or directory (os error 2)
error: failed to build archive: No such file or directory
warning: `rust` (lib) generated 2 warnings
error: could not compile `rust` due to previous error; 2 warnings emitted
warning: build failed, waiting for other jobs to finish...
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.10m7tz863ds16j5r.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/10m7tz863ds16j5r.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2g1dgkuj4iwo1dpd.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/2g1dgkuj4iwo1dpd.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2mlne7zmh6r0bbaz.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/2mlne7zmh6r0bbaz.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.34ce50mpm70vg2xp.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/34ce50mpm70vg2xp.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3jboau2gf9iotth5.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/3jboau2gf9iotth5.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4kludynsasaig1p8.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4kludynsasaig1p8.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4mgjk9xqfrl59h15.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4mgjk9xqfrl59h15.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4x66u4glhx5zajo6.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4x66u4glhx5zajo6.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.53xipwa889tr5l36.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/53xipwa889tr5l36.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.kijxc3ir8m0c4lu.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/kijxc3ir8m0c4lu.o`: No such file or directory (os error 2)
warning: error copying object file `/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.uh788nff365zzlt.rcgu.o` to incremental directory as `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/uh788nff365zzlt.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4mgjk9xqfrl59h15.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/53xipwa889tr5l36.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/2mlne7zmh6r0bbaz.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/kijxc3ir8m0c4lu.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/10m7tz863ds16j5r.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/uh788nff365zzlt.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4kludynsasaig1p8.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/3jboau2gf9iotth5.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/4x66u4glhx5zajo6.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/34ce50mpm70vg2xp.o`: No such file or directory (os error 2)
warning: file-system error deleting outdated file `/workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4g2efw-12rgpao-working/2g1dgkuj4iwo1dpd.o`: No such file or directory (os error 2)
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.10m7tz863ds16j5r.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2g1dgkuj4iwo1dpd.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2mlne7zmh6r0bbaz.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.34ce50mpm70vg2xp.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3jboau2gf9iotth5.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3w9uardnsemqbo8z.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4kludynsasaig1p8.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4mgjk9xqfrl59h15.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4p7ra8ebuf15pp70.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4royndzdbhzs52e2.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4x66u4glhx5zajo6.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.53xipwa889tr5l36.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.kijxc3ir8m0c4lu.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.uh788nff365zzlt.rcgu.o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432.19ahr4r5v6berd9h.rcgu.o" "-Wl,--as-needed" "-L" "/workspaces/rust/target/debug/deps" "-L" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-b6a068090bf40c71.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-1c1e08c768cd8903.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-3f4474e7a3a1f53f.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-ec55ab174918e77a.rlib" "-Wl,--start-group" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f2400674c7513725.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-605c3a7d1a5d300d.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-3d4fb4efa907e4e8.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-65207f030ab23308.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-76ca199cb0186109.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-1e3e01ed4f561dc1.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-dd8dddcba7c13fee.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-00b13d31c3420656.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e4c8460b81557bd5.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-600d46e5f0005455.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-e4a08a2585b62d37.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fbc21ec567cb9dc7.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-10b3fa8e49bd978f.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-64625b73694ffce7.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-fb6b78ac543a58ee.rlib" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-1d1f2d1bec6f51b8.rlib" "-Wl,--end-group" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-acf5ff6e9595d982.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/local/rustup/toolchains/1.60.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/workspaces/rust/target/debug/deps/rust-edc6e6500c367432" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
= note: /usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.10m7tz863ds16j5r.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2g1dgkuj4iwo1dpd.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.2mlne7zmh6r0bbaz.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.34ce50mpm70vg2xp.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3jboau2gf9iotth5.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4kludynsasaig1p8.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4mgjk9xqfrl59h15.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.4x66u4glhx5zajo6.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.53xipwa889tr5l36.rcgu.o: No such file or directory
/usr/bin/ld: cannot find /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.kijxc3ir8m0c4lu.rcgu.o: No such file or directory
collect2: error: ld returned 1 exit status
- 又一次
Compiling rust v0.1.0 (/workspaces/rust)
error: unable to copy /workspaces/rust/target/debug/incremental/rust-u7gm7mcexrpp/s-gaal4kvted-13shv61-working/3w9uardnsemqbo8z.o to /workspaces/rust/target/debug/deps/rust-edc6e6500c367432.3w9uardnsemqbo8z.rcgu.o: No such file or directory (os error 2)
error: could not compile `rust` due to previous error
即在任何次要代码编辑测试后不 compiled/launched
如果我执行 cargo clean && cargo test
- 它确实有效,但我认为一直重建所有内容是无效的。
问题:
有人可以向我解释如何消除这些错误并在我进行每次小改动后使其正常工作 w/o cargo clean
吗?
好的,我找到了一些可行的选项。问题出在目标文件夹周围,所以我只是对其进行了一些操作。
- 在工作区外使用
target
文件夹并 运行 使用CARGO_TARGET_DIR
环境变量进行测试
sudo mkdir ../target
sudo chown vscode:vscode ../target
CARGO_TARGET_DIR=../target cargo test
- 相同的想法,但
config.toml
。在项目文件夹或根文件夹中添加.cargo/config.toml
。
[build]
target-dir = "/tmp/target"
- 在此blog post中窥见了解决方案。将目标文件夹挂载为卷。刚刚向
devcontainer.json
添加了一些配置
"workspaceFolder": "/workspace",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated",
"mounts": ["source=rust-target-volume,target=/workspace/target,type=volume"],
"postCreateCommand": "sudo chown vscode:vscode /workspace/target",
但是cargo clean
会产生错误输出(不是什么大问题,就是烦人)
error: could not remove build directory
Caused by:
failed to remove directory `/workspace/target`
Caused by:
Device or resource busy (os error 16)
所以我完成了 post-create.sh
脚本
#! /bin/bash/
# grant permissions to mounted rust volume
chown vscode:vscode /rust-volume
# create /.cargo/config.toml in root folder
mkdir /.cargo/
touch /.cargo/config.toml
cat << EOF > /.cargo/config.toml
[build]
target-dir = "/rust-volume/target"
EOF
并更新了 devcontainer.json
"mounts": ["source=rust-volume,target=/rust-volume,type=volume"],
"postCreateCommand": "sudo sh ./.devcontainer/post-create.sh",
但是,我只找到了一个可行的选项,但我不明白为什么不进行一些额外的调整它就不起作用。如果有人可以用技术语言解释这一点,欢迎您。以防万一 - 我使用 macOS 作为主机。
得到正确答案on Github Issues
问题是因为在 macOS 12.2
上启用了 VirtioFS-
如果 VirtioFS 在 macOS 12.2 上的 docker 设置中禁用,
- 工作 w/o 额外配置(但非常慢)
- 也适用于在 macOS 12.4 上启用的 VirtioFS