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

Env.exePath returns "/memfd:roc_file_descriptor (deleted)" when running as script #265

Open
ScallyGames opened this issue Nov 17, 2024 · 0 comments

Comments

@ScallyGames
Copy link

Minimal Reproducible Example:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.16.0/O00IPk-Krg_diNS2dVWlI0ZQP794Vctxzv0ha96mK0E.tar.br",
}

import pf.Env
import pf.Path

main = 
    exePath = Env.exePath!
    exePathStr = Path.display exePath
    dbg exePathStr
    Task.ok {}

Run as roc test.roc

Expected Behavior:

Output of /home/user/path/to/script/test.roc

Actual Behavior:

Output of /memfd:roc_file_descriptor (deleted)

Environment:

OS: Archlinux
Roc Version: roc nightly pre-release, built from commit 06996d8

Context

Discussed in https://roc.zulipchat.com/#narrow/channel/231634-beginners/topic/basic-cli.20debugging.20Env.2EexePath

Implementation (

pub extern "C" fn roc_fx_exePath(_roc_str: &RocStr) -> RocResult<RocList<u8>, ()> {
) just defers to Rust's std::env::current_exe() (https://github.com/rust-lang/rust/blob/a8e75c53d0036b5d012cbc0ee5de17f8991fe60c/library/std/src/sys/pal/unix/os.rs#L406) which reads /proc/self/exe which seems to be invalid when running through roc <file>.

Somewhat related is roc-lang/roc#7172 which fixed argv[0] to be set correctly.

Proposed solution is to use argv[0] and ideally combine with Env.cwd for a full absolute path (similar to https://github.com/rust-lang/rust/blob/a8e75c53d0036b5d012cbc0ee5de17f8991fe60c/library/std/src/sys/pal/unix/os.rs#L253) if /proc/self/exe can't be utilized.

Credit to @jwoudenberg and @lukewilliamboswell who did most of the work of putting this information together.

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

No branches or pull requests

1 participant