Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple cross compile mechanism for flisp/libsupport (+ dependencies) #30526

Merged
merged 5 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add simple cross compile mechanism for flisp/libsupport
This makes some incremental progress towards #30338 in the build system.
In particular, it allows compiling a separate boostrap version of flisp
and its dependencies for an architecture different from the target.
The immediate use case here is to build libjulia for wasm. Of course,
there's still the enormous problem of building the system image itself,
but luckily wasm is largely memory-layout-identical to linux32, so doing
that limited bootstrap is fairly easy after this change (though the subject
of a different PR).

The mechanism here is to use the out-of-tree build support to create
separate host/ subdirectories for the build directories of interest.
These have a special make variable set that tell it to include a
different Make.user (or in the absence thereof use the host defaults).
  • Loading branch information
Keno committed Jul 1, 2019
commit e3150956c732ef3bd28af1c06fba6477e3a5cc8b
22 changes: 14 additions & 8 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,17 @@ endif

# we include twice to pickup user definitions better
# include from JULIAHOME first so that BUILDROOT can override
ifeq (exists, $(shell [ -e $(JULIAHOME)/Make.user ] && echo exists ))
include $(JULIAHOME)/Make.user
ifneq ($(BUILDING_HOST_TOOLS),1)
MAKE_USER_FNAME = Make.user
else
MAKE_USER_FNAME = Make.host.user
endif

ifeq (exists, $(shell [ -e $(JULIAHOME)/$(MAKE_USER_FNAME) ] && echo exists ))
include $(JULIAHOME)/$(MAKE_USER_FNAME)
endif
ifeq (exists, $(shell [ -e $(BUILDROOT)/Make.user ] && echo exists ))
include $(BUILDROOT)/Make.user
ifeq (exists, $(shell [ -e $(BUILDROOT)/$(MAKE_USER_FNAME) ] && echo exists ))
include $(BUILDROOT)/$(MAKE_USER_FNAME)
endif

# disable automatic Makefile rules
Expand Down Expand Up @@ -571,11 +577,11 @@ else
LOCALBASE ?= /usr
endif

ifeq (exists, $(shell [ -e $(JULIAHOME)/Make.user ] && echo exists ))
include $(JULIAHOME)/Make.user
ifeq (exists, $(shell [ -e $(JULIAHOME)/$(MAKE_USER_FNAME) ] && echo exists ))
include $(JULIAHOME)/$(MAKE_USER_FNAME)
endif
ifeq (exists, $(shell [ -e $(BUILDROOT)/Make.user ] && echo exists ))
include $(BUILDROOT)/Make.user
ifeq (exists, $(shell [ -e $(BUILDROOT)/$(MAKE_USER_FNAME) ] && echo exists ))
include $(BUILDROOT)/$(MAKE_USER_FNAME)
endif

# A bit of a kludge to work around libraries linking to FreeBSD's outdated system libgcc_s
Expand Down
2 changes: 1 addition & 1 deletion 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/clangsa ui doc deps stdlib test test/embedding test/llvmpasses)
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src src/flisp src/support src/clangsa ui doc deps stdlib test test/embedding test/llvmpasses)
BUILDDIRMAKE := $(addsuffix /Makefile,$(BUILDDIRS)) $(BUILDROOT)/sysimage.mk
DIRS := $(DIRS) $(BUILDDIRS)
$(BUILDDIRMAKE): | $(BUILDDIRS)
Expand Down
2 changes: 2 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
/libjulia-release.so
/libjulia-release.dylib
/julia_version.h
/flisp/host
/support/host
15 changes: 12 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,13 @@ SHIPFLAGS += $(FLAGS)
SHIPFLAGS += "-DJL_SYSTEM_IMAGE_PATH=\"$(build_private_libdir_rel)/sys.$(SHLIB_EXT)\""
DEBUGFLAGS += "-DJL_SYSTEM_IMAGE_PATH=\"$(build_private_libdir_rel)/sys-debug.$(SHLIB_EXT)\""

