Skip to content

Commit

Permalink
prepare osx build
Browse files Browse the repository at this point in the history
  • Loading branch information
timfel committed Nov 10, 2022
1 parent 884dd7e commit 12bb156
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 45 deletions.
97 changes: 54 additions & 43 deletions recipes/graalpy/build_graalpy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

set -exo pipefail

if [ `uname` = "Darwin" ]; then
MACOS="true"
fi

# this needs to be updated when the target python version of graalpy changes
PY_VERSION=3.8

Expand All @@ -12,9 +16,9 @@ export MX_PRIMARY_SUITE_PATH=$SRC_DIR/graal/vm

# mx ninja build templates hardcode ar, gcc, g++; symlink these to the conda
# compilers
ln -s $AR $MX_DIR/ar
ln -s $CC $MX_DIR/gcc
ln -s $CXX $MX_DIR/g++
ln -sf $AR $MX_DIR/ar
ln -sf $CC $MX_DIR/gcc
ln -sf $CXX $MX_DIR/g++

# sulong toolchain wrappers are not recognized and cmake is making trouble
# getting them to compile anything. Make sure to use the sysroot flag, and
Expand All @@ -24,14 +28,16 @@ export CXXFLAGS="$CXXFLAGS --sysroot $CONDA_BUILD_SYSROOT"
export LDFLAGS="$LDFLAGS --sysroot $CONDA_BUILD_SYSROOT"
export CPATH="$BUILD_PREFIX/include"
export LIBRARY_PATH="$BUILD_PREFIX/lib"
for filename in $CONDA_BUILD_SYSROOT/../lib/libgcc_s.so*; do
ln -s $filename $CONDA_BUILD_SYSROOT/lib/
done
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/crtbegin.o $CONDA_BUILD_SYSROOT/lib/
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/crtbeginS.o $CONDA_BUILD_SYSROOT/lib/
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/crtend.o $CONDA_BUILD_SYSROOT/lib/
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/crtendS.o $CONDA_BUILD_SYSROOT/lib/
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/libgcc.a $CONDA_BUILD_SYSROOT/lib/
if [ -z "${MACOS}" ]; then
for filename in $CONDA_BUILD_SYSROOT/../lib/libgcc_s.so*; do
ln -s $filename $CONDA_BUILD_SYSROOT/lib/
done
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/crtbegin.o $CONDA_BUILD_SYSROOT/lib/
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/crtbeginS.o $CONDA_BUILD_SYSROOT/lib/
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/crtend.o $CONDA_BUILD_SYSROOT/lib/
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/crtendS.o $CONDA_BUILD_SYSROOT/lib/
ln -s $CONDA_BUILD_SYSROOT/../../lib/gcc/x86_64-conda-linux-gnu/*/libgcc.a $CONDA_BUILD_SYSROOT/lib/
fi

# git init an empty repo inside graal, to force mx to pick graal download as
# siblings dir
Expand Down Expand Up @@ -65,17 +71,18 @@ if [ -n "${GRAALPY_STANDALONE_BUILD}" ]; then
STANDALONE=`mx standalone-home python`
cp -r $STANDALONE/* $PREFIX


# sulong ensures that the llvm toolchain uses libc++abi.so in the toolchain
# directory by dynamically making sure it's loaded in its toolchain wrappers,
# but the conda build cannot know this and complains
LIBCXX_RPATH=`patchelf --print-rpath $PREFIX/lib/llvm-toolchain/lib/*/libc++.so.1.0`
if [ -n "$LIBCXX_RPATH" ]; then
LIBCXX_RPATH="$LIBCXX_RPATH:\$ORIGIN"
else
LIBCXX_RPATH="\$ORIGIN"
if [ -z "${MACOS}" ]; then
# sulong ensures that the llvm toolchain uses libc++abi.so in the toolchain
# directory by dynamically making sure it's loaded in its toolchain wrappers,
# but the conda build cannot know this and complains
LIBCXX_RPATH=`patchelf --print-rpath $PREFIX/lib/llvm-toolchain/lib/*/libc++.so.1.0`
if [ -n "$LIBCXX_RPATH" ]; then
LIBCXX_RPATH="$LIBCXX_RPATH:\$ORIGIN"
else
LIBCXX_RPATH="\$ORIGIN"
fi
patchelf --set-rpath "$LIBCXX_RPATH" $PREFIX/lib/llvm-toolchain/lib/*/libc++.so.1.0
fi
patchelf --set-rpath "$LIBCXX_RPATH" $PREFIX/lib/llvm-toolchain/lib/*/libc++.so.1.0

# match cpython include folder structure
ln -sf $PREFIX/include $PREFIX/include/python${PY_VERSION}
Expand All @@ -98,31 +105,35 @@ else
# sulong ensures that the llvm toolchain uses libc++abi.so in the toolchain
# directory by dynamically making sure it's loaded in its toolchain wrappers,
# but the conda build cannot know this and complains
LIBCXX_RPATH=`patchelf --print-rpath $GRAALVM_PREFIX/lib/llvm/lib/*/libc++.so.1.0`
if [ -n "$LIBCXX_RPATH" ]; then
LIBCXX_RPATH="$LIBCXX_RPATH:\$ORIGIN"
else
LIBCXX_RPATH="\$ORIGIN"
if [ -z "${MACOS}" ]; then
LIBCXX_RPATH=`patchelf --print-rpath $GRAALVM_PREFIX/lib/llvm/lib/*/libc++.so.1.0`
if [ -n "$LIBCXX_RPATH" ]; then
LIBCXX_RPATH="$LIBCXX_RPATH:\$ORIGIN"
else
LIBCXX_RPATH="\$ORIGIN"
fi
patchelf --set-rpath "$LIBCXX_RPATH" $GRAALVM_PREFIX/lib/llvm/lib/*/libc++.so.1.0
fi
patchelf --set-rpath "$LIBCXX_RPATH" $GRAALVM_PREFIX/lib/llvm/lib/*/libc++.so.1.0

# delete graalvm libraries not required for graalpy
rm $GRAALVM_PREFIX/lib/libsplashscreen.so
rm $GRAALVM_PREFIX/lib/libawt_xawt.so
rm $GRAALVM_PREFIX/lib/libjawt.so
rm $GRAALVM_PREFIX/lib/libfontmanager.so
rm $GRAALVM_PREFIX/lib/libjsound.so

# relativize rpath for jvm libs
for i in $GRAALVM_PREFIX/lib/*.so; do
SO_RPATH=`patchelf --print-rpath $i`
if [ -n "$SO_RPATH" ]; then
SO_RPATH="$SO_RPATH:\$ORIGIN/server"
else
SO_RPATH="\$ORIGIN/server"
fi
patchelf --set-rpath "$SO_RPATH" $i
done
if [ -z "${MACOS}" ]; then
# delete graalvm libraries not required for graalpy
rm $GRAALVM_PREFIX/lib/libsplashscreen.so
rm $GRAALVM_PREFIX/lib/libawt_xawt.so
rm $GRAALVM_PREFIX/lib/libjawt.so
rm $GRAALVM_PREFIX/lib/libfontmanager.so
rm $GRAALVM_PREFIX/lib/libjsound.so

for i in $GRAALVM_PREFIX/lib/*.so; do
SO_RPATH=`patchelf --print-rpath $i`
if [ -n "$SO_RPATH" ]; then
SO_RPATH="$SO_RPATH:\$ORIGIN/server"
else
SO_RPATH="\$ORIGIN/server"
fi
patchelf --set-rpath "$SO_RPATH" $i
done
fi

# match cpython include folder structure
mkdir -p $PREFIX/include/
Expand Down
5 changes: 5 additions & 0 deletions recipes/graalpy/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ python_impl:
- '*'
numpy:
- '1.16'

MACOS_DEPLOYMENT_TARGET: # [osx]
- '10.10' # [osx]
MACOS_SDK_VERSION: # [osx]
- '10.10' # [osx]
4 changes: 3 additions & 1 deletion recipes/graalpy/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ source:
patches:
- patches/graalpy-honour-sysroot.patch
- patches/graalpy-reduce-image-build-xmx.patch
- patches/graalpy-fix-lzma.patch # [osx]

build:
number: {{ build_num }}
Expand Down Expand Up @@ -72,13 +73,14 @@ outputs:
- git
- curl
- cmake
- patchelf
- patchelf # [linux]
host:
- zlib
run:
- libzlib
- patch
- curl
- __osx >={{ MACOS_DEPLOYMENT_TARGET|default("10.10") }} # [osx]
run_constrained:
- python {{ gp_python_version }} {{ build_num }}_{{ graalpy_abi }}_graalpy
test:
Expand Down
13 changes: 13 additions & 0 deletions recipes/graalpy/patches/graalpy-fix-lzma.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/graalpython/com.oracle.graal.python.cext/lzma/config.h b/graalpython/com.oracle.graal.python.cext/lzma/config.h
index 0d1d0704f7..f96f33f045 100644
--- a/graalpython/com.oracle.graal.python.cext/lzma/config.h
+++ b/graalpython/com.oracle.graal.python.cext/lzma/config.h
@@ -108,7 +108,7 @@
#define STDC_HEADERS 1
#define TUKLIB_CPUCORES_SCHED_GETAFFINITY 1
#define TUKLIB_FAST_UNALIGNED_ACCESS 1
-#define TUKLIB_PHYSMEM_SYSCONF 1
+#define TUKLIB_PHYSMEM_SYSCTL 1
#define VERSION "5.2.6"
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ index 11a83ca8..8f592ad1 100755
elif isinstance(value, str):
value = expandvars(value)
if '$' in value or '%' in value:
+ if is_linux() and value == r"\$$ORIGIN":
+ if value == r"\$$ORIGIN":
+ # this is the escaping that CMake uses, see https://cmake.org/cmake/help/latest/policy/CMP0095.html#policy:CMP0095
+ return "$ORIGIN"
abort('value of ' + '.'.join(context) + ' contains an undefined environment variable: ' + value)
Expand Down

0 comments on commit 12bb156

Please sign in to comment.