Skip to content

Should we export get_self_path and friends? #4483

@LiberalArtist

Description

@LiberalArtist

In the "Inside" manual, we document ways to embed files (particularly bootfiles) as executable segments or equivalent on various platforms, including finding the path to the running executable:

@section[#:tag "segment-ideas"]{Embedding Files in Executable Sections}
Locating external files on startup, such as the boot files needed for
Racket CS, can be troublesome. An alternative to having separate files
is to embed the files in an ELF or Mach-O executable as data segments
or in a Windows executable as a resource. Embedding files in that way
requires using OS-specific linking steps and runtime libraries.

(Rendered at https://docs.racket-lang.org/inside/segment-ideas.html)

Racket also implements these ideas for its own use:

Defines self_exe_t get_self_path(char *exec_file),
which takes argv[0] and returns an improved representation of
the containing executable. At worst, on Unix, uses `PATH` to
convert `exec_file` into a path.
On Mac (even XonX), `find_mach_o_segment` is also defined.
On Unix (not Mac OS, not even XonX), `find_elf_section`
is also defined.
If USE_EXE_LOOKUP_VIA_PATH, also: `lookup_exe_via_path`,
`path_append`, and `do_path_append`.

Would it make sense for Racket to export these functions in racketcs.h (and scheme.h for BC)?

Someone in another context asked today about embedding files in executables and finding the path to the running program, and I pointed them to what Racket does. The implementations in the "Inside" manual for Windows, Mac, and Linux are reasonably concise, but I remembered there are more issues on the BSDs and other Unix-like systems without /proc/self/exe, and Racket handles these in self_exe.inc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions