Skip to content

Commit 336cdf8

Browse files
authored
[build] Add symlink_system_library calls for CSL (#40217)
* [build] Add `symlink_system_library` calls for CSL We differentiate between a `USE_BINARYBUILDER_CSL=0` configuration (where we copy the CSL libraries into the Julia build tree) versus a `USE_SYSTEM_CSL=1` configuration (where we symlink them in a manner similar to other system libararies) * Expand `JL_PRIVATE_LIBS-1` for versioned library names as well Without this, we fail to install things like `libgcc_s.so.1` when installed into the private libdir by `symlink_system_libraries`.
1 parent 54b610b commit 336cdf8

File tree

4 files changed

+92
-66
lines changed

4 files changed

+92
-66
lines changed

Make.inc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,21 @@ else
596596
SHLIB_EXT := so
597597
endif
598598

599+
ifeq ($(OS),WINNT)
600+
define versioned_libname
601+
$$(if $(2),$(1)-$(2).$(SHLIB_EXT),$(1).$(SHLIB_EXT))
602+
endef
603+
else ifeq ($(OS),Darwin)
604+
define versioned_libname
605+
$$(if $(2),$(1).$(2).$(SHLIB_EXT),$(1).$(SHLIB_EXT))
606+
endef
607+
else
608+
define versioned_libname
609+
$$(if $(2),$(1).$(SHLIB_EXT).$(2),$(1).$(SHLIB_EXT))
610+
endef
611+
endif
612+
613+
599614
ifeq ($(SHLIB_EXT), so)
600615
define SONAME_FLAGS
601616
-Wl,-soname=$1
@@ -1148,6 +1163,8 @@ BB_TRIPLET_LIBGFORTRAN := $(subst $(SPACE),-,$(filter-out cxx%,$(subst -,$(SPACE
11481163
BB_TRIPLET_CXXABI := $(subst $(SPACE),-,$(filter-out libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI))))
11491164
BB_TRIPLET := $(subst $(SPACE),-,$(filter-out cxx%,$(filter-out libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI)))))
11501165

1166+
LIBGFORTRAN_VERSION := $(subst libgfortran,,$(filter libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN))))
1167+
11511168
# This is the set of projects that BinaryBuilder dependencies are hooked up for.
11521169
BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM SUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP CSL
11531170
define SET_BB_DEFAULT
@@ -1480,8 +1497,12 @@ ifneq ($(findstring $(OS),Linux FreeBSD),)
14801497
LIBGCC_NAME := libgcc_s.$(SHLIB_EXT).1
14811498
endif
14821499

1483-
1500+
# USE_SYSTEM_CSL causes it to get symlinked into build_private_shlibdir
1501+
ifeq ($(USE_SYSTEM_CSL),1)
1502+
LIBGCC_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_private_shlibdir)/$(LIBGCC_NAME))
1503+
else
14841504
LIBGCC_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_shlibdir)/$(LIBGCC_NAME))
1505+
endif
14851506
LIBGCC_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlibdir)/$(LIBGCC_NAME))
14861507

14871508
# USE_SYSTEM_LIBM and USE_SYSTEM_OPENLIBM causes it to get symlinked into build_private_shlibdir

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,11 @@ endif
290290
done \
291291
done
292292
for suffix in $(JL_PRIVATE_LIBS-1) ; do \
293-
lib=$(build_private_libdir)/$${suffix}.$(SHLIB_EXT); \
294-
$(INSTALL_M) $$lib $(DESTDIR)$(private_libdir) ; \
293+
for lib in $(build_private_libdir)/$${suffix}.$(SHLIB_EXT)*; do \
294+
if [ "$${lib##*.}" != "dSYM" ]; then \
295+
$(INSTALL_M) $$lib $(DESTDIR)$(private_libdir) ; \
296+
fi \
297+
done \
295298
done
296299
endif
297300
# Install `7z` into libexec/

base/Makefile

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -169,53 +169,69 @@ endif
169169
# echo "$$P"
170170

171171
define symlink_system_library
172-
symlink_$1: $$(build_private_libdir)/$1.$$(SHLIB_EXT)
173-
$$(build_private_libdir)/$1.$$(SHLIB_EXT):
174-
REALPATH=`$$(call spawn,$$(build_depsbindir)/libwhich) -p $$(notdir $$@)` && \
175-
$$(call resolve_path,REALPATH) && \
176-
[ -e "$$$$REALPATH" ] && \
177-
([ ! -e "$$@" ] || rm "$$@") && \
178-
echo ln -sf "$$$$REALPATH" "$$@" && \
179-
ln -sf "$$$$REALPATH" "$$@"
180-
ifneq ($2,)
181-
ifneq ($$(USE_SYSTEM_$2),0)
182-
SYMLINK_SYSTEM_LIBRARIES += symlink_$1
183-
endif
172+
libname_$2 := $$(notdir $(call versioned_libname,$2,$3))
173+
libpath_$2 := $$(shell $$(call spawn,$$(build_depsbindir)/libwhich) -p $$(libname_$2) 2>/dev/null)
174+
symlink_$2: $$(build_private_libdir)/$$(libname_$2)
175+
$$(build_private_libdir)/$$(libname_$2):
176+
@if [ -e "$$(libpath_$2)" ]; then \
177+
REALPATH=$$(libpath_$2); \
178+
$$(call resolve_path,REALPATH) && \
179+
[ -e "$$$$REALPATH" ] && \
180+
([ ! -e "$$@" ] || rm "$$@") && \
181+
echo ln -sf "$$$$REALPATH" "$$@" && \
182+
ln -sf "$$$$REALPATH" "$$@"; \
183+
else \
184+
if [ "$4" != "ALLOW_FAILURE" ]; then \
185+
echo "System library symlink failure: Unable to locate $$(libname_$2) on your system!" >&2; \
186+
false; \
187+
fi; \
188+
fi
189+
ifneq ($$(USE_SYSTEM_$1),0)
190+
SYMLINK_SYSTEM_LIBRARIES += symlink_$2
184191
endif
185192
endef
186193