FLISP_EXECUTABLE_debug := $(BUILDDIR)/flisp/flisp-debug$(EXE)
FLISP_EXECUTABLE_release := $(BUILDDIR)/flisp/flisp$(EXE)
ifeq ($(USE_CROSS_FLISP), 1)
FLISPDIR := $(BUILDDIR)/flisp/host
else
FLISPDIR := $(BUILDDIR)/flisp
endif
FLISP_EXECUTABLE_debug := $(FLISPDIR)/flisp-debug$(EXE)
FLISP_EXECUTABLE_release := $(FLISPDIR)/flisp$(EXE)
ifeq ($(OS),WINNT)
FLISP_EXECUTABLE := $(FLISP_EXECUTABLE_release)
else
Expand Down Expand Up @@ -232,10 +237,14 @@ $(BUILDDIR)/support/libsupport-debug.a: $(addprefix $(SRCDIR)/support/,*.h *.c *
$(MAKE) -C $(SRCDIR)/support debug BUILDDIR='$(abspath $(BUILDDIR)/support)'

$(FLISP_EXECUTABLE_release): $(BUILDDIR)/flisp/libflisp.a
$(MAKE) -C $(BUILDDIR)/flisp $(subst $(abspath $(BUILDDIR)/flisp)/,,$(abspath $(FLISP_EXECUTABLE_release)))

$(FLISP_EXECUTABLE_debug): $(BUILDDIR)/flisp/libflisp-debug.a
$(MAKE) -C $(BUILDDIR)/flisp $(subst $(abspath $(BUILDDIR)/flisp)/,,$(abspath $(FLISP_EXECUTABLE_debug)))

$(BUILDDIR)/flisp/libflisp.a: $(addprefix $(SRCDIR)/flisp/,*.h *.c) $(BUILDDIR)/support/libsupport.a
$(MAKE) -C $(SRCDIR)/flisp BUILDDIR='$(abspath $(BUILDDIR)/flisp)'

$(FLISP_EXECUTABLE_debug): $(BUILDDIR)/flisp/libflisp-debug.a
$(BUILDDIR)/flisp/libflisp-debug.a: $(addprefix $(SRCDIR)/,flisp/*.h flisp/*.c) $(BUILDDIR)/support/libsupport-debug.a
$(MAKE) -C $(SRCDIR)/flisp debug BUILDDIR='$(abspath $(BUILDDIR)/flisp)'

Expand Down
56 changes: 40 additions & 16 deletions src/flisp/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
JULIAHOME := $(abspath ../..)
SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
JULIAHOME := $(abspath $(SRCDIR)/../..)
BUILDDIR := .
include $(JULIAHOME)/Make.inc

Expand All @@ -15,21 +16,30 @@ SRCS := flisp.c builtins.c string.c equalhash.c table.c iostream.c \
julia_extensions.c

LLTDIR := ../support
LLTSRCDIR := $(SRCDIR)/$(LLTDIR)
NATIVE_BUILDDIR :=
ifeq ($(BUILDING_HOST_TOOLS), 1)
NATIVE_BUILDDIR := $(BUILDDIR)/..
LLT_BUILDDIR := $(BUILDDIR)/../$(LLTDIR)/host
else
NATIVE_BUILDDIR := $(BUILDDIR)
LLT_BUILDDIR := $(BUILDDIR)/$(LLTDIR)
endif

HEADERS := $(wildcard *.h) $(LIBUV_INC)/uv.h $(wildcard $(LLTDIR)/*.h)

OBJS := $(SRCS:%.c=$(BUILDDIR)/%.o)
DOBJS := $(SRCS:%.c=$(BUILDDIR)/%.dbg.obj)
LLT_release := $(BUILDDIR)/$(LLTDIR)/libsupport.a
LLT_debug := $(BUILDDIR)/$(LLTDIR)/libsupport-debug.a
LLT_release := $(LLT_BUILDDIR)/libsupport.a
LLT_debug := $(LLT_BUILDDIR)/libsupport-debug.a
LIBFILES_release := $(LLT_release) $(LIBUV) $(LIBUTF8PROC)
LIBFILES_debug := $(LLT_debug) $(LIBUV) $(LIBUTF8PROC)
LIBS :=
ifneq ($(OS),WINNT)
LIBS += -lpthread
endif

FLAGS := -I$(LLTDIR) $(JCFLAGS) $(HFILEDIRS:%=-I%) \
FLAGS := -I$(LLTSRCDIR) $(JCFLAGS) $(HFILEDIRS:%=-I%) \
-I$(LIBUV_INC) -I$(UTF8PROC_INC) -I$(build_includedir) $(LIBDIRS:%=-L%) \
-DLIBRARY_EXPORTS -DUTF8PROC_EXPORTS
ifneq ($(USEMSVC), 1)
Expand All @@ -52,20 +62,22 @@ debug: $(BUILDDIR)/$(EXENAME)-debug$(EXE)
$(BUILDDIR):
mkdir -p $(BUILDDIR)

$(BUILDDIR)/%.o: %.c $(HEADERS) | $(BUILDDIR)
$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) | $(BUILDDIR)
@$(call PRINT_CC, $(CC) $(JCPPFLAGS) $(SHIPFLAGS) $(DISABLE_ASSERTIONS) -c $< -o $@)
$(BUILDDIR)/%.dbg.obj: %.c $(HEADERS) | $(BUILDDIR)
$(BUILDDIR)/%.dbg.obj: $(SRCDIR)/%.c $(HEADERS) | $(BUILDDIR)
@$(call PRINT_CC, $(CC) $(JCPPFLAGS) $(DEBUGFLAGS) -c $< -o $@)

$(BUILDDIR)/flisp.o: flisp.c cvalues.c types.c flisp.h print.c read.c equal.c
$(BUILDDIR)/flisp.dbg.obj: flisp.c cvalues.c types.c flisp.h print.c read.c equal.c
$(BUILDDIR)/flmain.o: flmain.c flisp.h
$(BUILDDIR)/flmain.dbg.obj: flmain.c flisp.h
FLISP_SRCS := $(flisp.c cvalues.c types.c flisp.h print.c read.c equal.c:%=$(SRCDIR)/%)
FLMAIN_SRCS := $(flmain.c flisp.h:%=$(SRCDIR)/%)
$(BUILDDIR)/flisp.o: $(FLISP_SRCS)
$(BUILDDIR)/flisp.dbg.obj: $(FLISP_SRCS)
$(BUILDDIR)/flmain.o: $(FLMAIN_SRCS)
$(BUILDDIR)/flmain.dbg.obj: $(FLMAIN_SRCS)

$(LLT_release): $(LLTDIR)/*.h $(LLTDIR)/*.c
$(MAKE) -C $(LLTDIR) BUILDDIR='$(abspath $(BUILDDIR)/$(LLTDIR))'
$(LLT_debug): $(LLTDIR)/*.h $(LLTDIR)/*.c
$(MAKE) debug -C $(LLTDIR) BUILDDIR='$(abspath $(BUILDDIR)/$(LLTDIR))'
$(LLT_release): $(LLTSRCDIR)/*.h $(LLTSRCDIR)/*.c
$(MAKE) -C $(NATIVE_BUILDDIR)/$(LLTDIR) $(subst $(abspath $(NATIVE_BUILDDIR)/$(LLTDIR))/,,$(abspath $(LLT_release)))
$(LLT_debug): $(LLTSRCDIR)/*.h $(LLTSRCDIR)/*.c
$(MAKE) -C $(NATIVE_BUILDDIR)/$(LLTDIR) $(subst $(abspath $(NATIVE_BUILDDIR)/$(LLTDIR))/,,$(abspath $(LLT_debug)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn’t this slightly conflicted? The directory seems to be for native, but the subst looks for a slightly different prefix? Maybe we should add the abspath rule to the LLT Makefile, so we can remove the subst from here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's much to be gained. Keeping the targets appropriately relative seems simplest to me. This just turns the absolute path back into a relative path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, just seemed like it wasn't relative to anything obviously meaningful

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's just "relative" to the LLT build dir, which seems reasonably meaningful.


$(BUILDDIR)/$(LIBTARGET)-debug.a: $(DOBJS) | $(BUILDDIR)
rm -rf $@
Expand All @@ -87,8 +99,19 @@ $(BUILDDIR)/$(EXENAME)-debug$(EXE): $(DOBJS) $(LIBFILES_debug) $(BUILDDIR)/$(LIB
$(BUILDDIR)/$(EXENAME)$(EXE): $(OBJS) $(LIBFILES_release) $(BUILDDIR)/$(LIBTARGET).a $(BUILDDIR)/flmain.o | $(BUILDDIR)/flisp.boot
@$(call PRINT_LINK, $(CCLD) $(SHIPFLAGS) $(JLDFLAGS) $(OBJS) $(BUILDDIR)/flmain.o -o $@ $(BUILDDIR)/$(LIBTARGET).a $(LIBFILES_release) $(LIBS) $(OSLIBS))

ifneq ($(BUILDDIR),.)
$(BUILDDIR)/flisp.boot: flisp.boot | $(BUILDDIR)
$(BUILDDIR)/host/Makefile:
mkdir -p $(BUILDDIR)/host
@# add Makefiles to the build directories for convenience (pointing back to the source location of each)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the right file source in the comment. Is it worth trying to use the existing code to do this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing the comment. I don't think it's worth trying to deduplicate, esp since this adds a couple extra lines.

@echo '# -- This file is automatically generated in julia/Makefile -- #' > $@
@echo 'BUILDDIR=$(BUILDDIR)/host' >> $@
@echo 'BUILDING_HOST_TOOLS=1' >> $@
@echo 'include $(SRCDIR)/Makefile' >> $@

$(BUILDDIR)/host/$(EXENAME): $(BUILDDIR)/host/Makefile
make -C $(BUILDDIR)/host $(EXENAME)

ifneq ($(BUILDDIR)$(BUILDING_HOST_TOOLS),.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this change may have introdced a minor build error?

make[2]: Circular /data/vtjnash/julia/src/flisp/flisp.boot <- /data/vtjnash/julia/src/flisp/flisp.boot dependency dropped.

$(BUILDDIR)/flisp.boot: $(SRCDIR)/flisp.boot | $(BUILDDIR)
cp $< $@
endif

Expand All @@ -103,5 +126,6 @@ clean:
rm -f $(BUILDDIR)/*.a
rm -f $(BUILDDIR)/$(EXENAME)$(EXE)
rm -f $(BUILDDIR)/$(EXENAME)-debug$(EXE)
rm -f $(BUILDDIR)/host/*

.PHONY: flisp-deps
30 changes: 23 additions & 7 deletions src/support/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
JULIAHOME := $(abspath ../..)
SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
JULIAHOME := $(abspath $(SRCDIR)/../..)
BUILDDIR := .
include $(JULIAHOME)/Make.inc

Expand Down Expand Up @@ -40,24 +41,32 @@ default: release
$(BUILDDIR):
mkdir -p $(BUILDDIR)

$(BUILDDIR)/%.o: %.c $(HEADERS) | $(BUILDDIR)
$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) | $(BUILDDIR)
@$(call PRINT_CC, $(CC) $(JCPPFLAGS) $(JCFLAGS) $(SHIPFLAGS) $(DISABLE_ASSERTIONS) -c $< -o $@)
$(BUILDDIR)/%.dbg.obj: %.c $(HEADERS) | $(BUILDDIR)
$(BUILDDIR)/%.dbg.obj: $(SRCDIR)/%.c $(HEADERS) | $(BUILDDIR)
@$(call PRINT_CC, $(CC) $(JCPPFLAGS) $(JCFLAGS) $(DEBUGFLAGS) -c $< -o $@)
ifneq ($(USEMSVC), 1)
$(BUILDDIR)/%.o: %.S | $(BUILDDIR)
$(BUILDDIR)/%.o: $(SRCDIR)/%.S | $(BUILDDIR)
@$(call PRINT_CC, $(CC) $(JCPPFLAGS) $(SHIPFLAGS) -c $< -o $@)
$(BUILDDIR)/%.dbg.obj: %.S | $(BUILDDIR)
$(BUILDDIR)/%.dbg.obj: $(SRCDIR)/%.S | $(BUILDDIR)
@$(call PRINT_CC, $(CC) $(JCPPFLAGS) $(DEBUGFLAGS) -c $< -o $@)
else
$(BUILDDIR)/%.o: %.S | $(BUILDDIR)
$(BUILDDIR)/%.o: $(SRCDIR)/%.S | $(BUILDDIR)
@$(call PRINT_CC, $(CPP) -P $(JCPPFLAGS) $(SHIPFLAGS) $<)
@$(call PRINT_CC, $(AS) $(JCPPFLAGS) $(SHIPFLAGS) -Fo $@ -c $*.i)
$(BUILDDIR)/%.dbg.obj: %.S | $(BUILDDIR)
$(BUILDDIR)/%.dbg.obj: $(SRCDIR)/%.S | $(BUILDDIR)
@$(call PRINT_CC, $(CPP) -P $(JCPPFLAGS) $(DEBUGFLAGS) $<)
@$(call PRINT_CC, $(AS) $(JCPPFLAGS) $(DEBUGFLAGS) -Fo $@ -c $*.i)
endif

$(BUILDDIR)/host/Makefile:
mkdir -p $(BUILDDIR)/host
@# add Makefiles to the build directories for convenience (pointing back to the source location of each)
@echo '# -- This file is automatically generated in julia/Makefile -- #' > $@
@echo 'BUILDDIR=$(BUILDDIR)/host' >> $@
@echo 'BUILDING_HOST_TOOLS=1' >> $@
@echo 'include $(SRCDIR)/Makefile' >> $@

release: $(BUILDDIR)/libsupport.a
debug: $(BUILDDIR)/libsupport-debug.a

Expand All @@ -69,6 +78,12 @@ $(BUILDDIR)/libsupport-debug.a: $(DOBJS) | $(BUILDDIR)
rm -rf $@
@$(call PRINT_LINK, $(AR) -rcs $@ $^)

$(BUILDDIR)/host/libsupport.a: $(BUILDDIR)/host/Makefile
$(MAKE) -C $(BUILDDIR)/host libsupport.a

$(BUILDDIR)/host/libsupport-debug.a: $(BUILDDIR)/host/Makefile
$(MAKE) -C $(BUILDDIR)/host libsupport.a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-debug


clean:
rm -f $(BUILDDIR)/*.o
rm -f $(BUILDDIR)/*.dbg.obj
Expand All @@ -77,3 +92,4 @@ clean:
rm -f $(BUILDDIR)/core*
rm -f $(BUILDDIR)/libsupport.a
rm -f $(BUILDDIR)/libsupport-debug.a
rm -f $(BUILDDIR)/host/*