首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >锈蚀增量构建不工作在vscode开发容器中。

锈蚀增量构建不工作在vscode开发容器中。
EN

Stack Overflow用户
提问于 2022-05-31 12:45:17
回答 2查看 312关注 0票数 0

简介:

我对生锈一无所知,我只是试着开始学习。每次我开始学习新语言时,我都会在docker容器中创建一个孤立的环境。VSCode + devcontainers确实符合我的需要。

但是我不能让它为生锈的语言工作.

Configuration:

Dockerfile:

代码语言:javascript
运行
复制
ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT}

devcontainer.json:

代码语言:javascript
运行
复制
{
    "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"
}

步骤:

  1. project cargo init --lib;inside src/lib.rs
代码语言:javascript
运行
复制
#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        let result = 2 + 2;
        assert_eq!(result, 4);
    }
}
  1. 构建并运行测试;在终端- cargo test中。工作正常
  2. 修改src/lib.rs中的源代码
代码语言:javascript
运行
复制
let result = 1 + 3;
  1. 试着重新构建和测试
代码语言:javascript
运行
复制
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
  1. 再一次
代码语言:javascript
运行
复制
   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

即,在未编译/启动的任何次要代码编辑测试之后

如果我执行cargo clean && cargo test -它确实工作,但我认为这是无效的重建所有的一切。

问题:,有人能解释我如何摆脱这些错误,并在我所做的每一个微小的改变之后使它工作吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-06-02 11:20:09

得到正确答案关于Github问题

问题在于启用了VirtioFS on macOS 12.2

  • 如果VirtioFSmacOS 12.2上的停靠设置中禁用,则可以进行w/o额外配置(但速度非常慢)
  • 还可以使用VirtioFSmacOS 12.4上启用
票数 1
EN

Stack Overflow用户

发布于 2022-06-01 13:38:03

好吧,我找到了一些工作选择。问题是围绕目标文件夹,所以我只是做了一些操作围绕它。

  1. 使用工作区外的target文件夹并使用CARGO_TARGET_DIR env变量运行测试
代码语言:javascript
运行
复制
sudo mkdir ../target
sudo chown vscode:vscode ../target
CARGO_TARGET_DIR=../target cargo test
  1. 同样的想法,但对config.toml。在项目文件夹或根文件夹中添加.cargo/config.toml
代码语言:javascript
运行
复制
[build]
target-dir = "/tmp/target"
  1. 在这个博客帖子中窥见了解决方案。将目标文件夹挂载为卷。刚给devcontainer.json添加了一些配置
代码语言:javascript
运行
复制
    "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会产生错误输出(不是什么大问题,只是很烦人)

代码语言:javascript
运行
复制
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脚本

代码语言:javascript
运行
复制
#! /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

代码语言:javascript
运行
复制
    "mounts": ["source=rust-volume,target=/rust-volume,type=volume"],
    "postCreateCommand": "sudo sh ./.devcontainer/post-create.sh",

然而,我只找到了一个可行的选择,但我不明白为什么如果不做一些额外的调整,它就不能工作。如果有人能用技术语言解释这一点,我们欢迎你。以防万一-我用macOS作为主机。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72448053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档