cargo-make icon indicating copy to clipboard operation
cargo-make copied to clipboard

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

Open wallem89 opened this issue 6 months ago • 0 comments

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

wallem89 avatar Aug 20 '24 07:08 wallem89