Skip to content

Commit

Permalink
Rework julia loading strategy in anticipation of JLL stdlibs
Browse files Browse the repository at this point in the history
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
staticfloat committed Jul 13, 2020
1 parent 78bd857 commit 91633f1
Show file tree
Hide file tree
Showing 19 changed files with 598 additions and 300 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Note: These instructions are for adding to or improving functionality in the bas
Add new code to Julia's base libraries as follows (this is the "basic" approach; see a more efficient approach in the next section):
1. Edit the appropriate file in the `base/` directory, or add new files if necessary. Create tests for your functionality and add them to files in the `test/` directory. If you're editing C or Scheme code, most likely it lives in `src/` or one of its subdirectories, although some aspects of Julia's REPL initialization live in `ui/`.
1. Edit the appropriate file in the `base/` directory, or add new files if necessary. Create tests for your functionality and add them to files in the `test/` directory. If you're editing C or Scheme code, most likely it lives in `src/` or one of its subdirectories, although some aspects of Julia's REPL initialization live in `cli/`.
2. Add any new files to `sysimg.jl` in order to build them into the Julia system image.
Expand Down
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4860,7 +4860,7 @@ New language features
shell. For example:
julia> ;ls
CONTRIBUTING.md Makefile VERSION deps/ julia@ ui/
CONTRIBUTING.md Makefile VERSION cli/ deps/ julia@
DISTRIBUTING.md NEWS.md Windows.inc doc/ src/ usr/
LICENSE.md README.md base/ etc/ test/
Make.inc README.windows.md contrib/ examples/ tmp/
Expand Down
55 changes: 55 additions & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,29 @@ else
endif

# On Windows, we want shared library files to end up in $(build_bindir), instead of $(build_libdir)
# We also don't really have a private bindir on windows right now, due to lack of RPATH.
ifeq ($(OS),WINNT)
build_shlibdir := $(build_bindir)
shlibdir := $(bindir)
private_shlibdir := $(bindir)
else
build_shlibdir := $(build_libdir)
shlibdir := $(libdir)
private_shlibdir := $(private_libdir)
endif

# If we're on windows, don't do versioned shared libraries. If we're on OSX,
# put the version number before the .dylib. Otherwise, put it after.
ifeq ($(OS), WINNT)
JL_MAJOR_MINOR_SHLIB_EXT := $(SHLIB_EXT)
else
ifeq ($(OS), Darwin)
JL_MAJOR_MINOR_SHLIB_EXT := $(SOMAJOR).$(SOMINOR).$(SHLIB_EXT)
JL_MAJOR_SHLIB_EXT := $(SOMAJOR).$(SHLIB_EXT)
else
JL_MAJOR_MINOR_SHLIB_EXT := $(SHLIB_EXT).$(SOMAJOR).$(SOMINOR)
JL_MAJOR_SHLIB_EXT := $(SHLIB_EXT).$(SOMAJOR)
endif
endif

ifeq ($(OS), FreeBSD)
Expand Down Expand Up @@ -1449,6 +1468,42 @@ JULIA_SYSIMG_debug := $(build_private_libdir)/sys-debug.$(SHLIB_EXT)
JULIA_SYSIMG_release := $(build_private_libdir)/sys.$(SHLIB_EXT)
JULIA_SYSIMG := $(JULIA_SYSIMG_$(JULIA_BUILD_MODE))

ifeq ($(OS),WINNT)
define dep_lib_path
$(subst /,\\\\,$(call rel_path,$(1),$(2)))
endef
else
define dep_lib_path
$(call rel_path,$(1),$(2))
endef
endif

# This whole mess is because we have different relative paths for dependencies at build-time
# versus install-time. Eventually, these will all be locked away in artifacts directories,
# so much of this variation will be gone, (not completely, as we'll still need to support
# from-source builds) but it will be much cleaner.
define argmaxlen
$(if $(1),$(word 1,$(sort $(1))),$(1))
endef
LIBGCC_DEP_NAME = $(call argmaxlen,$(notdir $(wildcard $(build_shlibdir)/libgcc_s*.$(SHLIB_EXT)*)))
LIBGCC_BUILD_DEPLIB = $(call dep_lib_path,$(build_bindir),$(build_shlibdir)/$(LIBGCC_DEP_NAME))
LIBGCC_INSTALL_DEPLIB = $(call dep_lib_path,$(bindir),$(private_shlibdir)/$(LIBGCC_DEP_NAME))

