Skip to content

Commit

Permalink
simplify build and output options to --output-o, --output-ji, and --o…
Browse files Browse the repository at this point in the history
…utput-bc

with filenames.
  • Loading branch information
JeffBezanson committed Jun 22, 2015
1 parent 1e081b7 commit a703799
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ before_install:
script:
- make check-whitespace || exit 1
- make $BUILDOPTS -C base version_git.jl.phony
- make $BUILDOPTS NO_GIT=1 prefix=/tmp/julia install | moreutils/ts -s "%.s"
- make $BUILDOPTS NO_GIT=1 JULIA_SYSIMG_BUILD_FLAGS="--output-ji ../usr/lib/julia/sys.ji" prefix=/tmp/julia install | moreutils/ts -s "%.s"
- if [ `uname` = "Darwin" ]; then
for name in spqr umfpack colamd cholmod amd suitesparse_wrapper; do
install -pm755 usr/lib/lib${name}*.dylib* /tmp/julia/lib/julia/;
Expand Down
29 changes: 17 additions & 12 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,26 @@ LD := link
endif #USEMSVC
RANLIB := $(CROSS_COMPILE)ranlib

# file extensions
ifeq ($(OS), WINNT)
SHLIB_EXT = dll
SHELL_EXT = bat
else ifeq ($(OS), Darwin)
SHLIB_EXT = dylib
SHELL_EXT = sh
else
SHLIB_EXT = so
SHELL_EXT = sh
endif


# if not absolute, then relative to the directory of the julia executable
# on windows, use .ji by default
ifeq ($(OS),WINNT)
JCPPFLAGS += "-DJL_SYSTEM_IMAGE_PATH=\"$(build_private_libdir_rel)/sys.ji\""
else
JCPPFLAGS += "-DJL_SYSTEM_IMAGE_PATH=\"$(build_private_libdir_rel)/sys.$(SHLIB_EXT)\""
endif

# On Windows, we want shared library files to end up in $(build_bindir), instead of $(build_libdir)
ifeq ($(OS),WINNT)
Expand Down Expand Up @@ -681,18 +698,6 @@ else
RPATH_ORIGIN = -Wl,-rpath,'$$ORIGIN' -Wl,-z,origin
endif

# file extensions
ifeq ($(OS), WINNT)
SHLIB_EXT = dll
SHELL_EXT = bat
else ifeq ($(OS), Darwin)
SHLIB_EXT = dylib
SHELL_EXT = sh
else
SHLIB_EXT = so
SHELL_EXT = sh
endif

# --whole-archive
ifeq ($(OS), Darwin)
WHOLE_ARCHIVE = -Xlinker -all_load
Expand Down
23 changes: 17 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,24 @@ BASE_SRCS := $(wildcard base/*.jl base/*/*.jl base/*/*/*.jl)

$(build_private_libdir)/inference0.o: $(CORE_SRCS) | $(build_private_libdir)
@$(call PRINT_JULIA, cd base && \
$(call spawn,$(JULIA_EXECUTABLE)) -C $(JULIA_CPU_TARGET) --build $(call cygpath_w,$(build_private_libdir)/inference0) -f \
$(call spawn,$(JULIA_EXECUTABLE)) -C $(JULIA_CPU_TARGET) --output-o $(call cygpath_w,$(build_private_libdir)/inference0.o) -f \
coreimg.jl)

$(build_private_libdir)/inference.o: $(build_private_libdir)/inference0.$(SHLIB_EXT)
@$(call PRINT_JULIA, cd base && \
$(call spawn,$(JULIA_EXECUTABLE)) -C $(JULIA_CPU_TARGET) --build $(call cygpath_w,$(build_private_libdir)/inference) -f \
-J $(call cygpath_w,$(build_private_libdir)/inference0.ji) coreimg.jl)
$(call spawn,$(JULIA_EXECUTABLE)) -C $(JULIA_CPU_TARGET) --output-o $(call cygpath_w,$(build_private_libdir)/inference.o) -f \
-J $(call cygpath_w,$(build_private_libdir)/inference0.$(SHLIB_EXT)) coreimg.jl)

# on windows, also generate a .ji file so we can delete the .dll
ifeq ($(OS),WINNT)
JULIA_SYSIMG_BUILD_FLAGS += --output-ji $(call cygpath_w,$(build_private_libdir)/sys.ji)
endif

