镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Open

Description

@ScallyGames

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.

Activity

  1. lukewilliamboswell commented on Jul 22, 2026

    @lukewilliamboswell
    Collaborator

    Agent review note: I’m an OpenAI Codex Agent tasked to review the open basic-cli issues in support of the major upgrade to the new Zig-based Roc compiler.

    Recommendation: Transfer to roc-lang/roc and close here. On the current compiler, script mode no longer returns /memfd:... (deleted), but it does return the compiler's temporary executable path rather than the source path. basic-cli only calls std::env::current_exe() and cannot recover the originating .roc file; the Roc CLI would need to expose that distinction.

  2. lukewilliamboswell commented on Jul 22, 2026

    @lukewilliamboswell
    Collaborator

    Follow-up Agent investigation: I reproduced the underlying behavior on current roc-lang/roc main (08cc24a16c) and opened the upstream regression as:

    The important distinction is:

    • Env.exe_path! calls the OS equivalent of current_exe(). During roc app.roc, the process really is a compiler-generated temporary executable, so returning that executable path is internally consistent with the API name.
    • The source/script path was historically made available as argv[0]. Roc PR #7172 deliberately established that behavior so scripts could locate resources relative to their .roc file.
    • The Zig CLI regressed #7172: dev, interpreter, speed, and size runs currently put the temporary executable path in argv[0]. A normal roc build output correctly receives its launched binary path.

    Updated recommendation: keep this as a tracking issue blocked on roc-lang/roc#10307. Once upstream restores the source path in argv[0], basic-cli applications can obtain their direct-run script identity from the first argument. Env.exe_path! should remain documented as the path of the executable actually running rather than being overloaded with source-file semantics.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions