Skip to content

Commit

Permalink
Merge pull request #156 from spacedriveapp/mob-119-compile-native-dep…
Browse files Browse the repository at this point in the history
…s-for-android

Add android build
  • Loading branch information
HeavenVolkoff authored Oct 21, 2024
2 parents 899c89c + 8fa92da commit b7c7afe
Show file tree
Hide file tree
Showing 39 changed files with 414 additions and 81 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
- target: aarch64-linux-gnu
- target: x86_64-linux-musl
- target: aarch64-linux-musl
- target: x86_64-linux-android
- target: aarch64-linux-android
name: Build native-deps ${{ matrix.settings.target }}
runs-on: ubuntu-latest
defaults:
Expand Down
40 changes: 37 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ARG CMAKE_VERSION='3.30.5'
ARG PATCHELF_VERSION='0.18.0'
ARG MACOS_SDK_VERSION='14.0'
ARG IOS_SDK_VERSION='17.0'
ARG ANDROID_API_LEVEL='28'

#--

Expand Down Expand Up @@ -49,6 +50,7 @@ RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/
make `
patch `
rsync `
lld-17 `
libtool `
python3 `
gettext `
Expand Down Expand Up @@ -116,6 +118,11 @@ RUN cd "${SYSROOT}/lib/libc/mingw/lib-common" `

FROM build-base AS base-layer

# Configure android ndk sysroot
ENV NDK_SDKROOT="${SYSROOT}/sysroot"
ARG ANDROID_API_LEVEL
ENV ANDROID_API_LEVEL="${ANDROID_API_LEVEL:?}"

