Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Android build target #73

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/build-and-test-make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ jobs:
host: aarch64-linux-musl
capture_interface: eth0
zigflags: -target aarch64-linux-musl -fPIC -mno-outline-atomics
- arch: i386
host: i386-linux-musl
capture_interface: eth0
zigflags: -target i386-linux-musl -fPIC -mno-outline-atomics
- arch: arm
host: arm-linux-gnueabihf
capture_interface: eth0
Expand Down Expand Up @@ -303,6 +299,7 @@ jobs:
- name: Run configure script
run: |
mkdir ${{ runner.temp }}/install
autoreconf -i
./configure LDFLAGS="-L$(brew --prefix zstd)/lib" CPPFLAGS="-I$(brew --prefix zstd)/include" --prefix=${{ runner.temp }}/install

# Cache the build of BoringSSL, which is the longest part of the build
Expand Down
231 changes: 231 additions & 0 deletions .github/workflows/build-android.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
name: Build for Android

on:
push:
branches:
- main
- feature/*
- bugfix/*
tags:
- "v*.*.*"
pull_request:
branches:
- main

permissions:
contents: write

env:
BORING_SSL_COMMIT: d24a38200fef19150eef00cad35b138936c08767
API: "21" # target android API version

jobs:
build-android:
name: Build curl-impersonate for Android
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- arch: aarch64
host: aarch64-linux-android
steps:
- name: Check out the repo
uses: actions/checkout@v2

- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r21e
local-cache: true

- name: Install Ubuntu dependencies
run: |
sudo apt-get update
sudo apt-get install build-essential pkg-config cmake ninja-build curl autoconf automake libtool
sudo apt-get install gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf
sudo apt-get install musl-tools musl-dev
# Chrome version dependencies
sudo apt-get install golang-go
# Needed to compile 'minicurl'
sudo apt-get install libcurl4-openssl-dev
# More dependencies for the tests
sudo apt-get install tcpdump nghttp2-server

- name: Build zlib
env:
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
curl -LO https://zlib.net/fossils/zlib-1.3.tar.gz
tar xf zlib-1.3.tar.gz
cd zlib-1.3
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=${{ matrix.host }}
export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
CHOST=${{ matrix.host }} ./configure --prefix=${{ runner.temp }}/zlib
make
make install
# Make sure curl will link with libz.so.1 and not libz.so
rm -f ${{ runner.temp }}/zlib/lib/libz.so

- name: Build libzstd
env:
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
curl -LO https://github.com/facebook/zstd/releases/download/v1.5.6/zstd-1.5.6.tar.gz
tar xf zstd-1.5.6.tar.gz
cd zstd-1.5.6
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=${{ matrix.host }}
make \
CC=$TOOLCHAIN/bin/$TARGET$API-clang \
AR=$TOOLCHAIN/bin/llvm-ar \
RANLIB=$TOOLCHAIN/bin/llvm-ranlib
mkdir -p ${{ runner.temp }}/zstd/lib
mkdir -p ${{ runner.temp }}/zstd/include
# move libzstd to runner.temp
cp lib/libzstd.a lib/libzstd.so.1.5.6 lib/libzstd.mk lib/libzstd.pc lib/libzstd.pc.in ${{ runner.temp }}/zstd/lib/
cp lib/zstd.h ${{ runner.temp }}/zstd/include/

- name: Run configure script
env:
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
mkdir ${{ runner.temp }}/install
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=${{ matrix.host }}
export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
./configure --prefix=${{ runner.temp }}/install \
--with-android=yes \
--host=${{ matrix.host }} \
--with-zlib=${{ runner.temp }}/zlib \
--with-zstd=${{ runner.temp }}/zstd \
--with-ca-path=/etc/ssl/certs \
--with-ca-bundle=/etc/ssl/certs/ca-certificates.crt

# Cache the build of BoringSSL, which is the longest part of the build
# We must cache the .zip as well, otherwise the Makefile will
# rebuild BoringSSL. This whole thing is a bit hacky, but necessary to
# reduce the insanely long build times.
- name: Cache BoringSSL source
uses: actions/cache@v4
with:
path: boringssl.zip
key: ${{ runner.os }}-${{ matrix.host }}-boring-source-${{ env.BORING_SSL_COMMIT }}

- name: Cache BoringSSL build
id: cache-boringssl
uses: actions/cache@v4
with:
path: boringssl/build
key: ${{ runner.os }}-${{ matrix.host }}-boring-build-${{ env.BORING_SSL_COMMIT }}-${{ hashFiles('chrome/patches/boringssl*.patch') }}

# Trick the Makefile into skipping the BoringSSL build step
# if it was found in the cache. See Makefile.in
- name: Post BoringSSL cache restore
if: ${{ steps.cache-boringssl.outputs.cache-hit != false }}
run: |
touch boringssl.zip
touch boringssl/.patched
find boringssl/build -type f | xargs touch

- name: Build the Chrome version of curl-impersonate
run: |
make chrome-build
make chrome-checkbuild

# Upload pre-compiled binaries to GitHub releases page and Github actions archives.
- name: Create tar release files for libcurl-impersonate
run: |
cp ${{ runner.temp }}/zlib/lib/lib*.a ${{ runner.temp }}/install/lib
cp ${{ runner.temp }}/zstd/lib/lib*.a ${{ runner.temp }}/install/lib
cp nghttp2*/installed/lib/lib*.a ${{ runner.temp }}/install/lib
cp brotli*/out/installed/lib/lib*.a ${{ runner.temp }}/install/lib
cp boringssl/build/lib/lib*.a ${{ runner.temp }}/install/lib

cd ${{ runner.temp }}/install/lib
ls -lah .
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
tar -c -z -f ${{ runner.temp }}/libcurl-impersonate-${{ github.ref_name }}.${{ matrix.host }}.tar.gz lib*
else
tar -c -z -f ${{ runner.temp }}/libcurl-impersonate.${{ matrix.host }}.tar.gz lib*
fi
echo "release_file_lib=${{ runner.temp }}/libcurl-impersonate-${{ github.ref_name }}.${{ matrix.host }}.tar.gz" >> $GITHUB_ENV

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: libcurl-impersonate.${{ matrix.host }}.tar.gz
path: ${{ runner.temp }}/libcurl-impersonate*.tar.gz

- name: Clean build
run: |
set -e
make chrome-clean
rm -Rf ${{ runner.temp }}/install
mkdir ${{ runner.temp }}/install

# Recompile curl-impersonate statically when doing a release.
- name: Reconfigure statically
env:
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
set -e
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=${{ matrix.host }}
export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
./configure --prefix=${{ runner.temp }}/install --enable-static \
--with-android=yes \
--host=${{ matrix.host }} \
--with-zlib=${{ runner.temp }}/zlib \
--with-zstd=${{ runner.temp }}/zstd \
--with-ca-path=/etc/ssl/certs \
--with-ca-bundle=/etc/ssl/certs/ca-certificates.crt \

- name: Rebuild statically
run: |
set -e
make chrome-build
make chrome-checkbuild

- name: Create tar release files for curl-impersonate
run: |
cd ${{ runner.temp }}/install/bin
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
tar -c -z -f ${{ runner.temp }}/curl-impersonate-${{ github.ref_name }}.${{ matrix.host }}.tar.gz curl-impersonate-chrome curl_*
else
tar -c -z -f ${{ runner.temp }}/curl-impersonate.${{ matrix.host }}.tar.gz curl-impersonate-chrome curl_*
fi
echo "release_file_bin=${{ runner.temp }}/curl-impersonate-${{ github.ref_name }}.${{ matrix.host }}.tar.gz" >> $GITHUB_ENV

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: curl-impersonate.${{ matrix.host }}.tar.gz
path: ${{ runner.temp }}/curl-impersonate*.tar.gz

- name: Upload release files
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
${{ env.release_file_lib }}
${{ env.release_file_bin }}
5 changes: 4 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ with_zstd = @with_zstd@
with_ca_bundle = @with_ca_bundle@
# Path to be passed to curl's --with-ca-path configure option.
with_ca_path = @with_ca_path@
# Extra cmake flags for android
EXTRA_CMAKE_FLAGS = @EXTRA_CMAKE_FLAGS@

CC = @CC@
CXX = @CXX@
Expand Down Expand Up @@ -191,6 +193,7 @@ $(boringssl_static_libs): boringssl.zip boringssl/.patched
-DCMAKE_C_COMPILER=$(CC) \
-DCMAKE_SYSTEM_NAME=$$system_name \
-DCMAKE_SYSTEM_PROCESSOR=$(host_cpu) \
$(EXTRA_CMAKE_FLAGS) \
-GNinja \
..
@ninja@ -j$(SUBJOBS)
Expand Down Expand Up @@ -278,7 +281,7 @@ $(CURL_VERSION)/.chrome: $(chrome_libs) $(CURL_VERSION).tar.gz $(CURL_VERSION)/.
if test -n "$(with_ca_path)"; then \
config_flags="$$config_flags --with-ca-path=$(with_ca_path)"; \
fi; \
add_libs="-pthread"; \
add_libs="-pthread -lssl -lcrypto -lc++"; \
}

echo "Configuring curl with: $$config_flags"
Expand Down
Loading
Loading