Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo make run rust script with rust-script fails on encrypted drive because file name too long #1150

Closed
wallem89 opened this issue Aug 20, 2024 · 8 comments
Assignees

Comments

@wallem89
Copy link

wallem89 commented Aug 20, 2024

Describe The Bug

Running a rust script trough cargo make fails on a dual boot system with Ubuntu 24.04 LTS 6.8.0-40-generic with an encrypted disk

To Reproduce

  1. Install Ubuntu 24.04 LTS
  2. Encrypt Linux partition following these steps: https://jumpcloud.com/blog/how-to-encrypt-ubuntu-20-04-desktop-post-installation
  3. Install Rust, Cargo etc.
  4. Create a new cargo project with cargo new <project-name>
  5. Add Makefile.toml with a task with task name <task-name> as explained in the Readme: https://github.com/sagiegurari/cargo-make?tab=readme-ov-file#rust-code
  6. Execute Cargo make <task-name>

Error Stack

[cargo-make] INFO - Execute Command: "rust-script" "/home/user01/git/rust-script-cargo-make/target/_cargo_make_temp/persisted_scripts/9E82D59A8E20E9E9C36290BD2CBF6FCCE20B02CD6D095A42E8DED57C29E89525.rs"
error: could not write output to /home/user01/.cache/rust-script/binaries/release/deps/_9e82d59a8e20e9e9c36290bd2cbf6fcce20b02cd6d095a42e8ded57c29e89525_bf38f7868792efabca30ea61-8b0e8709f49ba593._9e82d59a8e20e9e9c36290bd2cbf6fcce20b02cd6d095a42e8ded57c29e89525_bf38f7868792efabca30ea61.a89cfab540600d1e-cgu.0.rcgu.o: File name too long

error: could not compile `_9e82d59a8e20e9e9c36290bd2cbf6fcce20b02cd6d095a42e8ded57c29e89525_bf38f7868792efabca30ea61` (bin "_9e82d59a8e20e9e9c36290bd2cbf6fcce20b02cd6d095a42e8ded57c29e89525_bf38f7868792efabca30ea61") due to 1 previous error
error: Could not execute cargo
[cargo-make] ERROR - Unable to execute rust code.
[cargo-make] WARN - Build Failed.

Code Sample

// src/main.rs
fn main() {
    println!("Hello, world!");
}
# Makefile.toml
[tasks.foo]
script_runner = "@rust"
script = '''
fn main() {
    println!("running me will fail..");
}
'''

Further information

The file name it fails on, _9e82d59a8e20e9e9c36290bd2cbf6fcce20b02cd6d095a42e8ded57c29e89525_bf38f7868792efabca30ea61-8b0e8709f49ba593._9e82d59a8e20e9e9c36290bd2cbf6fcce20b02cd6d095a42e8ded57c29e89525_bf38f7868792efabca30ea61.a89cfab540600d1e-cgu.0.rcgu.o in this example, is 228 bytes long. This can be check with:
echo "9e82d59a8e20e9e9c36290bd2cbf6fcce20b02cd6d095a42e8ded57c29e89525_bf38f7868792efabca30ea61-8b0e8709f49ba593._9e82d59a8e20e9e9c36290bd2cbf6fcce20b02cd6d095a42e8ded57c29e89525_bf38f7868792efabca30ea61.a89cfab540600d1e-cgu.0.rcgu.o" | wc -c .
This shouldn't be a problem on a non-encryped Linux system because the maximum file name length on my system (check with getconf NAME_MAX /dev/nvme0 ; getconf PATH_MAX /dev/nvme0 is: 255. But unfortunately on encrypted systems this limit is lower (143 bytes), for background information: https://askubuntu.com/questions/728465/how-can-i-increase-ubuntus-143-byte-file-name-limit-for-encrypted-directories.

I have double checked this by creating a file with touch with the same file name length with a length of 143 bytes can be created.

When running the rust script as part of the task with the cargo-script runner it fails in the same way. Running the same with cargo-play will work:

# Makefile.toml
[tasks.foo]
env = { "CARGO_MAKE_RUST_SCRIPT_PROVIDER" = "cargo-play" }
script_runner = "@rust"
script = '''
fn main() {
    println!("running me will not fail..");
}
'''
[cargo-make] INFO - Execute Command: "cargo" "play" "/home/user01/git/rust-script-cargo-make/target/_cargo_make_temp/persisted_scripts/9D1C9C25F7714024B526BD4FEE5426D4B269A2803BFF48701DAEA9FF09D710F9.rs"
   Compiling p4rn1y4sdzkjharzweabgf5fwsrb5 v0.1.0 (/tmp/cargo-play.4RN1Y4sDZkJHaRZweAbgF5FWSRb5)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `/tmp/cargo-play.4RN1Y4sDZkJHaRZweAbgF5FWSRb5/target/debug/p4rn1y4sdzkjharzweabgf5fwsrb5`