COMMA:=,
$(build_private_libdir)/sys.o: VERSION $(BASE_SRCS) $(build_docdir)/helpdb.jl $(build_private_libdir)/inference.$(SHLIB_EXT)
@$(call PRINT_JULIA, cd base && \
$(call spawn,$(JULIA_EXECUTABLE)) -C $(JULIA_CPU_TARGET) --build $(call cygpath_w,$(build_private_libdir)/sys) -f \
-J $(call cygpath_w,$(build_private_libdir)/inference.ji) sysimg.jl \
$(call spawn,$(JULIA_EXECUTABLE)) -C $(JULIA_CPU_TARGET) --output-o $(call cygpath_w,$(build_private_libdir)/sys.o) $(JULIA_SYSIMG_BUILD_FLAGS) -f \
-J $(call cygpath_w,$(build_private_libdir)/inference.$(SHLIB_EXT)) sysimg.jl \
|| { echo '*** This error is usually fixed by running `make clean`. If the error persists$(COMMA) try `make cleanall`. ***' && false; } )

$(build_bindir)/stringreplace: contrib/stringreplace.c | $(build_bindir)
Expand Down Expand Up @@ -358,9 +363,15 @@ else ifeq ($(OS), Linux)
endif

# Overwrite JL_SYSTEM_IMAGE_PATH in julia library
ifeq ($(OS),WINNT)
for julia in $(DESTDIR)$(private_libdir)/libjulia*.$(SHLIB_EXT) ; do \
$(call spawn,$(build_bindir)/stringreplace $$(strings -t x - $$julia | grep "sys.ji$$" | awk '{print $$1;}' ) "$(private_libdir_rel)/sys.ji" 256 $(call cygpath_w,$$julia)); \
done
else
for julia in $(DESTDIR)$(private_libdir)/libjulia*.$(SHLIB_EXT) ; do \
$(call spawn,$(build_bindir)/stringreplace $$(strings -t x - $$julia | grep "sys.$(SHLIB_EXT)$$" | awk '{print $$1;}' ) "$(private_libdir_rel)/sys.$(SHLIB_EXT)" 256 $(call cygpath_w,$$julia)); \
done
endif
endif

mkdir -p $(DESTDIR)$(sysconfdir)
Expand Down Expand Up @@ -508,7 +519,7 @@ test: check-whitespace $(JULIA_BUILD_MODE)
@$(MAKE) $(QUIET_MAKE) -C test default JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)

testall: check-whitespace $(JULIA_BUILD_MODE)
cp $(build_prefix)/lib/julia/sys.ji local.ji && $(JULIA_EXECUTABLE) -J local.ji -e 'true' && rm local.ji
cp $(build_prefix)/lib/julia/sys.$(SHLIB_EXT) local.$(SHLIB_EXT) && $(JULIA_EXECUTABLE) -J local.$(SHLIB_EXT) -e 'true' && rm local.$(SHLIB_EXT)
@$(MAKE) $(QUIET_MAKE) -C test all JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)

testall1: check-whitespace $(JULIA_BUILD_MODE)
Expand Down
5 changes: 3 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,11 @@ let reqarg = Set(UTF8String["--home", "-H",
"--startup-file",
"--compile",
"--check-bounds",
"--dump-bitcode",
"--depwarn",
"--inline",
"--build", "-b",
"--output-o",
"--output-ji",
"--output-bc",
"--bind-to"])
global process_options
function process_options(opts::JLOptions, args::Vector{UTF8String})
Expand Down
7 changes: 4 additions & 3 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ immutable JLOptions
quiet::Int8
julia_home::Ptr{UInt8}
julia_bin::Ptr{UInt8}
build_path::Ptr{UInt8}
eval::Ptr{UInt8}
print::Ptr{UInt8}
postboot::Ptr{UInt8}
Expand All @@ -23,13 +22,15 @@ immutable JLOptions
malloc_log::Int8
opt_level::Int8
check_bounds::Int8
dumpbitcode::Int8
depwarn::Int8
can_inline::Int8
fast_math::Int8
worker::Int8
bindto::Ptr{UInt8}
handle_signals::Int8
bindto::Ptr{UInt8}
outputbc::Ptr{UInt8}
outputo::Ptr{UInt8}
outputji::Ptr{UInt8}
end

JLOptions() = unsafe_load(cglobal(:jl_options, JLOptions))
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void jl_init_frontend(void)

