-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework julia loading strategy in anticipation of JLL stdlibs
We move all code from `ui/repl.c` to `libjulia` and create two new entrypoints for the Julia REPL: an executable loader (`julia.exe`) and a library loader (`libjulialoader.dll`). These entrypoints know how to load all necessary dependent libraries and set things up such that `libjulia` can run. `libjulialoader` is intended for use by embedding clients. We move this code to `cli/` as `ui/` is somewhat misleading at this point. All this work is in expectation of future JLL stdlib work, which will require RPATH-like semantics on all platforms (including Windows). This commit enables such semantics by allowing the loader executable to directly `dlopen()` any necessary libraries, which will include foundational support libraries such as `libgcc_s` or `libLLVM`. Right now, these libraries are all dumped into `bin` or `lib` or `lib/julia`, so finding them is not hard, however in the future they will be stored in places such as `share/julia/stdlib/artifacts/<treehash>/lib`. Until such a point, this PR will not force loading of `libgcc` and `libLLVM` (especially as running `make install` currently changes the relative path!) and only loads `libjulia`, however the infrastructure is here, and we can move forward with the next phases of The Great Work.
- Loading branch information
1 parent
78bd857
commit 91633f1
Showing
19 changed files
with
598 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <errno.h> | ||
#include <libgen.h> | ||
|
||
/* Bring in definitions for `PATH_MAX` and `PATHSEPSTRING`, `jl_ptls_t`, etc... */ | ||
#include "../src/julia.h" | ||
|
||
#ifdef _OS_WINDOWS_ | ||
#include <windows.h> | ||
#include <direct.h> | ||
#else | ||
#include <unistd.h> | ||
#include <dlfcn.h> | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// Declarations from `loader_lib.c` | ||
extern const char * get_exe_dir(); | ||
extern int load_repl(const char *, int, char **); | ||
|
||
|
||
/* Define ptls getter, as this cannot be defined within a shared library. */ | ||
#if !defined(_OS_WINDOWS_) && !defined(_OS_DARWIN_) | ||
JL_DLLEXPORT JL_CONST_FUNC jl_ptls_t jl_get_ptls_states_static(void) | ||
{ | ||
static __attribute__((tls_model("local-exec"))) __thread jl_tls_states_t tls_states; | ||
return &tls_states; | ||
} | ||
#endif | ||
|
||
#ifdef _OS_WINDOWS_ | ||
int wmain(int argc, wchar_t *argv[], wchar_t *envp[]) | ||
#else | ||
int main(int argc, char * argv[]) | ||
#endif | ||
{ | ||
// Immediately get the current exe dir, allowing us to calculate relative paths. | ||
const char * exe_dir = get_exe_dir(); | ||
|
||
#ifdef _OS_WINDOWS_ | ||
// Convert Windows wchar_t values to UTF8 | ||
for (int i=0; i<argc; i++) { | ||
char * new_argv_i = NULL; | ||
if (!wchar_to_utf8(argv[i], &new_argv_i)) { | ||
fprintf(stderr, "Unable to convert %d'th argument to UTF-8!\n", i); | ||
return 1; | ||
} | ||
argv[i] = (wchar_t *)new_argv_i; | ||
} | ||
#endif | ||
|
||
// Call load_repl with our initialization arguments: | ||
return load_repl(exe_dir, argc, (char **)argv); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif |
Oops, something went wrong.