running me will not fail..
[cargo-make] INFO - Build Done in 0.36 seconds.

When moving the Rust script to an actual Rust script the behavior is the same when running through cargo make:

# Makefile.toml
[tasks.foo]
script_runner = "@rust"
script = { file = "script.rs" }
// script.rs
fn main() {
    println!("running me will not fail when not running through cargo make");
}

When running the Rust script directly with rust-script it does work:

$ rust-script script.rs
running me will not fail when not running through cargo make

But when changing the name of the script to something with a longer name, e.g. 733788858E67B5B8B2D6E2209D3C91EA16E7E8888ECA4616F707AF276465F795.rs this script fails too when running with: rust-script 733788858E67B5B8B2D6E2209D3C91EA16E7E8888ECA4616F707AF276465F795.rs

error: could not write output to /home/user01/.cache/rust-script/binaries/release/deps/_733788858e67b5b8b2d6e2209d3c91ea16e7e8888eca4616f707af276465f795_fd11e24052838ceb05481c15-7528ac1c89df1104._733788858e67b5b8b2d6e2209d3c91ea16e7e8888eca4616f707af276465f795_fd11e24052838ceb05481c15.91dd9bcbcc6a116d-cgu.0.rcgu.o: File name too long

error: could not compile `_733788858e67b5b8b2d6e2209d3c91ea16e7e8888eca4616f707af276465f795_fd11e24052838ceb05481c15` (bin "_733788858e67b5b8b2d6e2209d3c91ea16e7e8888eca4616f707af276465f795_fd11e24052838ceb05481c15") due to 1 previous error
error: Could not execute cargo
@sagiegurari
Copy link
Owner

@wallem89 sorry for late reply.
cargo-make generates a file at runtime with its name as sha256 of its content.
reason is to reuse same file over and over if content didn't change as rust compilation is slow.
i can move to a different hashing algo that is less powerful but generates shorter names.

@sagiegurari
Copy link
Owner

@wallem89 i pushed a possible fix in dev branch 0.37.17 mind trying it out to see if it helps? as i have no way to validate this.

@wallem89
Copy link
Author

wallem89 commented Sep 2, 2024

Thanks @sagiegurari for looking into this issue and providing the branch with possible fix.

I am trying to test but it is still not working or I din't manage to set cargo-make to the correct branch.

error: could not write output to /home/user01/.cache/rust-script/binaries/release/deps/_32ac41162beb9267fe10a0220917e973_236cd926da3cc1f0ec423f7f-f1dfe9adb8b3f0f3._32ac41162beb9267fe10a0220917e973_236cd926da3cc1f0ec423f7f.26f36b6d57b93943-cgu.1.rcgu.o: File name too long

error: could not compile `_32ac41162beb9267fe10a0220917e973_236cd926da3cc1f0ec423f7f` (bin "_32ac41162beb9267fe10a0220917e973_236cd926da3cc1f0ec423f7f") due to 1 previous error
error: Could not execute cargo
[cargo-make] ERROR - Unable to execute rust code.
[cargo-make] WARN - Build Failed.

If I check my cargo-make version it still shows 0.37.16:

$ cargo make --version
cargo-make 0.37.16

I (tried) to install with the following command:

cargo install --git https://github.com/sagiegurari/cargo-make cargo-make --branch "0.37.17" --force

But when done it still reports the following:

Replaced package `cargo-make v0.37.16 (https://github.com/sagiegurari/cargo-make#0e4a95dc)` with `cargo-make v0.37.16 (https://github.com/sagiegurari/cargo-make?branch=0.37.17#2e9a505b)` (executables `cargo-make`, `makers`)

Looks like it indeed switched branches and the version number is only confusing because it still says 0.37.16 because this is not updated yet in cargo.toml.

So I am afraid the possible fix didn't help.

@sagiegurari
Copy link
Owner

thanks. dumb question, can you do touch or something and test max file len? and maybe i can do some fallback and cut filename if failing but need some sort of estimated len to understand the size of the issue

@wallem89
Copy link
Author

wallem89 commented Sep 2, 2024

Yes I did this during my initial investigation of the source of the issue, as I wrote:

"I have double checked this by creating a file with touch with the same file name length with a length of 143 bytes can be created."

So the maximum length is 143 bytes as also stated here: https://askubuntu.com/questions/728465/how-can-i-increase-ubuntus-143-byte-file-name-limit-for-encrypted-directories

@sagiegurari
Copy link
Owner

great so will try to get to that as a target

@sagiegurari
Copy link
Owner

@wallem89 sorry it took so long. can you retry again using that same branch? make sure to pull it.
i'm trying original flow and if fails, i try to cut the path to limit the full path to 130 chars. not amazing but you seem to be an edge case.

@sagiegurari
Copy link
Owner

released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants