Skip to content

Commit

Permalink
guix: darwin builds
Browse files Browse the repository at this point in the history
  • Loading branch information
tobtoht committed Aug 25, 2024
1 parent 07e25f4 commit 8704c4e
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 145 deletions.
29 changes: 19 additions & 10 deletions contrib/depends/hosts/darwin.mk
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
OSX_MIN_VERSION=10.13
OSX_MIN_VERSION=11
OSX_SDK_VERSION=11.0
XCODE_VERSION=12.2
XCODE_BUILD_ID=12B45b
LD64_VERSION=609
LD64_VERSION=711

OSX_SDK=$(host_prefix)/native/SDK

darwin_native_toolchain=darwin_sdk native_cctools
darwin_native_toolchain=darwin_sdk

clang_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang")
clangxx_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang++")
llvm_config_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-config")

darwin_AR=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-ar")
darwin_DSYMUTIL=$(shell $(SHELL) $(.SHELLFLAGS) "command -v dsymutil")
darwin_NM=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-nm")
darwin_OBJDUMP=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-objdump")
darwin_RANLIB=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-ranlib")
darwin_STRIP=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-strip")
darwin_LIBTOOL=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-libtool-darwin")

# Flag explanations:
#
Expand Down Expand Up @@ -37,23 +46,23 @@ clangxx_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang++")
darwin_CC=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
-u LIBRARY_PATH \
$(clang_prog) --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
-isysroot$(OSX_SDK) \
$(clang_prog) --target=$(host) \
-B$(build_prefix)/bin \
-isysroot$(OSX_SDK) -nostdlibinc \
-iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks

darwin_CXX=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
-u LIBRARY_PATH \
$(clangxx_prog) --target=$(host) -mmacosx-version-min=$(OSX_MIN_VERSION) \
-B$(build_prefix)/bin -mlinker-version=$(LD64_VERSION) \
$(clangxx_prog) --target=$(host) \
-B$(build_prefix)/bin \
-isysroot$(OSX_SDK) -nostdlibinc \
-iwithsysroot/usr/include/c++/v1 \
-iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks

darwin_CFLAGS=-pipe
darwin_CXXFLAGS=$(darwin_CFLAGS)
darwin_CFLAGS=-pipe -std=c11 -mmacosx-version-min=$(OSX_MIN_VERSION) -mlinker-version=$(LD64_VERSION)
darwin_CXXFLAGS=-pipe -std=c++17 -mmacosx-version-min=$(OSX_MIN_VERSION) -mlinker-version=$(LD64_VERSION)
darwin_LDFLAGS=-Wl,-platform_version,macos,$(OSX_MIN_VERSION),$(OSX_SDK_VERSION) -Wl,-no_adhoc_codesign -fuse-ld=lld
darwin_ARFLAGS=cr

darwin_release_CFLAGS=-O2
Expand Down
6 changes: 6 additions & 0 deletions contrib/depends/packages/darwin_sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ $(package)_version=12.2
$(package)_download_path=https://bitcoincore.org/depends-sources/sdks
$(package)_file_name=Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
$(package)_sha256_hash=df75d30ecafc429e905134333aeae56ac65fac67cb4182622398fd717df77619
$(package)_patches=setup.sh

define $(package)_config_cmds
env host_prefix="$(host_prefix)" host="$(host)" bash $($(package)_patch_dir)/setup.sh
endef

define $(package)_stage_cmds
mkdir -p $($(package)_staging_dir)/$(host_prefix)/native/SDK &&\
rm -rf usr/include/readline && \
mv bin $($(package)_staging_dir)/$(host_prefix)/native/ && \
mv * $($(package)_staging_dir)/$(host_prefix)/native/SDK
endef
4 changes: 3 additions & 1 deletion contrib/depends/packages/libusb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ $(package)_version=1.0.27
$(package)_download_path=https://github.com/libusb/libusb/releases/download/v$($(package)_version)
$(package)_file_name=$(package)-$($(package)_version).tar.bz2
$(package)_sha256_hash=ffaa41d741a8a3bee244ac8e54a72ea05bf2879663c098c82fc5757853441575
$(package)_patches=no-c11.patch