187194
# the following excludes: libuv.a, libutf8proc.a
188195

189-
$(eval $(call symlink_system_library,$(LIBMNAME)))
190196
ifneq ($(USE_SYSTEM_LIBM),0)
191-
SYMLINK_SYSTEM_LIBRARIES += symlink_$(LIBMNAME)
197+
$(eval $(call symlink_system_library,LIBM,$(LIBMNAME)))
192198
else ifneq ($(USE_SYSTEM_OPENLIBM),0)
193-
SYMLINK_SYSTEM_LIBRARIES += symlink_$(LIBMNAME)
199+
$(eval $(call symlink_system_library,OPENLIBM,$(LIBMNAME)))
194200
endif
195201

196-
$(eval $(call symlink_system_library,libpcre2-8,PCRE))
197-
$(eval $(call symlink_system_library,libdSFMT,DSFMT))
198-
$(eval $(call symlink_system_library,$(LIBBLASNAME),BLAS))
202+
$(eval $(call symlink_system_library,CSL,libgcc_s,1))
203+
ifneq (,$(LIBGFORTRAN_VERSION))
204+
$(eval $(call symlink_system_library,CSL,libgfortran,$(LIBGFORTRAN_VERSION)))
205+
endif
206+
$(eval $(call symlink_system_library,CSL,libquadmath,0))
207+
$(eval $(call symlink_system_library,CSL,libstdc++,6))
208+
# We allow libssp, libatomic and libgomp to fail as they are not available on all systems
209+
$(eval $(call symlink_system_library,CSL,libssp,0,ALLOW_FAILURE))
210+
$(eval $(call symlink_system_library,CSL,libatomic,1,ALLOW_FAILURE))
211+
$(eval $(call symlink_system_library,CSL,libgomp,1,ALLOW_FAILURE))
212+
$(eval $(call symlink_system_library,PCRE,libpcre2-8))
213+
$(eval $(call symlink_system_library,DSFMT,libdSFMT))
214+
$(eval $(call symlink_system_library,BLAS,$(LIBBLASNAME)))
199215
ifneq ($(LIBLAPACKNAME),$(LIBBLASNAME))
200-
$(eval $(call symlink_system_library,$(LIBLAPACKNAME),LAPACK))
216+
$(eval $(call symlink_system_library,LAPACK,$(LIBLAPACKNAME)))
201217
endif
202-
$(eval $(call symlink_system_library,libgmp,GMP))
203-
$(eval $(call symlink_system_library,libmpfr,MPFR))
204-
$(eval $(call symlink_system_library,libmbedtls,MBEDTLS))
205-
$(eval $(call symlink_system_library,libmbedcrypto,MBEDTLS))
206-
$(eval $(call symlink_system_library,libmbedx509,MBEDTLS))
207-
$(eval $(call symlink_system_library,libssh2,LIBSSH2))
208-
$(eval $(call symlink_system_library,libnghttp2,NGHTTP2))
209-
$(eval $(call symlink_system_library,libcurl,CURL))
210-
$(eval $(call symlink_system_library,libgit2,LIBGIT2))
211-
$(eval $(call symlink_system_library,libamd,SUITESPARSE))
212-
$(eval $(call symlink_system_library,libcamd,SUITESPARSE))
213-
$(eval $(call symlink_system_library,libccolamd,SUITESPARSE))
214-
$(eval $(call symlink_system_library,libcholmod,SUITESPARSE))
215-
$(eval $(call symlink_system_library,libcolamd,SUITESPARSE))
216-
$(eval $(call symlink_system_library,libumfpack,SUITESPARSE))
217-
$(eval $(call symlink_system_library,libspqr,SUITESPARSE))
218-
$(eval $(call symlink_system_library,libsuitesparseconfig,SUITESPARSE))
218+
$(eval $(call symlink_system_library,GMP,libgmp))
219+
$(eval $(call symlink_system_library,MPFR,libmpfr))
220+
$(eval $(call symlink_system_library,MBEDTLS,libmbedtls))
221+
$(eval $(call symlink_system_library,MBEDTLS,libmbedcrypto))
222+
$(eval $(call symlink_system_library,MBEDTLS,libmbedx509))
223+
$(eval $(call symlink_system_library,LIBSSH2,libssh2))
224+
$(eval $(call symlink_system_library,NGHTTP2,libnghttp2))
225+
$(eval $(call symlink_system_library,CURL,libcurl))
226+
$(eval $(call symlink_system_library,LIBGIT2,libgit2))
227+
$(eval $(call symlink_system_library,SUITESPARSE,libamd))
228+
$(eval $(call symlink_system_library,SUITESPARSE,libcamd))
229+
$(eval $(call symlink_system_library,SUITESPARSE,libccolamd))
230+
$(eval $(call symlink_system_library,SUITESPARSE,libcholmod))
231+
$(eval $(call symlink_system_library,SUITESPARSE,libcolamd))
232+
$(eval $(call symlink_system_library,SUITESPARSE,libumfpack))
233+
$(eval $(call symlink_system_library,SUITESPARSE,libspqr))
234+
$(eval $(call symlink_system_library,SUITESPARSE,libsuitesparseconfig))
219235
# EXCLUDED LIBRARIES (installed/used, but not vendored for use with dlopen):
220236
# libunwind
221237
endif # WINNT