LIBLLVM_DEP_NAME = $(call argmaxlen,$(notdir $(wildcard $(build_shlibdir)/libLLVM*jl.$(SHLIB_EXT)*)))
LIBLLVM_BUILD_DEPLIB = $(call dep_lib_path,$(build_bindir),$(build_shlibdir)/$(LIBGCC_DEP_NAME))
LIBLLVM_INSTALL_DEPLIB = $(call dep_lib_path,$(bindir),$(private_shlibdir)/$(LIBGCC_DEP_NAME))

LIBJULIA_BUILD_DEPLIB := $(call dep_lib_path,$(build_bindir),$(build_shlibdir)/libjulia.$(JL_MAJOR_MINOR_SHLIB_EXT))
LIBJULIA_INSTALL_DEPLIB := $(call dep_lib_path,$(bindir),$(shlibdir)/libjulia.$(JL_MAJOR_MINOR_SHLIB_EXT))

LIBJULIA_DEBUG_BUILD_DEPLIB := $(call dep_lib_path,$(build_bindir),$(build_shlibdir)/libjulia-debug.$(JL_MAJOR_MINOR_SHLIB_EXT))
LIBJULIA_DEBUG_INSTALL_DEPLIB := $(call dep_lib_path,$(bindir),$(shlibdir)/libjulia-debug.$(JL_MAJOR_MINOR_SHLIB_EXT))

LOADER_BUILD_DEP_LIBS = $(LIBGCC_BUILD_DEPLIB):$(LIBLLVM_BUILD_DEPLIB):$(LIBJULIA_BUILD_DEPLIB)
LOADER_DEBUG_BUILD_DEP_LIBS = $(LIBGCC_BUILD_DEPLIB):$(LIBLLVM_BUILD_DEPLIB):$(LIBJULIA_DEBUG_BUILD_DEPLIB)
LOADER_INSTALL_DEP_LIBS = $(LIBGCC_INSTALL_DEPLIB):$(LIBLLVM_INSTALL_DEPLIB):$(LIBJULIA_INSTALL_DEPLIB)
LOADER_DEBUG_INSTALL_DEP_LIBS = $(LIBGCC_INSTALL_DEPLIB):$(LIBLLVM_INSTALL_DEPLIB):$(LIBJULIA_DEBUG_INSTALL_DEPLIB)

# Colors for make
ifndef VERBOSE
VERBOSE := 0
Expand Down
33 changes: 22 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ all: debug release
# sort is used to remove potential duplicates
DIRS := $(sort $(build_bindir) $(build_depsbindir) $(build_libdir) $(build_private_libdir) $(build_libexecdir) $(build_includedir) $(build_includedir)/julia $(build_sysconfdir)/julia $(build_datarootdir)/julia $(build_datarootdir)/julia/stdlib $(build_man1dir))
ifneq ($(BUILDROOT),$(JULIAHOME))
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src src/flisp src/support src/clangsa ui doc deps stdlib test test/embedding test/llvmpasses)
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src src/flisp src/support src/clangsa cli doc deps stdlib test test/embedding test/llvmpasses)
BUILDDIRMAKE := $(addsuffix /Makefile,$(BUILDDIRS)) $(BUILDROOT)/sysimage.mk
DIRS := $(DIRS) $(BUILDDIRS)
$(BUILDDIRMAKE): | $(BUILDDIRS)
Expand Down Expand Up @@ -46,7 +46,7 @@ julia_flisp.boot.inc.phony: julia-deps
$(BUILDROOT)/doc/_build/html/en/index.html: $(shell find $(BUILDROOT)/base $(BUILDROOT)/doc \( -path $(BUILDROOT)/doc/_build -o -path $(BUILDROOT)/doc/deps -o -name *_constants.jl -o -name *_h.jl -o -name version_git.jl \) -prune -o -type f -print)
@$(MAKE) docs

julia-symlink: julia-ui-$(JULIA_BUILD_MODE)
julia-symlink: julia-cli-$(JULIA_BUILD_MODE)
ifeq ($(OS),WINNT)
@echo '@"%~dp0"\'"$$(echo $(call rel_path,$(BUILDROOT),$(JULIA_EXECUTABLE)) | tr / '\\')" '%*' > $(BUILDROOT)/julia.bat
chmod a+x $(BUILDROOT)/julia.bat
Expand Down Expand Up @@ -74,16 +74,16 @@ julia-libllvmcalltest: julia-deps
julia-src-release julia-src-debug : julia-src-% : julia-deps julia_flisp.boot.inc.phony
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/src libjulia-$*

