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

[libflame] Initial build scripts. #8671

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
89 changes: 89 additions & 0 deletions L/libflame/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name = "libflame"

using BinaryBuilder, Pkg

version = v"5.2.0"

# Collection of sources required to build lapack
sources = [
GitSource("https://github.com/flame/libflame",
"646ed9075cc45aeffb53632a3ec88defb423fefa"),
DirectorySource("bundled"),
]

# Bash recipe for building across all *64-bit* platforms
# We try to maintain consistency with the blis Yggdrasil build scripts.

script = raw"""
cd $WORKSPACE/srcdir/libflame

# We might need newer `config.guess`` and `config.sub` files
update_configure_scripts

extra_flags=" --disable-static-build "

if [[ "${target}" == *-apple-* ]]; then
extra_flags=" --enable-static-build "
atomic_patch -p1 ${WORKSPACE}/srcdir/patches/mac-update-makefile.patch
fi

if [[ "${target}" == *-w64-mingw32* ]]; then
extra_flags+=" --enable-windows-build "
# disable time & clock functions on windows (mingw): sys/times.h is missing
atomic_patch -p1 ${WORKSPACE}/srcdir/patches/windows-remove-time.patch
# update the make build scripts for windows cross-compiling with gcc:
atomic_patch -p1 ${WORKSPACE}/srcdir/patches/windows-update-build.patch
fi

if [[ "${target}" == *mingw* ]]; then
LBT="-L${libdir} -lblastrampoline-5"
else
LBT="-L${libdir} -lblastrampoline"
fi

# - Compile and build a LAPACK compatibility layer with --enable-lapack2flame
# - If a static library is not needed, use --disable-static-build
# - Enable a dynamic build with --enable-dynamic-build
./configure \
--prefix=${prefix} --build=${MACHTYPE} --host=${target} \
--enable-multithreading=openmp \
--enable-lapack2flame \
--enable-dynamic-build \
--enable-max-arg-list-hack \
--disable-autodetect-f77-ldflags --disable-autodetect-f77-name-mangling \
$extra_flags

make -j${nproc} BLAS_LIB="${LBT}"
make install

install_license LICENSE
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = supported_platforms()

filter!(p -> arch(p) != "i686", platforms)
filter!(p -> arch(p) != "armv7l", platforms)
filter!(p -> arch(p) != "armv6l", platforms)
filter!(p -> arch(p) != "powerpc64le", platforms)

# Enable the following line if trying to link against Fortran code:
# platforms = expand_gfortran_versions(platforms)

# Dependencies that must be installed before this package can be built
dependencies = [
Dependency(PackageSpec(name="libblastrampoline_jll", uuid="8e850b90-86db-534c-a0d3-1478176c7d93"), compat="5.8"),
# For OpenMP we use libomp from `LLVMOpenMP_jll` where we use LLVM as compiler (BSD
# systems), and libgomp from `CompilerSupportLibraries_jll` everywhere else.
Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae"); platforms=filter(!Sys.isbsd, platforms)),
Dependency(PackageSpec(name="LLVMOpenMP_jll", uuid="1d63c593-3942-5779-bab2-d838dc0a180e"); platforms=filter(Sys.isbsd, platforms)),
]

products = [
LibraryProduct("libflame", :libflame),
]

# Build the tarballs
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
preferred_gcc_version=v"11", lock_microarchitecture=false, julia_compat="1.6")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
preferred_gcc_version=v"11", lock_microarchitecture=false, julia_compat="1.6")
preferred_gcc_version=v"11", clang_use_lld=false, lock_microarchitecture=false, julia_compat="1.6")

Lets try not using LLD and instead using the other linker to see if these flags work then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mixed up the gcc ld -whole-archive vs. clang lld -force_load but didn't seem to like it anyway. Might need to try your approach.

Copy link
Member

Choose a reason for hiding this comment

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

Mixed up the gcc ld -whole-archive vs. clang lld -force_load

  1. this isn't gcc vs clang, but Linux vs macOS
  2. this is why we provide the flagon utility.

31 changes: 31 additions & 0 deletions L/libflame/bundled/patches/mac-update-makefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/Makefile b/Makefile
index c7a2b7f7..0c509288 100644
--- a/Makefile
+++ b/Makefile
@@ -140,7 +140,7 @@ LIBFLAME_SO_OUTPUT_NAME := $(LIBFLAME_SO_PATH)
ifeq ($(OS_NAME),Darwin)
# OS X shared library link flags.
SOFLAGS := -dynamiclib
-SOFLAGS += -Wl,-install_name,$(LIBFLAME_SONAME)
+SOFLAGS += -Wl,-install_name,@rpath/$(LIBFLAME_SONAME)
else
SOFLAGS := -shared
# Linux shared library link flags.
@@ -670,7 +670,7 @@ ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
$(SORT) $(AR_OBJ_LIST_FILE) | $(UNIQ) > $(AR_OBJ_LIST_FILE).sotmp
$(CAT) $(AR_OBJ_LIST_FILE).sotmp | xargs -n$(AR_CHUNK_SIZE) $(AR) $(ARFLAGS) $(LIBFLAME_A)
ifeq ($(OS_NAME),Darwin)
- $(LINKER) $(SOFLAGS) -o $@ -Wl,-force_load,$(LIBFLAME_A) $(LDFLAGS)
+ $(LINKER) $(SOFLAGS) -o $@ -Wl,-rpath,$(BASE_LIB_PATH):$(LIBFLAME_A_PATH) -Wl,-all_load $(LDFLAGS)
else
$(LINKER) $(SOFLAGS) -o $@ -Wl,--whole-archive $(LIBFLAME_A) -Wl,--no-whole-archive $(LDFLAGS)
endif
@@ -686,7 +686,7 @@ ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
@$(SORT) $(AR_OBJ_LIST_FILE) | $(UNIQ) > $(AR_OBJ_LIST_FILE).sotmp
@$(CAT) $(AR_OBJ_LIST_FILE).sotmp | xargs -n$(AR_CHUNK_SIZE) $(AR) $(ARFLAGS) $(LIBFLAME_A)
ifeq ($(OS_NAME),Darwin)
- @$(LINKER) $(SOFLAGS) -o $@ -Wl,-force_load,$(LIBFLAME_A) $(LDFLAGS)
+ $(LINKER) $(SOFLAGS) -o $@ -Wl,-rpath,$(BASE_LIB_PATH):$(LIBFLAME_A_PATH) -Wl,-all_load $(LDFLAGS)
else
@$(LINKER) $(SOFLAGS) -o $@ -Wl,--whole-archive $(LIBFLAME_A) -Wl,--no-whole-archive $(LDFLAGS)
endif
196 changes: 196 additions & 0 deletions L/libflame/bundled/patches/windows-remove-time.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
diff --git a/src/map/common/lapacksrc/install/static/dsecnd.c b/src/map/common/lapacksrc/install/static/dsecnd.c
index 2711ccee..89626f23 100644
--- a/src/map/common/lapacksrc/install/static/dsecnd.c
+++ b/src/map/common/lapacksrc/install/static/dsecnd.c
@@ -1,5 +1,5 @@
#include "FLA_f2c.h"
-#include <sys/times.h>
+// #include <sys/times.h>
//#include <sys/types.h>
//#include <time.h>

@@ -7,11 +7,11 @@
#define CLK_TCK 60
#endif

-doublereal dsecnd_( void )
-{
- struct tms rusage;
+// doublereal dsecnd_( void )
+// {
+// struct tms rusage;

- times(&rusage);
- return (doublereal)(rusage.tms_utime) / CLK_TCK;
+// times(&rusage);
+// return (doublereal)(rusage.tms_utime) / CLK_TCK;

-} /* dsecnd_ */
+// } /* dsecnd_ */
diff --git a/src/map/common/lapacksrc/install/static/second.c b/src/map/common/lapacksrc/install/static/second.c
index 68fbb062..915446f9 100644
--- a/src/map/common/lapacksrc/install/static/second.c
+++ b/src/map/common/lapacksrc/install/static/second.c
@@ -1,5 +1,5 @@
#include "FLA_f2c.h"
-#include <sys/times.h>
+// #include <sys/times.h>
//#include <sys/types.h>
//#include <time.h>

@@ -7,11 +7,11 @@
#define CLK_TCK 60
#endif

-real second_( void )
-{
- struct tms rusage;
+// real second_( void )
+// {
+// struct tms rusage;

- times(&rusage);
- return (real)(rusage.tms_utime) / CLK_TCK;
+// times(&rusage);
+// return (real)(rusage.tms_utime) / CLK_TCK;

-} /* second_ */
+// } /* second_ */
diff --git a/src/map/common/lapacksrc/install/util/other/dtime_.c b/src/map/common/lapacksrc/install/util/other/dtime_.c
index 6a09b3e9..5d87552d 100644
--- a/src/map/common/lapacksrc/install/util/other/dtime_.c
+++ b/src/map/common/lapacksrc/install/util/other/dtime_.c
@@ -13,7 +13,7 @@
#define _INCLUDE_POSIX_SOURCE /* for HP-UX */
#define _INCLUDE_XOPEN_SOURCE /* for HP-UX */
#include "sys/types.h"
-#include "sys/times.h"
+// #include "sys/times.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -30,34 +30,34 @@ extern "C" {
#endif
#endif

- REAL
-#ifdef KR_headers
-dtime_(tarray) float *tarray;
-#else
-dtime_(float *tarray)
-#endif
-{
-#ifdef USE_CLOCK
-#ifndef CLOCKS_PER_SECOND
-#define CLOCKS_PER_SECOND Hz
-#endif
- static double t0;
- double t = clock();
- tarray[1] = 0;
- tarray[0] = (t - t0) / CLOCKS_PER_SECOND;
- t0 = t;
- return tarray[0];
-#else
- struct tms t;
- static struct tms t0;
+// REAL
+// #ifdef KR_headers
+// dtime_(tarray) float *tarray;
+// #else
+// dtime_(float *tarray)
+// #endif
+// {
+// #ifdef USE_CLOCK
+// #ifndef CLOCKS_PER_SECOND
+// #define CLOCKS_PER_SECOND Hz
+// #endif
+// static double t0;
+// double t = clock();
+// tarray[1] = 0;
+// tarray[0] = (t - t0) / CLOCKS_PER_SECOND;
+// t0 = t;
+// return tarray[0];
+// #else
+// struct tms t;
+// static struct tms t0;

- times(&t);
- tarray[0] = (double)(t.tms_utime - t0.tms_utime) / Hz;
- tarray[1] = (double)(t.tms_stime - t0.tms_stime) / Hz;
- t0 = t;
- return tarray[0] + tarray[1];
-#endif
- }
+// times(&t);
+// tarray[0] = (double)(t.tms_utime - t0.tms_utime) / Hz;
+// tarray[1] = (double)(t.tms_stime - t0.tms_stime) / Hz;
+// t0 = t;
+// return tarray[0] + tarray[1];
+// #endif
+// }
#ifdef __cplusplus
}
#endif
diff --git a/src/map/common/lapacksrc/install/util/other/etime_.c b/src/map/common/lapacksrc/install/util/other/etime_.c
index 2d9a36d8..15ceca93 100644
--- a/src/map/common/lapacksrc/install/util/other/etime_.c
+++ b/src/map/common/lapacksrc/install/util/other/etime_.c
@@ -13,7 +13,7 @@
#define _INCLUDE_POSIX_SOURCE /* for HP-UX */
#define _INCLUDE_XOPEN_SOURCE /* for HP-UX */
#include "sys/types.h"
-#include "sys/times.h"
+// #include "sys/times.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -30,28 +30,28 @@ extern "C" {
#endif
#endif

- REAL
-#ifdef KR_headers
-etime_(tarray) float *tarray;
-#else
-etime_(float *tarray)
-#endif
-{
-#ifdef USE_CLOCK
-#ifndef CLOCKS_PER_SECOND
-#define CLOCKS_PER_SECOND Hz
-#endif
- double t = clock();
- tarray[1] = 0;
- return tarray[0] = t / CLOCKS_PER_SECOND;
-#else
- struct tms t;
+// REAL
+// #ifdef KR_headers
+// etime_(tarray) float *tarray;
+// #else
+// etime_(float *tarray)
+// #endif
+// {
+// #ifdef USE_CLOCK
+// #ifndef CLOCKS_PER_SECOND
+// #define CLOCKS_PER_SECOND Hz
+// #endif
+// double t = clock();
+// tarray[1] = 0;
+// return tarray[0] = t / CLOCKS_PER_SECOND;
+// #else
+// struct tms t;

- times(&t);
- return (tarray[0] = (double)t.tms_utime/Hz)
- + (tarray[1] = (double)t.tms_stime/Hz);
-#endif
- }
+// times(&t);
+// return (tarray[0] = (double)t.tms_utime/Hz)
+// + (tarray[1] = (double)t.tms_stime/Hz);
+// #endif
+// }
#ifdef __cplusplus
}
#endif
Loading