-
-
Notifications
You must be signed in to change notification settings - Fork 687
Description
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:
racket/pkgs/racket-doc/scribblings/inside/appendix.scrbl
Lines 131 to 137 in 8743229
| @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:
racket/racket/src/start/self_exe.inc
Lines 3 to 14 in 8743229
| 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.