fornwall / rust-script

Run Rust files and expressions as scripts without any setup or compilation step.
https://rust-script.org
Apache License 2.0
1.21k stars 41 forks source link

rust-script fails to execute in nix #55

Closed DavidDTA closed 1 year ago

DavidDTA commented 2 years ago

I've installed rust-script via nix like so:

nix-shell -p rust-script

In that shell, I can run the rust-script executable:

[nix-shell:~]$ rust-script --version
rust-script 0.20.0

However, if I attempt to provide a file, I get an error:

[nix-shell:~]$ rust-script ~/myscript
error: No such file or directory (os error 2)

The same problem happens with the --expr option:

[nix-shell:~]$ rust-script --expr "3"
error: No such file or directory (os error 2)

Here is a full trace:

[nix-shell:~]$ RUST_LOG=rust_script=trace rust-script ~/myscript
[2022-05-21T18:42:48Z INFO  rust_script] Arguments: Args { script: Some("/Users/dta/myscript"), script_args: [], features: None, expr: false, loop_: false, count: false, pkg_path: None, gen_pkg_only: false, cargo_output: false, clear_cache: false, debug: false, dep: [], extern_: [], force: false, unstable_features: [], build_kind: Normal, template: None, list_templates: false, toolchain_version: None }
[2022-05-21T18:42:48Z INFO  rust_script] input: File("myscript", "/Users/dta/myscript", "", 1653158268482)
[2022-05-21T18:42:48Z INFO  rust_script] prelude_items: []
[2022-05-21T18:42:48Z INFO  rust_script] id: "65f3c77206ea3caf68f2d30d"
[2022-05-21T18:42:48Z INFO  rust_script] pkg_path: "/Users/dta/Library/Caches/rust-script/projects/65f3c77206ea3caf68f2d30d"
[2022-05-21T18:42:48Z INFO  rust_script] using_cache: true
[2022-05-21T18:42:48Z INFO  rust_script::manifest] part_mani: Toml("")
[2022-05-21T18:42:48Z INFO  rust_script::manifest] source: "fn main() -> Result<(), Box<dyn std::error::Error+Sync+Send>> {\n    {\n        }\n    Ok(())\n}"
[2022-05-21T18:42:48Z INFO  rust_script::manifest] part_mani: {}
[2022-05-21T18:42:48Z INFO  rust_script::manifest] mani: {"bin": Array([Table({"name": String("myscript_65f3c77206ea3caf68f2d30d"), "path": String("myscript.rs")})]), "dependencies": Table({}), "package": Table({"authors": Array([String("Anonymous")]), "edition": String("2018"), "name": String("myscript"), "version": String("0.1.0")})}
[2022-05-21T18:42:48Z INFO  rust_script::manifest] mani_str: [[bin]]
    name = "myscript_65f3c77206ea3caf68f2d30d"
    path = "myscript.rs"

    [dependencies]

    [package]
    authors = ["Anonymous"]
    edition = "2018"
    name = "myscript"
    version = "0.1.0"

[2022-05-21T18:42:48Z INFO  rust_script] input_meta: PackageMetadata { path: Some("/Users/dta/myscript"), modified: Some(1653158268482), template: None, debug: false, deps: [], prelude: [], features: None, manifest_hash: "a8e53ac300f30974d4a72844ff059f9142643863", script_hash: "56ecf0b760b401c9aa37b7ff226399b2b988b458" }
[2022-05-21T18:42:48Z DEBUG rust_script] meta_path: "/Users/dta/Library/Caches/rust-script/projects/65f3c77206ea3caf68f2d30d/metadata.json"
[2022-05-21T18:42:48Z INFO  rust_script] action: InputAction { cargo_output: false, force_compile: false, emit_metadata: true, execute: true, pkg_path: "/Users/dta/Library/Caches/rust-script/projects/65f3c77206ea3caf68f2d30d", using_cache: true, toolchain_version: None, metadata: PackageMetadata { path: Some("/Users/dta/myscript"), modified: Some(1653158268482), template: None, debug: false, deps: [], prelude: [], features: None, manifest_hash: "a8e53ac300f30974d4a72844ff059f9142643863", script_hash: "56ecf0b760b401c9aa37b7ff226399b2b988b458" }, old_metadata: Some(PackageMetadata { path: Some("/Users/dta/myscript"), modified: Some(1653158268482), template: None, debug: false, deps: [], prelude: [], features: None, manifest_hash: "a8e53ac300f30974d4a72844ff059f9142643863", script_hash: "56ecf0b760b401c9aa37b7ff226399b2b988b458" }), manifest: "[[bin]]\nname = \"myscript_65f3c77206ea3caf68f2d30d\"\npath = \"myscript.rs\"\n\n[dependencies]\n\n[package]\nauthors = [\"Anonymous\"]\nedition = \"2018\"\nname = \"myscript\"\nversion = \"0.1.0\"\n", script: "fn main() -> Result<(), Box<dyn std::error::Error+Sync+Send>> {\n    {\n        }\n    Ok(())\n}", build_kind: Normal }
[2022-05-21T18:42:48Z INFO  rust_script] creating pkg dir...
[2022-05-21T18:42:48Z INFO  rust_script] generating Cargo package...
[2022-05-21T18:42:48Z DEBUG rust_script] overwrite_file("/Users/dta/Library/Caches/rust-script/projects/65f3c77206ea3caf68f2d30d/Cargo.toml", _, Some("a8e53ac300f30974d4a72844ff059f9142643863"))
[2022-05-21T18:42:48Z DEBUG rust_script] .. hashes match
[2022-05-21T18:42:48Z DEBUG rust_script] overwrite_file("/Users/dta/Library/Caches/rust-script/projects/65f3c77206ea3caf68f2d30d/myscript.rs", _, Some("56ecf0b760b401c9aa37b7ff226399b2b988b458"))
[2022-05-21T18:42:48Z DEBUG rust_script] .. hashes match
[2022-05-21T18:42:48Z INFO  rust_script] emitting metadata...
[2022-05-21T18:42:48Z DEBUG rust_script] meta_path: "/Users/dta/Library/Caches/rust-script/projects/65f3c77206ea3caf68f2d30d/metadata.json"
[2022-05-21T18:42:48Z INFO  rust_script] disarming pkg dir cleanup...
[2022-05-21T18:42:48Z INFO  rust_script] running `cargo run`
[2022-05-21T18:42:48Z INFO  rust_script] cleaning cache with max_age: 604800000
[2022-05-21T18:42:48Z INFO  rust_script] cutoff:            1652553768992 ms
[2022-05-21T18:42:48Z INFO  rust_script] checking: "/Users/dta/Library/Caches/rust-script/projects/d2ff9865f1eaa9644ad89e24"
[2022-05-21T18:42:48Z INFO  rust_script] meta_mtime:        1653158506101 ms
[2022-05-21T18:42:48Z INFO  rust_script] checking: "/Users/dta/Library/Caches/rust-script/projects/65f3c77206ea3caf68f2d30d"
[2022-05-21T18:42:48Z INFO  rust_script] meta_mtime:        1653158568990 ms
[2022-05-21T18:42:48Z INFO  rust_script] checking: "/Users/dta/Library/Caches/rust-script/projects/469150566bd728fc90b4adf6"
[2022-05-21T18:42:48Z INFO  rust_script] meta_mtime:        1653157831910 ms
[2022-05-21T18:42:48Z INFO  rust_script] checking: "/Users/dta/Library/Caches/rust-script/projects/e4e0ddc7731ab1b525ef66f2"
[2022-05-21T18:42:48Z INFO  rust_script] meta_mtime:        1653157605894 ms
[2022-05-21T18:42:48Z INFO  rust_script] checking: "/Users/dta/Library/Caches/rust-script/projects/871fdb4f6a736fff1ddcba23"
[2022-05-21T18:42:48Z INFO  rust_script] meta_mtime:        1653158135317 ms
[2022-05-21T18:42:48Z INFO  rust_script] done cleaning cache.
error: No such file or directory (os error 2)
fornwall commented 1 year ago

@DavidDTA Could you retry with the latest version - just released version 0.23.0? If the problem persists, could you perhaps use strace to see where the problem is (which file or directory does not exist)?

DavidDTA commented 1 year ago

I'm afraid I no longer have a nix setup, and won't be able to retry

bcdroid commented 1 year ago

I had had the same problem, but it appears to now work without problems with both 0.22.0 and 0.23.0. Thank you!

fornwall commented 1 year ago

@DavidDTA & @bcdroid: Thanks!