define $(package)_preprocess_cmds
patch -p1 < $($(package)_patch_dir)/no-c11.patch && \
cp -f $(BASEDIR)/config.guess $(BASEDIR)/config.sub . && \
autoreconf -i
endef
Expand All @@ -18,7 +20,7 @@ define $(package)_set_vars
endef

define $(package)_config_cmds
$($(package)_autoconf) AR_FLAGS=$($(package)_arflags)
$($(package)_autoconf) ac_c_dialect=c
endef

define $(package)_build_cmd
Expand Down
37 changes: 0 additions & 37 deletions contrib/depends/packages/native_cctools.mk

This file was deleted.

19 changes: 0 additions & 19 deletions contrib/depends/packages/native_libtapi.mk

This file was deleted.

1 change: 1 addition & 0 deletions contrib/depends/packages/openssl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $(package)_config_env=AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CC="$(
$(package)_config_env_android=ANDROID_NDK_ROOT="$(toolchain_prefix)" PATH="$(toolchain_prefix)/bin"
$(package)_build_env_android=ANDROID_NDK_ROOT="$(toolchain_prefix)"
$(package)_config_opts=--prefix=$(host_prefix) --openssldir=$(host_prefix)/etc/openssl --libdir=$(host_prefix)/lib
$(package)_config_opts+=no-asm
$(package)_config_opts+=no-capieng
$(package)_config_opts+=no-dso
$(package)_config_opts+=no-dtls1
Expand Down
2 changes: 1 addition & 1 deletion contrib/depends/packages/packages.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ mingw32_packages = $(hardware_packages)
mingw32_native_packages = $(hardware_native_packages)

ifneq ($(build_os),darwin)
darwin_native_packages += darwin_sdk native_cctools native_libtapi
darwin_native_packages += darwin_sdk
endif
7 changes: 7 additions & 0 deletions contrib/depends/packages/rustc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $(package)_sha256_hash=ee106e4c569f52dba3b5b282b105820f86bd8f6b3d09c06b8dce82fb1
$(package)_patches=config.toml
$(package)_freebsd_dependencies=freebsd_base native_binutils
$(package)_android_dependencies=android_ndk
$(package)_darwin_dependencies=darwin_sdk

define $(package)_set_vars
$(package)_stage_env_freebsd=AR_x86_64_unknown_freebsd=x86_64-unknown-freebsd11-ar
Expand All @@ -15,6 +16,12 @@ $(package)_stage_env_aarch64_android=CC_aarch64_linux_android="$(host_toolchain)
$(package)_stage_env_aarch64_android+=CXX_aarch64_linux_android="$(host_toolchain)clang++"
$(package)_stage_env_arm_android=CC_armv7_linux_androideabi="$(host_toolchain)clang"
$(package)_stage_env_arm_android+=CXX_armv7_linux_androideabi="$(host_toolchain)clang++"
$(package)_stage_env_darwin=CC_x86_64_apple_darwin=x86_64-apple-darwin-clang
$(package)_stage_env_darwin+=CXX_x86_64_apple_darwin=x86_64-apple-darwin-clang++
$(package)_stage_env_darwin+=AR_x86_64_apple_darwin=llvm-ar
$(package)_stage_env_darwin=CC_aarch64_apple_darwin=aarch64-apple-darwin-clang
$(package)_stage_env_darwin+=CXX_aarch64_apple_darwin=aarch64-apple-darwin-clang++
$(package)_stage_env_darwin+=AR_aarch64_apple_darwin=llvm-ar
endef

define $(package)_config_cmds
Expand Down
2 changes: 1 addition & 1 deletion contrib/depends/packages/unbound.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ define $(package)_preprocess_cmds
endef

define $(package)_config_cmds
$($(package)_autoconf) ac_cv_func_getentropy=no AR_FLAGS=$($(package)_arflags)
$($(package)_autoconf) ac_cv_func_getentropy=no
endef

define $(package)_build_cmds
Expand Down
3 changes: 1 addition & 2 deletions contrib/depends/packages/zeromq.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ define $(package)_set_vars
$(package)_config_opts=--without-documentation --disable-shared --without-libsodium --disable-curve
$(package)_config_opts_linux=--with-pic
$(package)_config_opts_freebsd=--with-pic
$(package)_cxxflags=-std=c++11
endef

define $(package)_config_cmds
$($(package)_autoconf) AR_FLAGS=$($(package)_arflags)
$($(package)_autoconf)
endef

define $(package)_build_cmds
Expand Down
24 changes: 24 additions & 0 deletions contrib/depends/patches/darwin_sdk/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

mkdir bin

target=${host}

OSX_SDK=${host_prefix}/native/SDK

for tool in clang clang++; do
tool_path=bin/${target}-${tool}
cat > "$tool_path" <<EOF
#!/bin/sh
exec env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
-u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \
-u LIBRARY_PATH \
${tool} --target=${target} \
-B${host_prefix}/native/bin \
-isysroot${OSX_SDK} -nostdlibinc \
-iwithsysroot/usr/include \
-iframeworkwithsysroot/System/Library/Frameworks \
-pipe -mmacosx-version-min=11 -mlinker-version=711 -Wl,-platform_version,macos,11,11.0 -Wl,-no_adhoc_codesign -fuse-ld=lld "\$@"
EOF
chmod +x "$tool_path"
done
35 changes: 35 additions & 0 deletions contrib/depends/patches/libusb/no-c11.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/configure.ac b/configure.ac
index 6dc7c698..3ce6cb78 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,30 +41,6 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
EXTRA_CPPFLAGS=
EXTRA_CFLAGS=

-dnl check for -std=gnu11 compiler support (optional)
-dnl note that we don't just check if the compiler accepts '-std=x11'
-dnl but also that it supports the _Thread_local keyword because some compilers
-dnl (e.g. gcc 4.8) accept the command line option but do not implement TLS
-saved_CFLAGS="${CFLAGS}"
-CFLAGS="-std=gnu11"
-AC_MSG_CHECKING([if $CC supports -std=gnu11])
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
- [AC_MSG_RESULT([yes])
- c_dialect=gnu],
- [AC_MSG_RESULT([no])
- c_dialect=])
-if test "x$c_dialect" != xgnu; then
- dnl fallback check for -std=c11 compiler support (required)
- CFLAGS="-std=c11"
- AC_MSG_CHECKING([if $CC supports -std=c11])
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
- [AC_MSG_RESULT([yes])],
- [AC_MSG_RESULT([no])
- AC_MSG_ERROR([compiler with C11 support is required to build libusb])])
- c_dialect=c
-fi
-CFLAGS="${saved_CFLAGS}"
-
AC_DEFINE([_GNU_SOURCE], [1], [Enable GNU extensions.])
AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__ ((visibility ("default")))], [Define to the attribute for default visibility.])
AC_DEFINE([PRINTF_FORMAT(a, b)], [__attribute__ ((__format__ (__printf__, a, b)))], [Define to the attribute for enabling parameter checks on printf-like functions.])
12 changes: 0 additions & 12 deletions contrib/depends/patches/native_cctools/no-build-date.patch

This file was deleted.

31 changes: 0 additions & 31 deletions contrib/depends/patches/native_libtapi/no_embed_git_rev.patch

This file was deleted.