julia-ui-release julia-ui-debug : julia-ui-% : julia-src-%
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/ui julia-$*
julia-cli-release julia-cli-debug : julia-cli-% : julia-src-%
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/cli julia-$*

julia-sysimg-ji : julia-stdlib julia-base julia-ui-$(JULIA_BUILD_MODE) | $(build_private_libdir)
julia-sysimg-ji : julia-stdlib julia-base julia-cli-$(JULIA_BUILD_MODE) | $(build_private_libdir)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) -f sysimage.mk sysimg-ji JULIA_EXECUTABLE='$(JULIA_EXECUTABLE)'

julia-sysimg-bc : julia-stdlib julia-base julia-ui-$(JULIA_BUILD_MODE) | $(build_private_libdir)
julia-sysimg-bc : julia-stdlib julia-base julia-cli-$(JULIA_BUILD_MODE) | $(build_private_libdir)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) -f sysimage.mk sysimg-bc JULIA_EXECUTABLE='$(JULIA_EXECUTABLE)'

julia-sysimg-release julia-sysimg-debug : julia-sysimg-% : julia-sysimg-ji julia-ui-%
julia-sysimg-release julia-sysimg-debug : julia-sysimg-% : julia-sysimg-ji julia-cli-%
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) -f sysimage.mk sysimg-$*

julia-debug julia-release : julia-% : julia-sysimg-% julia-symlink julia-libccalltest julia-libllvmcalltest julia-base-cache
Expand Down Expand Up @@ -154,9 +154,9 @@ julia-base-cache: julia-sysimg-$(JULIA_BUILD_MODE) | $(DIRS) $(build_datarootdir
$(call cygpath_w,$(build_datarootdir)/julia/base.cache))

# public libraries, that are installed in $(prefix)/lib
JL_TARGETS := julia
JL_TARGETS := julia julialoader
ifeq ($(BUNDLE_DEBUG_LIBS),1)
JL_TARGETS += julia-debug
JL_TARGETS += julia-debug julialoader-debug
endif

# private libraries, that are installed in $(prefix)/lib/julia
Expand Down Expand Up @@ -410,8 +410,19 @@ endif
if [ $(BUNDLE_DEBUG_LIBS) = 1 ]; then \
$(call stringreplace,$${DEBUG_TARGET},sys-debug.$(SHLIB_EXT)$$,$(private_libdir_rel)/sys-debug.$(SHLIB_EXT)); \
fi;
endif

ifneq ($(LOADER_BUILD_DEP_LIBS),$(LOADER_INSTALL_DEP_LIBS))
# Next, overwrite relative path to libjulia in our loaders:
$(call stringreplace,$(DESTDIR)$(bindir)/julia,$(LOADER_BUILD_DEP_LIBS)$$,$(LOADER_INSTALL_DEP_LIBS))
$(call stringreplace,$(DESTDIR)$(shlibdir)/libjulialoader.$(JL_MAJOR_MINOR_SHLIB_EXT),$(LOADER_BUILD_DEP_LIBS)$$,$(LOADER_INSTALL_DEP_LIBS))

ifeq ($(BUNDLE_DEBUG_LIBS),1)
$(call stringreplace,$(DESTDIR)$(bindir)/julia-debug,$(LOADER_DEBUG_BUILD_DEP_LIBS)$$,$(LOADER_DEBUG_INSTALL_DEP_LIBS))
$(call stringreplace,$(DESTDIR)$(shlibdir)/libjulialoader-debug.$(JL_MAJOR_MINOR_SHLIB_EXT),$(LOADER_DEBUG_BUILD_DEP_LIBS)$$,$(LOADER_DEBUG_INSTALL_DEP_LIBS))
endif
endif

# On FreeBSD, remove the build's libdir from each library's RPATH
ifeq ($(OS),FreeBSD)
$(JULIAHOME)/contrib/fixup-rpath.sh "$(PATCHELF)" $(DESTDIR)$(libdir) $(build_libdir)
Expand Down Expand Up @@ -528,7 +539,7 @@ clean: | $(CLEAN_TARGETS)
@-$(MAKE) -C $(BUILDROOT)/base clean
@-$(MAKE) -C $(BUILDROOT)/doc clean
@-$(MAKE) -C $(BUILDROOT)/src clean
@-$(MAKE) -C $(BUILDROOT)/ui clean
@-$(MAKE) -C $(BUILDROOT)/cli clean
@-$(MAKE) -C $(BUILDROOT)/test clean
@-$(MAKE) -C $(BUILDROOT)/stdlib clean
-rm -f $(BUILDROOT)/julia
Expand All @@ -552,7 +563,7 @@ distcleanall: cleanall

