Skip to content

Commit 698ae27

Browse files
authored
Add CROSS_BOOTSTRAP_JULIA option for building the sysimg with another Julia (#59033)
Adds makefile variables called `CROSS_BOOTSTRAP_JULIA` and `CROSS_BOOTSTRAP_SYSBASE` that control the Julia executable and `sysbase.so` used to build `sys.so`. This is really useful for building a ThreadSanitizer-enabled version of Julia in a reasonable amount of time. It is used like this: ``` make O=bootstrap julia-src-release julia-sysbase-release make CROSS_BOOTSTRAP_JULIA=bootstrap/usr/bin/julia CROSS_BOOTSTRAP_SYSBASE=bootstrap/usr/lib/julia/sysbase.so julia-src-release julia-sysimg-release ``` This also adds a faster way to create a debug build of Julia (documented in the devdocs).
1 parent ca4981c commit 698ae27

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

Make.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@ ifneq ($(OS), Darwin)
798798
endif
799799
endif
800800

801+
bootstrap_julia_flags :=
802+
801803
ifeq ($(SANITIZE),1)
802804
SANITIZE_OPTS :=
803805
SANITIZE_LDFLAGS :=
@@ -815,6 +817,9 @@ endif
815817
ifeq ($(SANITIZE_THREAD),1)
816818
SANITIZE_OPTS += -fsanitize=thread
817819
SANITIZE_LDFLAGS += -fsanitize=thread
820+
ifneq ($(CROSS_BOOTSTRAP_JULIA),)
821+
bootstrap_julia_flags += --target-sanitize=thread
822+
endif
818823
endif
819824
ifeq ($(SANITIZE_OPTS),)
820825
$(error SANITIZE=1, but no sanitizer selected, set either SANITIZE_MEMORY, SANITIZE_THREAD, or SANITIZE_ADDRESS)
@@ -1761,9 +1766,15 @@ JULIA_BUILD_MODE := debug
17611766
endif
17621767
endif
17631768

1769+
ifneq ($(CROSS_BOOTSTRAP_JULIA),)
1770+
JULIA_EXECUTABLE_debug := $(CROSS_BOOTSTRAP_JULIA)
1771+
JULIA_EXECUTABLE_release := $(CROSS_BOOTSTRAP_JULIA)
1772+
JULIA_EXECUTABLE := $(CROSS_BOOTSTRAP_JULIA)
1773+
else
17641774
JULIA_EXECUTABLE_debug := $(build_bindir)/julia-debug$(EXE)
17651775
JULIA_EXECUTABLE_release := $(build_bindir)/julia$(EXE)
17661776
JULIA_EXECUTABLE := $(JULIA_EXECUTABLE_$(JULIA_BUILD_MODE))
1777+
endif
17671778

17681779
JULIA_SYSIMG_debug := $(build_private_libdir)/sys-debug.$(SHLIB_EXT)
17691780
JULIA_SYSIMG_release := $(build_private_libdir)/sys.$(SHLIB_EXT)

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ julia-cli-release julia-cli-debug: julia-cli-% : julia-deps
113113
julia-sysimg-release julia-sysimg-debug : julia-sysimg-% : julia-src-% $(TOP_LEVEL_PKG_LINK_TARGETS) julia-stdlib julia-base julia-cli-% | $(build_private_libdir)
114114
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) -f sysimage.mk sysimg-$*
115115

116+
# Useful for cross-bootstrapping
117+
julia-sysbase-release julia-sysbase-debug : julia-sysbase-% : julia-src-% $(TOP_LEVEL_PKG_LINK_TARGETS) julia-stdlib julia-base julia-cli-% | $(build_private_libdir)
118+
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) -f sysimage.mk sysbase-$*
119+
116120
julia-debug julia-release : julia-% : julia-sysimg-% julia-src-% julia-symlink julia-libccalltest \
117121
julia-libccalllazyfoo julia-libccalllazybar julia-libllvmcalltest julia-base-cache
118122

contrib/tsan/Make.user.tsan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ USE_BINARYBUILDER_LLVM=1
1010

1111
override SANITIZE=1
1212
override SANITIZE_THREAD=1
13+
override CROSS_BOOTSTRAP_JULIA=$(BUILDROOT)/../bootstrap/usr/bin/julia
14+
override CROSS_BOOTSTRAP_SYSBASE=$(BUILDROOT)/../bootstrap/usr/lib/julia/sysbase.$(SHLIB_EXT)

contrib/tsan/build.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#
55
# Usage:
6-
# contrib/tsan/build.sh <path> [<make_targets>...]
6+
# contrib/tsan/build.sh [-j<N>] <path> [<make_targets>...]
77
#
88
# Build TSAN-enabled julia. Given a workspace directory <path>, build
99
# TSAN-enabled julia in <path>/tsan. Required toolss are install under
@@ -13,6 +13,16 @@
1313
# make target is `debug`.
1414

1515
set -ue
16+
set -x
17+
18+
JOBS=1
19+
while getopts j: opt
20+
do
21+
case $opt in
22+
j) JOBS="$OPTARG";;
23+
esac
24+
done
25+
shift $((OPTIND-1))
1626

1727
# `$WORKSPACE` is a directory in which we create `toolchain` and `tsan`
1828
# sub-directories.
@@ -44,6 +54,12 @@ fi
4454

