Hc package error - No such file or directory - after deleting target directory

I was attempting to fix a missing zome function error when I decided to delete the target directory in case it was not compiled.

After deleting the target directory, I now get a No such file or directory panic error.

$ hc package
> cargo build --release --target=wasm32-unknown-unknown
"cargo build --release --target=wasm32-unknown-unknown"
    Finished release [optimized] target(s) in 0.12s
> wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm
"wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm"
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/libcore/result.rs:999:5
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::continue_panic_fmt
   3: rust_begin_unwind
   4: core::panicking::panic_fmt
   5: core::result::unwrap_failed
   6: wasm_gc::main
   7: std::rt::lang_start::{{closure}}
Error: Couldn't traverse DNA in directory "/home/brian/work/cogov/cogov-dev": command wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm was not successful

Hm, deleting the target directory should be an appropriate way to clean out build artifacts. @freesig you know stuff about rustc; can you identify the issue here?

1 Like

This is fixed in the new release which should be out today in the meantime you can enter the nix-shell like:

nix-shell https://github.com/holochain/holonix/archive/develop.tar.gz
2 Likes

Thank you @freesig. It looks like I’m still getting an issue with the develop.tar.gz version though…

$ hc package
> cargo build --release --target=wasm32-unknown-unknown
"cargo build --release --target=wasm32-unknown-unknown"
    Finished release [optimized] target(s) in 0.07s
> wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm
"wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm"
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/libcore/result.rs:999:5
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::continue_panic_fmt
   3: rust_begin_unwind
   4: core::panicking::panic_fmt
   5: core::result::unwrap_failed
   6: wasm_gc::main
   7: std::rt::lang_start::{{closure}}
Error: Couldn't traverse DNA in directory "/home/brian/work/cogov/cogov-dev/zomes/cogov": command wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm was not successful

You might also need to update the .hcbuild file. See this post:

My .hcbuild file was already up to date.

I’m new to rust, but noticed src/libcore/result.rs:999:5 in the stack trace. How would I find the absolute file path of src/libcore/result.rs?

From https://www.reddit.com/r/rust/comments/73cwro/as_newcomer_with_this_error_trace_how_i_can/dnpdvwn?utm_source=share&utm_medium=web2x

Relative paths are relative to the current working directory, usually the same as the one containing your Cargo.toml , so you want to open "src/hello.txt" or move hello.txt up to the same level.

Looks like there’s a github issue wrt the absolute path in stack traces https://github.com/rust-lang/rust/issues/44938

Now what is the cwd in the case of this stack trace?

$ hc package
> cargo build --release --target=wasm32-unknown-unknown
"cargo build --release --target=wasm32-unknown-unknown"
    Finished release [optimized] target(s) in 0.07s
> wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm
"wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm"
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/libcore/result.rs:999:5
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::continue_panic_fmt
   3: rust_begin_unwind
   4: core::panicking::panic_fmt
   5: core::result::unwrap_failed
   6: wasm_gc::main
   7: std::rt::lang_start::{{closure}}
Error: Couldn't traverse DNA in directory "/home/brian/work/cogov/cogov-dev": command wasm-gc target/wasm32-unknown-unknown/release/cogov.wasm was not successful

result.rs is just the std libraries Result. The error is saying somewhere unwrap() was called on the result of trying to open the path target/wasm32-unknown-unknown/release/cogov.wasm.

Does you’re .hcbuild have $CARGO_TARGET_DIR in it? It should showing up in the output in place of target

Here’s my .hcbuild

{
  "steps": [
    {
      "command": "cargo",
      "arguments": [
        "build",
        "--release",
        "--target=wasm32-unknown-unknown"
      ]
    },
    {
      "command": "wasm-gc",
      "arguments": ["target/wasm32-unknown-unknown/release/cogov.wasm"]
    },
    {
      "command": "wasm-opt",
      "arguments": [
        "-O1",
        "--vacuum",
        "target/wasm32-unknown-unknown/release/cogov.wasm"
      ]
    },
    {
      "command": "wasm2wat",
      "arguments": [
        "target/wasm32-unknown-unknown/release/cogov.wasm",
        "-o",
        "target/wasm32-unknown-unknown/release/cogov.wat"
      ]
    },
    {
      "command": "wat2wasm",
      "arguments": [
        "target/wasm32-unknown-unknown/release/cogov.wat",
        "-o",
        "target/wasm32-unknown-unknown/release/cogov.wasm"
      ]
    }
  ],
  "artifact": "target/wasm32-unknown-unknown/release/cogov.wasm"
}

It’s missing $CARGO_TARGET_DIR. Try this one

Sorry about the way updating this works. We are looking at putting the package process into nix so we can avoid this sort of issue :slight_smile:

That’s ok. Everything is a work in progress. I appreciate your help on this!

Looks like there’s another issue. Am I using the correct versions?

$ rustc -V
rustc 1.41.0-nightly (1bd30ce2a 2019-11-15)
$ hc package
> CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && echo $CARGO_TARGET_DIR
"CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && echo $CARGO_TARGET_DIR "
/home/brian/work/cogov/cogov-dev/target
> CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && cargo build --release --target=wasm32-unknown-unknown --target-dir=$CARGO_TARGET_DIR
"CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && cargo build --release --target=wasm32-unknown-unknown --target-dir=$CARGO_TARGET_DIR"
    Finished release [optimized] target(s) in 0.07s
> CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wasm-gc $CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm
"CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wasm-gc $CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm"
Usage: wasm-gc [options] <INPUT> [OUTPUT]

Options:
    -o NAME             set output file name
        --no-demangle   don't demangle symbol names
    -h, --help          print this help menu

A postprocessing command for wasm files to garbage-collect unused
imports, internal functions, types, etc. This is intended to be
similar to the functionality provided by `--gc-sections` by linkers
in that it is not intended to modify the functionality of the wasm
binary, only make it a little smaller.

Usage of this command typically looks like:

    # Read and write output to one file
    wasm-gc foo.wasm

    # Read input from one file and write it to another file
    wasm-gc input.wasm output.wasm

    # Passing various options
    wasm-gc --no-demangle input.wasm -o output.wasm

Please reports bugs to https://github.com/alexcrichton/wasm-gc if you find
them!

> CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wasm-opt -Oz --vacuum $CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm
"CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wasm-opt -Oz --vacuum $CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm"
Unexpected second positional argument 'name' for INFILE
Error: Couldn't traverse DNA in directory "/home/brian/work/cogov/cogov-dev": command CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wasm-opt -Oz --vacuum $CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm was not successful
$ echo $CARGO_TARGET_DIR
/home/brian/work/cogov/cogov-dev/target

Is the above being run inside this shell?

nix-shell https://github.com/holochain/holonix/archive/develop.tar.gz

Oh wait I think I see the problem

Yes, I had to replace the template {{ name }} with the zome name (cogov in my case).

It’s now packaging!

Yep good one. I forgot that it’s a template. Good catch

Thank you! I appreciate your attention on this.

The test suite also made some progress. I’m going to go to bed I’ll follow up with the other forum posts tomorrow.

1 Like