# Configure macOS SDK for darwin targets
ARG MACOS_SDK_VERSION
ENV MACOS_SDK_VERSION="${MACOS_SDK_VERSION:?}"
Expand All @@ -137,8 +144,7 @@ RUN echo "Building: ${TARGET}$(case "$TARGET" in *darwin*) echo " (macOS SDK: ${
# Script wrapper for some common build tools. Auto choose between llvm, zig or apple specific versions
COPY --chmod=0750 ./scripts/tool-wrapper.sh "${SYSROOT}/bin/tool-wrapper.sh"
RUN for tool in `
ar nm lib lipo size otool strip ranlib readelf libtool objdump dlltool `
objcopy strings bitcode-strip install_name_tool; `
ar nm lib lipo size otool strip ranlib readelf libtool objdump dlltool objcopy strings bitcode-strip install_name_tool; `
do ln -s "$(command -v tool-wrapper.sh)" "${SYSROOT}/bin/${tool}"; done

# Custom llvm rc wrapper script with some pre-configurations
Expand Down Expand Up @@ -178,13 +184,20 @@ RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/00-apple/05-ldid.sh,target=/srv/05-ldid.sh `
/srv/05-ldid.sh

# Download NDK sysroot
RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/00-ndk.sh,target=/srv/00-ndk.sh `
/srv/00-ndk.sh

# Ensure no one tries to call the native system linker
RUN ln -s '/usr/bin/false' "${SYSROOT}/bin/ld"

# Add wrapper script for zig compilers, we need to ensure that they are called with the correct arguments
COPY --chmod=0750 ./scripts/cc.sh "${SYSROOT}/bin/cc"
RUN ln -s 'cc' "${SYSROOT}/bin/c++"
RUN chmod +x "${SYSROOT}/bin/cc" "${SYSROOT}/bin/c++"
# Hack for cmake to work when compiling android targets
RUN ln -s 'cc' "${SYSROOT}/bin/android-gcc"
RUN ln -s 'cc' "${SYSROOT}/bin/android-g++"

# Create cmake and meson toolchain files
RUN --mount=type=bind,rw,source=scripts/toolchain.sh,target=/srv/toolchain.sh /srv/toolchain.sh
Expand Down Expand Up @@ -270,11 +283,18 @@ RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/25-ogg.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-20 AS layer-25-pciaccess

RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/25-pciaccess.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-20 AS layer-25

COPY --from=layer-25-lcms "${PREFIX}/." "$PREFIX"
COPY --from=layer-25-lzma "${PREFIX}/." "$PREFIX"
COPY --from=layer-25-ogg "${PREFIX}/." "$PREFIX"
COPY --from=layer-25-pciaccess "${PREFIX}/." "$PREFIX"

#--

Expand All @@ -291,6 +311,12 @@ RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=patches/45-de265,target="${PREFIX}/patches" `
/srv/build.sh

FROM layer-25 AS layer-45-drm

RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/45-drm.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-25 AS layer-45-opencl

RUN --mount=type=cache,target=/root/.cache `
Expand All @@ -317,6 +343,7 @@ FROM layer-25 AS layer-45

COPY --from=layer-45-dav1d "${PREFIX}/." "$PREFIX"
COPY --from=layer-45-de265 "${PREFIX}/." "$PREFIX"
COPY --from=layer-45-drm "${PREFIX}/." "$PREFIX"
COPY --from=layer-45-opencl "${PREFIX}/." "$PREFIX"
COPY --from=layer-45-sharpyuv "${PREFIX}/." "$PREFIX"
COPY --from=layer-45-vorbis "${PREFIX}/." "$PREFIX"
Expand Down Expand Up @@ -372,6 +399,12 @@ RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/50-theora.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-45 AS layer-50-va

RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/50-va.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-45 AS layer-50-vpx

RUN --mount=type=cache,target=/root/.cache `
Expand Down Expand Up @@ -421,6 +454,7 @@ COPY --from=layer-50-opus "${PREFIX}/." "$PREFIX"
COPY --from=layer-50-soxr "${PREFIX}/." "$PREFIX"
COPY --from=layer-50-svt-av1 "${PREFIX}/." "$PREFIX"
COPY --from=layer-50-theora "${PREFIX}/." "$PREFIX"
COPY --from=layer-50-va "${PREFIX}/." "$PREFIX"
COPY --from=layer-50-vpx "${PREFIX}/." "$PREFIX"
COPY --from=layer-50-vulkan "${PREFIX}/." "$PREFIX"
COPY --from=layer-50-x264 "${PREFIX}/." "$PREFIX"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Where `<TARGET>` is one of:
- aarch64-linux-gnu
- x86_64-linux-musl
- aarch64-linux-musl
- x86_64-linux-android
- aarch64-linux-android

> To build for iOS choose one of the `darwin` targets and pass `--build-arg OS_IPHONE=<1|2>` as an argument, `1` means iOS and `2` means iOS Simulator. Only iOS simulator supports `x86_64`.
Expand All @@ -36,18 +38,16 @@ After some time (it takes aroung 1~2 hours in Github CI) a directory named `out`

- Fortify linux-musl shared libs:
> https://git.2f30.org/fortify-headers/file/README.html
- Add stack check/protector to linux-musl shared libs
- Add stack check to windows dlls whenever zig adds support to it:
> https://github.com/ziglang/zig/blob/b3462b7/src/target.zig#L326-L329
- Add stack check/protector to linux arm64 glibc shared libs whenever zig fix the bug preventing it from working:
- Add stack check/protector to linux arm64 shared libs whenever zig fix the bug preventing it from working:
> https://github.com/ziglang/zig/issues/17430#issuecomment-1752592338
- Add support for pthread in windows builds:
> https://github.com/GerHobbelt/pthread-win32
> https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-libraries/winpthreads/
> https://github.com/msys2/MINGW-packages/blob/f4bd368/mingw-w64-winpthreads-git/PKGBUILD
- Add libplacebo and vulkan support for apple builds through MoltenVK:
> https://github.com/KhronosGroup/MoltenVK
- Investigate why mediafoundation fails to link to ffmpeg's libav* libs for windows builds
- Add Metal shader support for ffmpeg in apple builds:
> https://github.com/darlinghq/darling/issues/326
- Investigate why LTO fails at linking ffmpeg's libav* libs for windows builds
Expand Down
16 changes: 16 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@
{
"packageNames": ["bblanchon/pdfium-binaries"],
"extractVersion": "^chromium/(?<version>.+)$"
},
{
"packageNames": ["intel/libva"],
"extractVersion": "^(?<version>\\d+\\.\\d+\\.\\d+)$"
},
{
"packageNames": ["intel/libvpl"],
"extractVersion": "^v(?<version>\\d+\\.\\d+\\.\\d+)$"
},
{
"packageNames": ["drm/libdrm"],
"extractVersion": "^libdrm-(?<version>.+)$"
},
{
"packageNames": ["xorg/lib/libpciaccess"],
"extractVersion": "^libpciaccess-(?<version>.+)$"
}
]
}
18 changes: 18 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,28 @@ case "$TARGET" in
;;
esac

LLVM_BUILTIN='/usr/lib/llvm-17/lib/clang/17/lib'
case "$TARGET" in
*gnu)
CFLAGS="${CFLAGS} -D_GLIBCXX_ASSERTIONS=1"
;;
*musl)
CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
;;
*android*)
export SDKROOT="${NDK_SDKROOT:?Missing ndk sysroot}"
ANDROID_LIB="${SDKROOT}/usr/lib/${TARGET}"
CFLAGS="${CFLAGS} -D__ANDROID_API__=${ANDROID_API_LEVEL:?Missing android api level}"
LDFLAGS="-fuse-ld=$(command -v ld.lld-17) -B${ANDROID_LIB}/${ANDROID_API_LEVEL:?} -L${ANDROID_LIB}/${ANDROID_API_LEVEL:?} -L${ANDROID_LIB} -lm ${LDFLAGS}"
;;& # Resume switch/case matching from this point forward
x86_64-linux-android*)
# VERY UGLY HACK, no ideia why clang is not picking this up automatically
LDFLAGS="-L${LLVM_BUILTIN}/linux -lclang_rt.builtins-x86_64-android ${LDFLAGS}"
;;
aarch64-linux-android*)
# VERY UGLY HACK, no ideia why clang is not picking this up automatically
LDFLAGS="-L${LLVM_BUILTIN}/baremetal -L${LLVM_BUILTIN}/linux -lclang_rt.builtins-aarch64-android -lclang_rt.builtins-aarch64 ${LDFLAGS}"
;;
esac
;;
*darwin*)
Expand Down Expand Up @@ -179,6 +194,9 @@ cd /srv
# Make sure license directory exists
mkdir -p "${PREFIX}/licenses/"

OS_ANDROID="$(case "${TARGET##*-}" in android*) echo 1 ;; *) echo 0 ;; esac)"
export OS_ANDROID

# shellcheck disable=SC1091
. /srv/stage.sh
)
Expand Down
Loading

0 comments on commit b7c7afe

Please sign in to comment.