4555
make -C "$TOOLCHAIN/deps" install-clang install-llvm-tools
4656

57+
echo
58+
echo "Building bootstrap Julia..."
59+
BUILD="$WORKSPACE/bootstrap"
60+
61+
make -j "$JOBS" O="$BUILD" julia-src-release julia-sysbase-release
62+
4763
echo
4864
echo "Building Julia..."
4965

@@ -54,4 +70,6 @@ if [ ! -d "$BUILD" ]; then
5470
fi
5571

5672
cd "$BUILD" # so that we can pass `-C src` to `make`
57-
make "$@"
73+
# Reporting tsan warnings will interfere with bootstrapping.
74+
export TSAN_OPTIONS="report_bugs=0 exitcode=0"
75+
make -j "$JOBS" "$@"

doc/src/devdocs/build/build.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,20 @@ LLVM_ASSERTIONS=1
304304

305305
Please note that assert builds of Julia will be slower than regular (non-assert) builds.
306306

307+
## Building a debug build of Julia
308+
309+
A full debug build of Julia can be built with `make debug`. This builds a debug
310+
version of `libjulia` and uses it to bootstrap the compiler, before creating a
311+
system image with debug symbols enabled. This can take more than 15 minutes.
312+
313+
Although it may result in some differences, a debug build can be built much
314+
quicker by bootstrapping from a release build:
315+
316+
```sh
317+
$ make julia-src-release julia-sysbase-release
318+
$ make julia-sysimg-debug CROSS_BOOTSTRAP_JULIA=$PWD/usr/bin/julia CROSS_BOOTSTRAP_SYSBASE=$PWD/usr/lib/julia/sysbase.so
319+
```
320+
307321
## Building 32-bit Julia on a 64-bit machine
308322

309323
Occasionally, bugs specific to 32-bit architectures may arise, and when this happens it is useful to be able to debug the problem on your local machine. Since most modern 64-bit systems support running programs built for 32-bit ones, if you don't have to recompile Julia from source (e.g. you mainly need to inspect the behavior of a 32-bit Julia without having to touch the C code), you can likely use a 32-bit build of Julia for your system that you can obtain from the [official downloads page](https://julialang.org/downloads/).

sysimage.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ sysimg-ji: $(build_private_libdir)/sysbase.ji
1111
sysimg-bc: $(build_private_libdir)/sys-bc.a
1212
sysimg-release: $(build_private_libdir)/sys.$(SHLIB_EXT)
1313
sysimg-debug: $(build_private_libdir)/sys-debug.$(SHLIB_EXT)
14+
sysbase-release: $(build_private_libdir)/sysbase.$(SHLIB_EXT)
15+
sysbase-debug: $(build_private_libdir)/sysbase-debug.$(SHLIB_EXT)
1416

1517
VERSDIR := v$(shell cut -d. -f1-2 < $(JULIAHOME)/VERSION)
1618

@@ -124,7 +126,8 @@ $$(build_private_libdir)/sysbase$1-o.a $$(build_private_libdir)/sysbase$1-bc.a :
124126
false; \
125127
fi )
126128
@mv $$@.tmp $$@
127-
$$(build_private_libdir)/sys$1-o.a $$(build_private_libdir)/sys$1-bc.a : $$(build_private_libdir)/sys$1-%.a : $$(build_private_libdir)/sysbase$1.$$(SHLIB_EXT) $$(JULIAHOME)/contrib/generate_precompile.jl
129+
build_sysbase_$1 := $$(or $$(CROSS_BOOTSTRAP_SYSBASE),$$(build_private_libdir)/sysbase$1.$$(SHLIB_EXT))
130+
$$(build_private_libdir)/sys$1-o.a $$(build_private_libdir)/sys$1-bc.a : $$(build_private_libdir)/sys$1-%.a : $$(build_sysbase_$1) $$(JULIAHOME)/contrib/generate_precompile.jl
128131
@$$(call PRINT_JULIA, cd $$(JULIAHOME)/base && \
129132
if ! JULIA_BINDIR=$$(call cygpath_w,$(build_bindir)) \
130133
WINEPATH="$$(call cygpath_w,$$(build_bindir));$$$$WINEPATH" \
@@ -133,6 +136,7 @@ $$(build_private_libdir)/sys$1-o.a $$(build_private_libdir)/sys$1-bc.a : $$(buil
133136
JULIA_DEPOT_PATH=':' \
134137
JULIA_NUM_THREADS=1 \
135138
$$(call spawn, $3) $2 -C "$$(JULIA_CPU_TARGET)" $$(HEAPLIM) --output-$$* $$(call cygpath_w,$$@).tmp $$(JULIA_SYSIMG_BUILD_FLAGS) \
139+
$(bootstrap_julia_flags) \
136140
--startup-file=no --warn-overwrite=yes --depwarn=error --sysimage $$(call cygpath_w,$$<) $$(call cygpath_w,$$(JULIAHOME)/contrib/generate_precompile.jl) $(JULIA_PRECOMPILE); then \
137141
echo '*** This error is usually fixed by running `make clean`. If the error persists$$(COMMA) try `make cleanall`. ***'; \
138142
false; \

0 commit comments

Comments
 (0)