Skip to content

Commit

Permalink
Add macOS universal lib build support
Browse files Browse the repository at this point in the history
  • Loading branch information
RyeMutt committed Nov 21, 2024
1 parent 5f1cc93 commit 7cf8f8d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 53 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
strategy:
matrix:
os: [windows-2022, macos-12, ubuntu-22.04]
os: [windows-2022, macos-15, ubuntu-22.04]
addrsize: ["64"]
continue-on-error: false
runs-on: ${{ matrix.os }}
Expand All @@ -20,10 +20,10 @@ jobs:
- name: Setup Apt Packages
if: ${{ runner.os == 'Linux' }}
shell: bash
run: |
run: |
sudo apt-get update
sudo apt-get -y install autoconf automake autopoint gettext
- uses: secondlife/action-autobuild@v4
- uses: secondlife/action-autobuild@v5
with:
addrsize: ${{ matrix.addrsize }}
release:
Expand Down
11 changes: 5 additions & 6 deletions apr-util/build/apu-conf.m4
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,16 @@ AC_ARG_WITH([expat],
# Add given path to standard search paths if appropriate:
if test "$withval" != "/usr"; then
APR_ADDTO(LDFLAGS, [-L$withval/lib])
APR_ADDTO(CPPFLAGS, [-I$withval/include])
APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
APR_ADDTO(CPPFLAGS, [-I$withval/include/expat])
APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include/expat])
APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
fi
APU_TRY_EXPAT_LINK([Expat 1.95.x], apu_cv_expat_system,
[expat.h], [-lexpat])
fi
])
if test $apu_try_external_expat = 1; then
APU_SYSTEM_EXPAT
fi
APR_ADDTO(APRUTIL_EXPORT_LIBS, [$apu_expat_libs])
APR_ADDTO(APRUTIL_LIBS, [$apu_expat_libs])
Expand Down
1 change: 1 addition & 0 deletions apr/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AC_PREREQ(2.59)
AC_INIT(build/apr_common.m4)
AC_CONFIG_HEADER(include/arch/unix/apr_private.h)
AC_CONFIG_AUX_DIR(build)
AC_CONFIG_MACRO_DIR(build)