23 changes: 19 additions & 4 deletions contrib/depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,35 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
SET(_CMAKE_TOOLCHAIN_PREFIX @prefix@/native/bin/${CONF_TRIPLE}-)
SET(CMAKE_C_COMPILER @CC@)
SET(CMAKE_C_COMPILER_TARGET ${CLANG_TARGET})
SET(CMAKE_C_FLAGS_INIT -B${_CMAKE_TOOLCHAIN_PREFIX})
SET(CMAKE_C_FLAGS_INIT "@CFLAGS@")
SET(CMAKE_C_FLAGS "@CFLAGS@")
SET(CMAKE_CXX_COMPILER @CXX@ -stdlib=libc++)
SET(CMAKE_CXX_COMPILER_TARGET ${CLANG_TARGET})
SET(CMAKE_CXX_FLAGS_INIT -B${_CMAKE_TOOLCHAIN_PREFIX})
SET(CMAKE_CXX_FLAGS_INIT @CXXFLAGS@)
SET(CMAKE_CXX_FLAGS "@CXXFLAGS@")

set(CMAKE_EXE_LINKER_FLAGS_INIT " -L/usr/lib @LDFLAGS@ -v")
set(CMAKE_MODULE_LINKER_FLAGS_INIT " -L/usr/lib @LDFLAGS@ -v")
set(CMAKE_SHARED_LINKER_FLAGS_INIT " -L/usr/lib @LDFLAGS@ -v")

SET(CMAKE_OSX_SYSROOT "@prefix@/native/SDK/")

set(CMAKE_EXE_LINKER_FLAGS " -L/usr/lib @LDFLAGS@ -v")
set(CMAKE_MODULE_LINKER_FLAGS "-L/usr/lib @LDFLAGS@ -v")
set(CMAKE_SHARED_LINKER_FLAGS "-L/usr/lib @LDFLAGS@ -v")

set(CMAKE_INSTALL_NAME_TOOL llvm-install-name-tool)

SET(CMAKE_ASM_COMPILER clang)
SET(CMAKE_ASM-ATT_COMPILER as)
SET(CMAKE_ASM-ATT_COMPILER llvm-as)
SET(CMAKE_ASM_COMPILER_TARGET ${CLANG_TARGET})
SET(CMAKE_ASM-ATT_COMPILER_TARGET ${CLANG_TARGET})
SET(APPLE True)
SET(BUILD_64 ON)
SET(BREW OFF)
SET(PORT OFF)
SET(CMAKE_OSX_SYSROOT "@prefix@/native/SDK/")
SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
SET(CMAKE_OSX_DEPLOYMENT_TARGET "11")
SET(CMAKE_CXX_STANDARD 17)
SET(LLVM_ENABLE_PIC OFF)
SET(LLVM_ENABLE_PIE OFF)
Expand Down
25 changes: 1 addition & 24 deletions contrib/guix/libexec/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,7 @@ for p in "${PATHS[@]}"; do
done

# Disable Guix ld auto-rpath behavior
case "$HOST" in
*darwin*)
# The auto-rpath behavior is necessary for darwin builds as some native
# tools built by depends refer to and depend on Guix-built native
# libraries
#
# After the native packages in depends are built, the ld wrapper should
# no longer affect our build, as clang would instead reach for
# x86_64-apple-darwin-ld from cctools
;;
*android*)
;;
*) export GUIX_LD_WRAPPER_DISABLE_RPATH=yes ;;
esac
export GUIX_LD_WRAPPER_DISABLE_RPATH=yes

# Make /usr/bin if it doesn't exist
[ -e /usr/bin ] || mkdir -p /usr/bin
Expand Down Expand Up @@ -228,16 +215,6 @@ export GLIBC_DYNAMIC_LINKER=${glibc_dynamic_linker}
# Environment variables for determinism
export TAR_OPTIONS="--owner=0 --group=0 --numeric-owner --mtime='@${SOURCE_DATE_EPOCH}' --sort=name"
export TZ="UTC"
case "$HOST" in
*darwin*)
# cctools AR, unlike GNU binutils AR, does not have a deterministic mode
# or a configure flag to enable determinism by default, it only
# understands if this env-var is set or not. See:
#
# https://github.com/tpoechtrager/cctools-port/blob/55562e4073dea0fbfd0b20e0bf69ffe6390c7f97/cctools/ar/archive.c#L334
export ZERO_AR_DATE=yes
;;
esac

####################
# Depends Building #
Expand Down
Loading

0 comments on commit 8704c4e

Please sign in to comment.