// Enable / disable syntax deprecation warnings
// Disable in imaging mode to avoid i/o errors (#10727)
if (jl_options.build_path != NULL)
if (jl_generating_output())
jl_parse_depwarn(0);
else
jl_parse_depwarn((int)jl_options.depwarn);
Expand Down
4 changes: 2 additions & 2 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static inline void add_named_global(GlobalValue *gv, void *addr)
#ifdef _OS_WINDOWS_
std::string imp_name;
// setting DLLEXPORT correctly only matters when building a binary
if (jl_options.build_path != NULL) {
if (jl_generating_output()) {
// add the __declspec(dllimport) attribute
gv->setDLLStorageClass(GlobalValue::DLLImportStorageClass);
// this will cause llvm to rename it, so we do the same
Expand All @@ -97,7 +97,7 @@ static inline void add_named_global(GlobalValue *gv, void *addr)

#ifdef _OS_WINDOWS_
// setting DLLEXPORT correctly only matters when building a binary
if (jl_options.build_path != NULL) {
if (jl_generating_output()) {
if (gv->getLinkage() == GlobalValue::ExternalLinkage)
gv->setLinkage(GlobalValue::DLLImportLinkage);
#ifdef _P64
Expand Down
2 changes: 1 addition & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5683,7 +5683,7 @@ extern "C" void jl_init_codegen(void)
#if defined(_CPU_PPC_) || defined(_CPU_PPC64_)
imaging_mode = true; // LLVM seems to JIT bad TOC tables for the optimizations we attempt in non-imaging_mode
#else
imaging_mode = jl_options.build_path != NULL;
imaging_mode = jl_generating_output();
#endif

#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 3
Expand Down
41 changes: 22 additions & 19 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,16 @@ DLLEXPORT int jl_running_on_valgrind()
return RUNNING_ON_VALGRIND;
}

static void jl_load_sysimg_so()
static int jl_load_sysimg_so()
{
#ifndef _OS_WINDOWS_
Dl_info dlinfo;
#endif
// attempt to load the pre-compiled sysimage from jl_sysimg_handle
// if this succeeds, sysimg_gvars will be a valid array
// otherwise, it will be NULL
if (jl_sysimg_handle == 0) {
sysimg_gvars = 0;
return;
}
if (jl_sysimg_handle == 0)
return -1;

int imaging_mode = jl_options.build_path != NULL;
int imaging_mode = jl_generating_output();
#ifdef _OS_WINDOWS_
//XXX: the windows linker forces our system image to be
// linked against only one dll, I picked libjulia-release
Expand Down Expand Up @@ -261,7 +257,9 @@ static void jl_load_sysimg_so()
if (sysimg_data) {
size_t len = *(size_t*)jl_dlsym(jl_sysimg_handle, "jl_system_image_size");
jl_restore_system_image_data(sysimg_data, len);
return 0;
}
return -1;
}

static jl_value_t *jl_deserialize_gv(ios_t *s, jl_value_t *v)
Expand Down Expand Up @@ -1503,8 +1501,11 @@ DLLEXPORT void jl_preload_sysimg_so(const char *fname)
char *fname_shlib = (char*)alloca(strlen(fname)+1);
strcpy(fname_shlib, fname);
char *fname_shlib_dot = strrchr(fname_shlib, '.');
if (fname_shlib_dot != NULL)
if (fname_shlib_dot != NULL) {
if (!strcmp(fname_shlib_dot, ".ji"))
return; // .ji extension => load .ji file only
*fname_shlib_dot = 0;
}

// Get handle to sys.so
#ifdef _OS_WINDOWS_
Expand Down Expand Up @@ -1603,19 +1604,21 @@ DLLEXPORT void jl_restore_system_image(const char *fname)
char *dot = (char*) strrchr(fname, '.');
int is_ji = (dot && !strcmp(dot, ".ji"));

jl_load_sysimg_so();
if (!is_ji) {
if (sysimg_gvars == 0)
jl_errorf("System image file \"%s\" not found\n", fname);
return;
int err = jl_load_sysimg_so();
if (err != 0) {
if (jl_sysimg_handle == 0)
jl_errorf("System image file \"%s\" not found\n", fname);
jl_errorf("Library \"%s\" does not contain a valid system image\n", fname);
}
}

ios_t f;
if (ios_file(&f, fname, 1, 0, 0, 0) == NULL) {
jl_errorf("System image file \"%s\" not found\n", fname);
else {
ios_t f;
if (ios_file(&f, fname, 1, 0, 0, 0) == NULL)
jl_errorf("System image file \"%s\" not found\n", fname);
jl_restore_system_image_from_stream(&f);
ios_close(&f);
}
jl_restore_system_image_from_stream(&f);
ios_close(&f);
}

DLLEXPORT void jl_restore_system_image_data(const char *buf, size_t len)
Expand Down
Loading

0 comments on commit a703799

Please sign in to comment.