deps/csl.mk

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,34 @@ $$(build_shlibdir)/$(1): | $$(build_shlibdir)
1919
[ -n "$$$${SRC_LIB}" ] && cp $$$${SRC_LIB} $$(build_shlibdir)
2020
endef
2121

22-
ifeq ($(OS),WINNT)
23-
define gen_libname
24-
$$(if $(2),lib$(1)-$(2).$(SHLIB_EXT),lib$(1).$(SHLIB_EXT))
25-
endef
26-
else ifeq ($(OS),Darwin)
27-
define gen_libname
28-
$$(if $(2),lib$(1).$(2).$(SHLIB_EXT),lib$(1).$(SHLIB_EXT))
29-
endef
30-
else
31-
define gen_libname
32-
$$(if $(2),lib$(1).$(SHLIB_EXT).$(2),lib$(1).$(SHLIB_EXT))
33-
endef
34-
endif
35-
3622
# libgfortran has multiple names; we're just going to copy any version we can find
3723
# Since we're only looking in the location given by `$(FC)` this should only succeed for one.
38-
$(eval $(call copy_csl,$(call gen_libname,gfortran,3)))
39-
$(eval $(call copy_csl,$(call gen_libname,gfortran,4)))
40-
$(eval $(call copy_csl,$(call gen_libname,gfortran,5)))
24+
$(eval $(call copy_csl,$(call versioned_libname,libgfortran,3)))
25+
$(eval $(call copy_csl,$(call versioned_libname,libgfortran,4)))
26+
$(eval $(call copy_csl,$(call versioned_libname,libgfortran,5)))
4127

4228
# These are all libraries that we should always have
43-
$(eval $(call copy_csl,$(call gen_libname,quadmath,0)))
44-
$(eval $(call copy_csl,$(call gen_libname,stdc++,6)))
45-
$(eval $(call copy_csl,$(call gen_libname,ssp,0)))
46-
$(eval $(call copy_csl,$(call gen_libname,atomic,1)))
47-
$(eval $(call copy_csl,$(call gen_libname,gomp,1)))
29+
$(eval $(call copy_csl,$(call versioned_libname,libquadmath,0)))
30+
$(eval $(call copy_csl,$(call versioned_libname,libstdc++,6)))
31+
$(eval $(call copy_csl,$(call versioned_libname,libssp,0)))
32+
$(eval $(call copy_csl,$(call versioned_libname,libatomic,1)))
33+
$(eval $(call copy_csl,$(call versioned_libname,libgomp,1)))
4834

4935
ifeq ($(OS),WINNT)
5036
# Windwos has special gcc_s names
5137
ifeq ($(ARCH),i686)
52-
$(eval $(call copy_csl,$(call gen_libname,gcc_s_sjlj,1)))
38+
$(eval $(call copy_csl,$(call versioned_libname,libgcc_s_sjlj,1)))
5339
else
54-
$(eval $(call copy_csl,$(call gen_libname,gcc_s_seh,1)))
40+
$(eval $(call copy_csl,$(call versioned_libname,libgcc_s_seh,1)))
5541
endif
5642
else
57-
$(eval $(call copy_csl,$(call gen_libname,gcc_s,1)))
43+
$(eval $(call copy_csl,$(call versioned_libname,libgcc_s,1)))
5844
endif
5945
# winpthread is only Windows, pthread is only others
6046
ifeq ($(OS),WINNT)
61-
$(eval $(call copy_csl,$(call gen_libname,winpthread,1)))
47+
$(eval $(call copy_csl,$(call versioned_libname,libwinpthread,1)))
6248
else
63-
$(eval $(call copy_csl,$(call gen_libname,pthread,0)))
49+
$(eval $(call copy_csl,$(call versioned_libname,libpthread,0)))
6450
endif
6551

6652
get-csl:

0 commit comments

Comments
 (0)