.PHONY: default debug release check-whitespace release-candidate \
julia-debug julia-release julia-stdlib julia-deps julia-deps-libs \
julia-ui-release julia-ui-debug julia-src-release julia-src-debug \
julia-cli-release julia-cli-debug julia-src-release julia-src-debug \
julia-symlink julia-base julia-sysimg julia-sysimg-ji julia-sysimg-release julia-sysimg-debug \
test testall testall1 test test-* test-revise-* \
clean distcleanall cleanall clean-* \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ The Julia source code is organized as follows:
doc/build detailed notes for building Julia
src/ source for Julia language core
test/ test suites
ui/ source for various front ends
cli/ source for the command line interface/REPL
usr/ binaries and shared libraries loaded by Julia's standard libraries

## Terminal, Editors and IDEs
Expand Down
File renamed without changes.
73 changes: 47 additions & 26 deletions ui/Makefile → cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,47 @@ include $(JULIAHOME)/deps/Versions.make
include $(JULIAHOME)/Make.inc
include $(JULIAHOME)/deps/llvm-ver.make

override CFLAGS += $(JCFLAGS)
override CXXFLAGS += $(JCXXFLAGS)
override CPPFLAGS += $(JCPPFLAGS)

SRCS := repl

HEADERS := $(addprefix $(JULIAHOME)/src/,julia.h julia_assert.h julia_threads.h julia_internal.h options.h) \
$(BUILDDIR)/../src/julia_version.h $(wildcard $(JULIAHOME)/src/support/*.h) $(LIBUV_INC)/uv.h

FLAGS := -I$(BUILDROOT)/src -I$(JULIAHOME)/src -I$(JULIAHOME)/src/support -I$(build_includedir)
ifneq ($(USEMSVC), 1)
FLAGS += -Wall -Wno-strict-aliasing -fno-omit-frame-pointer -Wc++-compat
endif

OBJS := $(SRCS:%=$(BUILDDIR)/%.o)
DOBJS := $(SRCS:%=$(BUILDDIR)/%.dbg.obj)
DEBUGFLAGS += $(FLAGS)
SHIPFLAGS += $(FLAGS)
JLDFLAGS += $(LDFLAGS) $(NO_WHOLE_ARCHIVE) $(OSLIBS) $(RPATH)
LOADER_CFLAGS := $(JCFLAGS) -I$(BUILDROOT)/src -I$(JULIAHOME)/src -I$(JULIAHOME)/src/support -I$(build_includedir)
LOADER_LDFLAGS :=

ifeq ($(USE_SYSTEM_LIBM),0)
ifneq ($(UNTRUSTED_SYSTEM_LIBM),0)
JLDFLAGS += $(WHOLE_ARCHIVE) $(build_libdir)/libopenlibm.a $(NO_WHOLE_ARCHIVE)
endif
ifeq ($(OS),WINNT)
LOADER_CFLAGS += -municode -mconsole -ffreestanding -nostdlib \
-fno-stack-check -fno-stack-protector -mno-stack-arg-probe
endif

#LDFLAGS += -static
ifeq ($(OS),WINNT)
JLDFLAGS += -municode
LOADER_LDFLAGS += -municode -mconsole -ffreestanding -nostdlib \
--disable-auto-import --disable-runtime-pseudo-reloc \
-lntdll -lkernel32 -lpsapi
else ifeq ($(OS),Linux)
LOADER_LDFLAGS += -ldl -rdynamic
else ifeq ($(OS),FreeBSD)
LOADER_LDFLAGS += -ldl -rdynamic
endif

# Build list of dependent libraries that must be opened
SHIPFLAGS += -DDEP_LIBS="\"$(LOADER_BUILD_DEP_LIBS)\""
DEBUGFLAGS += -DDEP_LIBS="\"$(LOADER_DEBUG_BUILD_DEP_LIBS)\""

SRCS := loader_exe loader_lib
OBJS := $(SRCS:%=$(BUILDDIR)/%.o)
DOBJS := $(SRCS:%=$(BUILDDIR)/%.dbg.obj)
LIB_OBJS := $(BUILDDIR)/loader_lib.o
LIB_DOBJS := $(BUILDDIR)/loader_lib.dbg.obj

default: release
all: release debug
release debug : % : julia-%

$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(HEADERS)
@$(call PRINT_CC, $(CC) $(CPPFLAGS) $(CFLAGS) $(SHIPFLAGS) -c $< -o $@)
@$(call PRINT_CC, $(CC) $(LOADER_CFLAGS) $(SHIPFLAGS) -c $< -o $@)
$(BUILDDIR)/%.dbg.obj: $(SRCDIR)/%.c $(HEADERS)
@$(call PRINT_CC, $(CC) $(CPPFLAGS) $(CFLAGS) $(DEBUGFLAGS) -c $< -o $@)
@$(call PRINT_CC, $(CC) $(LOADER_CFLAGS) $(DEBUGFLAGS) -c $< -o $@)

ifeq ($(OS),WINNT)
ifneq ($(USEMSVC), 1)
Expand All @@ -57,8 +60,8 @@ DOBJS += julia_res.o
endif
endif

julia-release: $(build_bindir)/julia$(EXE)
julia-debug: $(build_bindir)/julia-debug$(EXE)
julia-release: $(build_bindir)/julia$(EXE) $(build_shlibdir)/libjulialoader.$(JL_MAJOR_MINOR_SHLIB_EXT)
julia-debug: $(build_bindir)/julia-debug$(EXE) $(build_shlibdir)/libjulialoader-debug.$(JL_MAJOR_MINOR_SHLIB_EXT)

# Embed an Info.plist in the julia executable
# Create an intermediate target Info.plist for Darwin code signing.
Expand All @@ -82,10 +85,28 @@ else
CXXLD := $(LD)
endif

$(build_shlibdir)/libjulialoader.$(JL_MAJOR_MINOR_SHLIB_EXT): $(LIB_OBJS)
@$(call PRINT_LINK, $(CXXLD) $(LOADER_CFLAGS) -shared $(SHIPFLAGS) $^ -o $@ $(LOADER_LDFLAGS))
ifneq ($(OS), WINNT)
@ln -sf $(notdir $@) $(build_shlibdir)/libjulialoader.$(JL_MAJOR_SHLIB_EXT)
@ln -sf $(notdir $@) $(build_shlibdir)/libjulialoader.$(SHLIB_EXT)
endif


$(build_shlibdir)/libjulialoader-debug.$(JL_MAJOR_MINOR_SHLIB_EXT): $(LIB_DOBJS)
@$(call PRINT_LINK, $(CXXLD) $(LOADER_CFLAGS) -shared $(DEBUGFLAGS) $^ -o $@ $(LOADER_LDFLAGS))
ifneq ($(OS), WINNT)
@ln -sf $(notdir $@) $(build_shlibdir)/libjulialoader-debug.$(JL_MAJOR_SHLIB_EXT)
@ln -sf $(notdir $@) $(build_shlibdir)/libjulialoader-debug.$(SHLIB_EXT)
endif


$(build_bindir)/julia$(EXE): $(OBJS)
@$(call PRINT_LINK, $(CXXLD) $(CXXFLAGS) $(CXXLDFLAGS) $(LINK_FLAGS) $(SHIPFLAGS) $(OBJS) -o $@ -L$(build_private_libdir) -L$(build_libdir) -L$(build_shlibdir) -ljulia $(JLDFLAGS) $(CXXLDFLAGS))
@$(call PRINT_LINK, $(CXXLD) $(LOADER_CFLAGS) $(SHIPFLAGS) $^ -o $@ $(LOADER_LDFLAGS))

$(build_bindir)/julia-debug$(EXE): $(DOBJS)
@$(call PRINT_LINK, $(CXXLD) $(CXXFLAGS) $(CXXLDFLAGS) $(LINK_FLAGS) $(DEBUGFLAGS) $(DOBJS) -o $@ -L$(build_private_libdir) -L$(build_libdir) -L$(build_shlibdir) -ljulia-debug $(JLDFLAGS) $(CXXLDFLAGS))
@$(call PRINT_LINK, $(CXXLD) $(LOADER_CFLAGS) $(DEBUGFLAGS) $^ -o $@ $(LOADER_LDFLAGS))


clean: | $(CLEAN_TARGETS)
rm -f *.o *.dbg.obj
Expand Down
63 changes: 63 additions & 0 deletions cli/loader_exe.c
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
Loading

0 comments on commit 91633f1

Please sign in to comment.