dnl
dnl Include our own M4 macros along with those for libtool
Expand Down
1 change: 0 additions & 1 deletion autobuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
<key>manifest</key>
<array>
<string>lib/release/*.a</string>
<string>lib/release/*.dylib</string>
</array>
<key>name</key>
<string>darwin</string>
Expand Down
111 changes: 68 additions & 43 deletions build-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,51 @@ case "$AUTOBUILD_PLATFORM" in

opts="-arch $AUTOBUILD_CONFIGURE_ARCH $LL_BUILD_RELEASE"
plainopts="$(remove_cxxstd $opts)"
export CFLAGS="$plainopts"
export CXXFLAGS="$opts"
export LDFLAGS="$plainopts"
export MAKEFLAGS="-j${AUTOBUILD_CPU_COUNT:-2}"

export MACOSX_DEPLOYMENT_TARGET="$LL_BUILD_DARWIN_DEPLOY_TARGET"

pushd "$TOP_DIR/apr"
autoreconf -fvi
./configure --prefix="$PREFIX"
make
make install
popd
for arch in x86_64 arm64 ; do
ARCH_ARGS="-arch $arch"
opts="${TARGET_OPTS:-$ARCH_ARGS $LL_BUILD_RELEASE}"
cc_opts="$(remove_cxxstd $opts)"
ld_opts="$ARCH_ARGS"

pushd "$TOP_DIR/apr"
autoreconf -fvi

mkdir -p "build_$arch"
pushd "build_$arch"
CFLAGS="$cc_opts" CXXFLAGS="$opts" LDFLAGS="$ld_opts" \
../configure --prefix="$PREFIX" --disable-shared --enable-static --host=$arch-apple-darwin
make
make install
popd
popd

pushd "$TOP_DIR/apr-util"
autoreconf -fvi

lipo $STAGING_DIR/packages/lib/release/libexpat.a -thin $arch -output $STAGING_DIR/packages/lib/libexpat.a

mkdir -p "build_$arch"
pushd "build_$arch"
CFLAGS="$cc_opts" CXXFLAGS="$opts" LDFLAGS="$ld_opts" \
../configure --prefix="$PREFIX" --with-apr="$PREFIX" --with-expat="$STAGING_DIR/packages" --disable-shared --enable-static --host=$arch-apple-darwin
make
make install
popd

rm $STAGING_DIR/packages/lib/libexpat.a
popd

mkdir -p "$PREFIX/lib/release/$arch"
mv "$PREFIX"/lib/*.* "$PREFIX/lib/release/$arch"
done

pushd "$TOP_DIR/apr-util"
autoreconf -fvi
./configure --prefix="$PREFIX" --with-apr="$PREFIX" --with-expat="$PREFIX"
make
make install
popd
# Create universal library
lipo -create -output "$STAGING_DIR/lib/release/libapr-1.a" "$STAGING_DIR/lib/release/x86_64/libapr-1.a" "$STAGING_DIR/lib/release/arm64/libapr-1.a"
lipo -create -output "$STAGING_DIR/lib/release/libaprutil-1.a" "$STAGING_DIR/lib/release/x86_64/libaprutil-1.a" "$STAGING_DIR/lib/release/arm64/libaprutil-1.a"

# To conform with autobuild install-package conventions, we want to move
# the libraries presently in "$PREFIX/lib" to "$PREFIX/lib/release".
Expand All @@ -184,26 +209,26 @@ case "$AUTOBUILD_PLATFORM" in
# directly, they want to manipulate only libapr[util]-1.0.dylib. Fix
# things while relocating.

mkdir -p "$PREFIX/lib/release" || echo "reusing $PREFIX/lib/release"
for libname in libapr libaprutil
do # First just move the static library, that part is easy
mv "$PREFIX/lib/$libname-1.a" "$PREFIX/lib/release/"
# Ensure that lib/release/$libname-1.0.dylib is a real file, not a symlink
cp "$PREFIX/lib/$libname-1.0.dylib" "$PREFIX/lib/release"
# Make sure it's stamped with the -id we need in our app bundle.
# As of 2012-02-07, with APR 1.4.5, this function has been observed to
# fail on TeamCity builds. Does the failure matter? Hopefully not...
pushd "$PREFIX/lib/release"
fix_dylib_id "$libname-1.0.dylib" || \
echo "fix_dylib_id $libname-1.0.dylib failed, proceeding"
popd
# Recreate the $libname-1.dylib symlink, because the one in lib/ is
# pointing to (e.g.) libapr-1.0.4.5.dylib -- no good
ln -svf "$libname-1.0.dylib" "$PREFIX/lib/release/$libname-1.dylib"
# Clean up whatever's left in $PREFIX/lib for this $libname (e.g.
# libapr-1.0.4.5.dylib)
rm "$PREFIX/lib/$libname-"*.dylib || echo "moved all $libname-*.dylib"
done
# mkdir -p "$PREFIX/lib/release" || echo "reusing $PREFIX/lib/release"
# for libname in libapr libaprutil
# do # First just move the static library, that part is easy
# mv "$PREFIX/lib/$libname-1.a" "$PREFIX/lib/release/"
# # Ensure that lib/release/$libname-1.0.dylib is a real file, not a symlink
# cp "$PREFIX/lib/$libname-1.0.dylib" "$PREFIX/lib/release"
# # Make sure it's stamped with the -id we need in our app bundle.
# # As of 2012-02-07, with APR 1.4.5, this function has been observed to
# # fail on TeamCity builds. Does the failure matter? Hopefully not...
# pushd "$PREFIX/lib/release"
# fix_dylib_id "$libname-1.0.dylib" || \
# echo "fix_dylib_id $libname-1.0.dylib failed, proceeding"
# popd
# # Recreate the $libname-1.dylib symlink, because the one in lib/ is
# # pointing to (e.g.) libapr-1.0.4.5.dylib -- no good
# ln -svf "$libname-1.0.dylib" "$PREFIX/lib/release/$libname-1.dylib"
# # Clean up whatever's left in $PREFIX/lib for this $libname (e.g.
# # libapr-1.0.4.5.dylib)
# rm "$PREFIX/lib/$libname-"*.dylib || echo "moved all $libname-*.dylib"
# done

# When we linked apr-util against apr (above), it grabbed the -id baked
# into libapr-1.0.dylib as of that moment. A libaprutil-1.0.dylib built
Expand All @@ -226,14 +251,14 @@ case "$AUTOBUILD_PLATFORM" in
# to the canonical relative Resources path. NOW: feed all those -change
# switches into an install_name_tool command operating on that same
# .dylib.
lib="$PREFIX/lib/release/libaprutil-1.0.dylib"
install_name_tool \
$(otool -L "$lib" | tail -n +3 | \
grep "$PREFIX/lib" | awk '{ print $1 }' | \
(while read f; \
do echo -change "$f" "@executable_path/../Resources/$(basename "$f")"; \
done) ) \
"$lib"
# lib="$PREFIX/lib/release/libaprutil-1.0.dylib"
# install_name_tool \
# $(otool -L "$lib" | tail -n +3 | \
# grep "$PREFIX/lib" | awk '{ print $1 }' | \
# (while read f; \
# do echo -change "$f" "@executable_path/../Resources/$(basename "$f")"; \
# done) ) \
# "$lib"
;;

# ****************************************************************************
Expand Down

0 comments on commit 7cf8f8d

Please sign in to comment.