forked from ozimov/embedded-redis
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support arm64/aarch64 Linux and Apple Silicon
- remove references to 32 bit macos/darwin - normalize Redis server file names - update `build-server-binaries.sh` to statically link openssl on macOS - correctly detect macOS and Unix architectures Co-authored-by: Nathan J Mehl <[email protected]>
- Loading branch information
1 parent
d8f71db
commit 445a8e6
Showing
22 changed files
with
203 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
redis-server-* | ||
redis-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ARG ALPINE_VERSION=3.12 | ||
FROM alpine:${ALPINE_VERSION} | ||
RUN apk add --no-cache gcc musl-dev libressl-dev make pkgconfig linux-headers | ||
|
||
WORKDIR /build | ||
|
||
ARG REDIS_VERSION | ||
ENV REDIS_VERSION=${REDIS_VERSION} | ||
COPY redis-${REDIS_VERSION}.tar.gz /redis-${REDIS_VERSION}.tar.gz | ||
RUN ls -l / | ||
|
||
ARG ARCH | ||
RUN tar zxf /redis-${REDIS_VERSION}.tar.gz && \ | ||
cd redis-${REDIS_VERSION} && \ | ||
make BUILD_TLS='yes' CC='gcc -static' LDFLAGS='-s' MALLOC='libc' && \ | ||
mv src/redis-server /build/redis-server-${REDIS_VERSION}-linux-${ARCH} | ||
|
||
CMD [ "/bin/sh" ] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,115 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
REDIS_VERSION=6.2.6 | ||
REDIS_TARBALL="redis-${REDIS_VERSION}.tar.gz" | ||
REDIS_URL="https://download.redis.io/releases/${REDIS_TARBALL}" | ||
|
||
echo $ARCH | ||
|
||
function copy_openssl_and_remove_dylibs() { | ||
# To make macOS builds more portable, we want to statically link OpenSSL, | ||
# which is not straightforward. To force static compilation, we copy | ||
# the openssl libraries and remove dylibs, forcing static linking | ||
OPENSSL_HOME="${1}" | ||
ARCH=$2 | ||
OPENSSL_HOME_COPY="${3}/${ARCH}" | ||
if [ -d "${OPENSSL_HOME}" ]; then | ||
echo "*** Copying openssl libraries for static linking" | ||
cp -RL "${OPENSSL_HOME}" "${OPENSSL_HOME_COPY}" | ||
rm -f "${OPENSSL_HOME_COPY}"/lib/*.dylib | ||
else | ||
echo "*** WARNING: could not find openssl libraries at ${OPENSSL_HOME}; this build will almost certainly fail" | ||
fi | ||
} | ||
|
||
if [ "$(dirname ${0})" != "." ]; then | ||
echo "This script must be run from $(dirname ${0}). \`cd\` there and run again" | ||
exit 1 | ||
fi | ||
|
||
if ! [ -f "${REDIS_TARBALL}" ]; then | ||
curl -o "${REDIS_TARBALL}" "${REDIS_URL}" | ||
fi | ||
|
||
all_linux=0 | ||
if command -pv docker 2>/dev/null; then | ||
for arch in x86_64 arm64 i386; do | ||
|
||
echo "*** Building redis version ${REDIS_VERSION} for linux-${arch}" | ||
|
||
set +e | ||
docker build \ | ||
"--platform=linux/${arch}" \ | ||
--build-arg "REDIS_VERSION=${REDIS_VERSION}" \ | ||
--build-arg "ARCH=${arch}" \ | ||
-t "redis-server-builder-${arch}" \ | ||
. | ||
|
||
if [[ $? -ne 0 ]]; then | ||
echo "*** ERROR: could not build for linux-${arch}" | ||
continue | ||
fi | ||
set -e | ||
|
||
docker run -it --rm \ | ||
"--platform=linux/${arch}" \ | ||
-v "$(pwd)/":/mnt \ | ||
"redis-server-builder-${arch}" \ | ||
sh -c "cp /build/redis-server-${REDIS_VERSION}-linux-${arch} /mnt" | ||
|
||
((all_linux+=1)) | ||
|
||
done | ||
else | ||
echo "*** WARNING: No docker command found. Cannot build for linux." | ||
fi | ||
|
||
if [[ "${all_linux}" -lt 3 ]]; then | ||
echo "*** WARNING: was not able to build for all linux arches; see above for errors" | ||
fi | ||
|
||
if [[ "$(uname -s)" == "Darwin" ]]; then | ||
|
||
tar zxf "${REDIS_TARBALL}" | ||
cd "redis-${REDIS_VERSION}" | ||
|
||
# temporary directory for openssl libraries for static linking. | ||
# assumes standard Homebrew openssl install: | ||
# - arm64e at /opt/homebrew/opt/openssl | ||
# - x86_64 at /usr/local/opt/openssl | ||
OPENSSL_TEMP=$(mktemp -d /tmp/embedded-redis-darwin-openssl.XXXXX) | ||
|
||
# build for arm64 on apple silicon | ||
if arch -arm64e true 2>/dev/null; then | ||
copy_openssl_and_remove_dylibs /opt/homebrew/opt/openssl arm64e "${OPENSSL_TEMP}" | ||
echo "*** Building redis version ${REDIS_VERSION} for darwin-arm64e (apple silicon)" | ||
make clean | ||
arch -arm64e make -j3 BUILD_TLS=yes OPENSSL_PREFIX="$OPENSSL_TEMP/arm64e" | ||
mv src/redis-server "../redis-server-${REDIS_VERSION}-darwin-arm64" | ||
else | ||
echo "*** WARNING: could not build for darwin-arm64e; you probably want to do this on an apple silicon device" | ||
fi | ||
|
||
# build for x86_64 if we're on apple silicon or a recent macos on x86_64 | ||
if arch -x86_64 true 2>/dev/null; then | ||
copy_openssl_and_remove_dylibs /usr/local/opt/openssl x86_64 "${OPENSSL_TEMP}" | ||
echo "*** Building redis version ${REDIS_VERSION} for darwin-x86_64" | ||
make clean | ||
arch -x86_64 make -j3 BUILD_TLS=yes OPENSSL_PREFIX="$OPENSSL_TEMP/x86_64" | ||
mv src/redis-server "../redis-server-${REDIS_VERSION}-darwin-x86_64" | ||
else | ||
echo "*** WARNING: you are on a version of macos that lacks /usr/bin/arch, you probably do not want this" | ||
exit 1 | ||
fi | ||
cd .. | ||
|
||
docker build --build-arg REDIS_VERSION=${REDIS_VERSION} -t redis-server-builder-amd64 -f ./build-server-amd64.docker . | ||
docker build --build-arg REDIS_VERSION=${REDIS_VERSION} -t redis-server-builder-x86 -f ./build-server-x86.docker . | ||
else | ||
echo "*** WARNING: Cannot build for macos/darwin on a $(uname -s) host" | ||
fi | ||
|
||
docker run -it --rm \ | ||
-v "$(pwd)/":/redis-server-binaries \ | ||
redis-server-builder-amd64 \ | ||
sh -c "cd redis-${REDIS_VERSION}; make BUILD_TLS='yes' CC='gcc -static' LDFLAGS='-s' MALLOC='libc'; cp src/redis-server /redis-server-binaries/redis-server-${REDIS_VERSION}" | ||
ls -l redis-server-* | ||
|
||
docker run -it --rm \ | ||
-v "$(pwd)/":/redis-server-binaries \ | ||
redis-server-builder-x86 \ | ||
sh -c "cd redis-${REDIS_VERSION}; make BUILD_TLS='yes' CC='gcc -static' CFLAGS='-m32' LDFLAGS='-m32 -s' MALLOC='libc'; cp src/redis-server /redis-server-binaries/redis-server-${REDIS_VERSION}-32" | ||
echo "*** Moving built binaries to ../resources; you need to handle the rest yourself" | ||
mv redis-server-* ../resources/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
public enum Architecture { | ||
x86, | ||
x86_64 | ||
x86_64, | ||
arm64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, I suspect that should be
redis.x86_64
notredis-x86_64