Skip to content

Commit

Permalink
Merge pull request #50 from lwthiker/macos_part1
Browse files Browse the repository at this point in the history
macOS initial support attempt
  • Loading branch information
lwthiker authored Apr 19, 2022
2 parents 8afee95 + 4b41e5b commit 3f1c350
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 88 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test-make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ jobs:
- name: Build the Chrome version of curl-impersonate
run: |
make chrome-build
make chrome-checkbuild
make chrome-install
- name: Build the Firefox version of curl-impersonate
run: |
make firefox-build
make firefox-checkbuild
make firefox-install
- name: Prepare the tests
Expand Down
25 changes: 16 additions & 9 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,9 @@ ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/ngh
RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL}
RUN tar xf ${NGHTTP2_VERSION}.tar.bz2

# Patch nghttp2 pkg config file to support static builds.
COPY patches/libnghttp2-*.patch ${NGHTTP2_VERSION}/
RUN cd ${NGHTTP2_VERSION} && \
for p in $(ls libnghttp2-*.patch); do patch -p1 < $p; done && \
autoreconf -i && automake && autoconf

# Compile nghttp2
RUN cd ${NGHTTP2_VERSION} && \
./configure --with-pic && \
./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \
make && make install

# Download curl.
Expand All @@ -148,7 +142,7 @@ RUN cd ${CURL_VERSION} && \
./configure --prefix=/build/install \
--enable-static \
--disable-shared \
--with-nghttp2=/usr/local \
--with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
--with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
{{#firefox}}
--with-nss=/build/${NSS_VERSION}/dist/Release \
Expand All @@ -173,12 +167,21 @@ RUN mkdir out && \
{{/chrome}}
strip out/curl-impersonate

# Verify that the resulting 'curl' has all the necessary features.
RUN ./out/curl-impersonate -V | grep -q zlib && \
./out/curl-impersonate -V | grep -q brotli && \
./out/curl-impersonate -V | grep -q nghttp2 && \
./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL

# Verify that the resulting 'curl' is really statically compiled
RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto)

RUN rm -Rf /build/install

# Re-compile libcurl dynamically
RUN cd ${CURL_VERSION} && \
./configure --prefix=/build/install \
--with-nghttp2=/usr/local \
--with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
--with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
{{#firefox}}
--with-nss=/build/${NSS_VERSION}/dist/Release \
Expand Down Expand Up @@ -208,6 +211,10 @@ RUN ver=$(readlink -f curl-7.81.0/lib/.libs/libcurl-impersonate-chrome.so | sed
ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \
strip "out/libcurl-impersonate.so.$ver"

# Verify that the resulting 'libcurl' is really statically compiled against its
# dependencies.
RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto)

# Wrapper scripts
{{#firefox}}
COPY curl_ff* out/
Expand Down
31 changes: 29 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ There are currently two build options depending on your use case:
There are two versions of `curl-impersonate` for technical reasons. The **chrome** version is used to impersonate Chrome, Edge and Safari. The **firefox** version is used to impersonate Firefox.

## Native build
Currently tested for Linux only. Work on porting to Mac is in progress.

### Linux (Ubuntu)

Install dependencies for building all the components:
```
Expand All @@ -18,7 +19,7 @@ sudo apt install build-essential pkg-config cmake ninja-build curl autoconf auto
sudo apt install python3-pip python-is-python3
pip install gyp-next
export PATH="$PATH:~/.local/bin" # Add gyp to PATH
# For the Chrome vesion only
# For the Chrome version only
sudo apt install golang-go
```

Expand Down Expand Up @@ -63,6 +64,32 @@ curl-impersonate-ff https://www.wikipedia.org
curl-impersonate-chrome https://www.wikipedia.org
```

### macOS
*macOS support is still a work in progress and currently supports the Chrome version only.*

Install dependencies for building all the components:
```
brew install pkg-config make cmake ninja autoconf automake libtool
# For the Chrome version only
brew install go
```

Generate the configure script:
```
autoconf
```

Configure and compile:
```
mkdir build && cd build
../configure
# Build and install the Chrome version
gmake chrome-build
sudo gmake chrome-install
# Optionally remove all the build files
cd ../ && rm -Rf build
```

### Static compilation
To compile curl-impersonate statically with libcurl-impersonate, pass `--enable-static` to the `configure` script.

Expand Down
53 changes: 32 additions & 21 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,58 @@ help: ## Show this help message
firefox-build: $(CURL_VERSION)/.firefox ## Build the Firefox version of curl-impersonate
cd $(CURL_VERSION)
# Don't pass this Makefile's MAKEFLAGS
make MAKEFLAGS=
$(MAKE) MAKEFLAGS=
.PHONY: firefox-build

firefox-checkbuild: ## Run basic checks on the built binary
cd $(CURL_VERSION)
# Make sure all needed features were compiled in
./src/curl-impersonate-ff -V | grep -q zlib
./src/curl-impersonate-ff -V | grep -q brotli
./src/curl-impersonate-ff -V | grep -q nghttp2
./src/curl-impersonate-ff -V | grep -q NSS
$(info Build OK)
.PHONY: firefox-checkbuild

firefox-install: ## Install the Firefox version of curl-impersonate after build
cd $(CURL_VERSION)
make install-exec MAKEFLAGS=
$(MAKE) install-exec MAKEFLAGS=
# Wrapper scripts for the Firefox version (e.g. 'curl_ff98')
cp -f $(srcdir)/firefox/curl_ff* @bindir@
.PHONY: firefox-install

firefox-uninstall: ## Uninstall the Firefox version of curl-impersonate after 'make install'
cd $(CURL_VERSION)
make uninstall MAKEFLAGS=
$(MAKE) uninstall MAKEFLAGS=
rm -Rf @bindir@/curl_ff*
.PHONY: firefox-uninstall

chrome-build: $(CURL_VERSION)/.chrome ## Build the Chrome version of curl-impersonate
cd $(CURL_VERSION)
# Don't pass this Makefile's MAKEFLAGS
make MAKEFLAGS=
$(MAKE) MAKEFLAGS=
.PHONY: chrome-build

chrome-checkbuild: ## Run basic checks on the built binary
cd $(CURL_VERSION)
# Make sure all needed features were compiled in
./src/curl-impersonate-chrome -V | grep -q zlib
./src/curl-impersonate-chrome -V | grep -q brotli
./src/curl-impersonate-chrome -V | grep -q nghttp2
./src/curl-impersonate-chrome -V | grep -q BoringSSL
$(info Build OK)
.PHONY: chrome-checkbuild

chrome-install: ## Install the Chrome version of curl-impersonate after build
cd $(CURL_VERSION)
make install-exec MAKEFLAGS=
$(MAKE) install-exec MAKEFLAGS=
# Wrapper scripts for the Chrome version (e.g. 'curl_chrome99')
cp -f $(srcdir)/chrome/curl_chrome* $(srcdir)/chrome/curl_edge* $(srcdir)/chrome/curl_safari* @bindir@
.PHONY: chrome-install

chrome-uninstall: ## Uninstall the Chrome version of curl-impersonate after 'make install'
cd $(CURL_VERSION)
make uninstall MAKEFLAGS=
$(MAKE) uninstall MAKEFLAGS=
rm -Rf @bindir@/curl_chrome* @bindir@/curl_edge* @bindir@/curl_safari*
.PHONY: chrome-uninstall

Expand Down Expand Up @@ -137,21 +157,12 @@ $(boringssl_static_libs): boringssl.zip boringssl/.patched
$(NGHTTP2_VERSION).tar.bz2:
curl -L $(NGHTTP2_URL) -o $(NGHTTP2_VERSION).tar.bz2

# Patch nghttp2 and use a dummy '.patched' file to mark it patched
$(NGHTTP2_VERSION)/.patched: $(srcdir)/firefox/patches/libnghttp2-*.patch
rm -Rf $(NGHTTP2_VERSION)
$(nghttp2_static_libs): $(NGHTTP2_VERSION).tar.bz2
tar -xf $(NGHTTP2_VERSION).tar.bz2
cd $(NGHTTP2_VERSION)
for p in $^; do patch -p1 < $$p; done
# Re-generate the configure script
autoreconf -i && automake && autoconf
touch .patched

$(nghttp2_static_libs): $(NGHTTP2_VERSION).tar.bz2 $(NGHTTP2_VERSION)/.patched
cd $(NGHTTP2_VERSION)
./configure --prefix=$(nghttp2_install_dir) --with-pic
make MAKEFLAGS=
make install MAKEFLAGS=
./configure --prefix=$(nghttp2_install_dir) --with-pic --disable-shared
$(MAKE) MAKEFLAGS=
$(MAKE) install MAKEFLAGS=

$(CURL_VERSION).tar.xz:
curl -L "https://curl.se/download/$(CURL_VERSION).tar.xz" \
Expand Down Expand Up @@ -190,7 +201,7 @@ $(CURL_VERSION)/.firefox: $(firefox_libs) $(CURL_VERSION).tar.xz $(CURL_VERSION)
USE_CURL_SSLKEYLOGFILE=true \
CFLAGS="-I$(nss_install_dir)/../public/nss -I$(nss_install_dir)/include/nspr"
# Remove possible leftovers from a previous compilation
make clean MAKEFLAGS=
$(MAKE) clean MAKEFLAGS=
touch .firefox
# Remove the Chrome flag if it exists
rm -f .chrome
Expand All @@ -207,7 +218,7 @@ $(CURL_VERSION)/.chrome: $(chrome_libs) $(CURL_VERSION).tar.xz $(CURL_VERSION)/.
LIBS="-pthread" \
CFLAGS="-I$(boringssl_install_dir)"
# Remove possible leftovers from a previous compilation
make clean MAKEFLAGS=
$(MAKE) clean MAKEFLAGS=
touch .chrome
# Remove the Firefox flag if it exists
rm -f .firefox
25 changes: 16 additions & 9 deletions chrome/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,9 @@ ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/ngh
RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL}
RUN tar xf ${NGHTTP2_VERSION}.tar.bz2

# Patch nghttp2 pkg config file to support static builds.
COPY patches/libnghttp2-*.patch ${NGHTTP2_VERSION}/
RUN cd ${NGHTTP2_VERSION} && \
for p in $(ls libnghttp2-*.patch); do patch -p1 < $p; done && \
autoreconf -i && automake && autoconf

# Compile nghttp2
RUN cd ${NGHTTP2_VERSION} && \
./configure --with-pic && \
./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \
make && make install

# Download curl.
Expand All @@ -89,7 +83,7 @@ RUN cd ${CURL_VERSION} && \
./configure --prefix=/build/install \
--enable-static \
--disable-shared \
--with-nghttp2=/usr/local \
--with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
--with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
--with-openssl=/build/boringssl/build \
LIBS="-pthread" \
Expand All @@ -102,12 +96,21 @@ RUN mkdir out && \
ln -s curl-impersonate-chrome out/curl-impersonate && \
strip out/curl-impersonate

# Verify that the resulting 'curl' has all the necessary features.
RUN ./out/curl-impersonate -V | grep -q zlib && \
./out/curl-impersonate -V | grep -q brotli && \
./out/curl-impersonate -V | grep -q nghttp2 && \
./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL

# Verify that the resulting 'curl' is really statically compiled
RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto)

RUN rm -Rf /build/install

# Re-compile libcurl dynamically
RUN cd ${CURL_VERSION} && \
./configure --prefix=/build/install \
--with-nghttp2=/usr/local \
--with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
--with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
--with-openssl=/build/boringssl/build \
LIBS="-pthread" \
Expand All @@ -124,6 +127,10 @@ RUN ver=$(readlink -f curl-7.81.0/lib/.libs/libcurl-impersonate-chrome.so | sed
ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \
strip "out/libcurl-impersonate.so.$ver"

# Verify that the resulting 'libcurl' is really statically compiled against its
# dependencies.
RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto)

# Wrapper scripts
COPY curl_chrome* curl_edge* curl_safari* out/
RUN chmod +x out/curl_*
25 changes: 16 additions & 9 deletions chrome/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,9 @@ ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/ngh
RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL}
RUN tar xf ${NGHTTP2_VERSION}.tar.bz2

# Patch nghttp2 pkg config file to support static builds.
COPY patches/libnghttp2-*.patch ${NGHTTP2_VERSION}/
RUN cd ${NGHTTP2_VERSION} && \
for p in $(ls libnghttp2-*.patch); do patch -p1 < $p; done && \
autoreconf -i && automake && autoconf

# Compile nghttp2
RUN cd ${NGHTTP2_VERSION} && \
./configure --with-pic && \
./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \
make && make install

# Download curl.
Expand All @@ -86,7 +80,7 @@ RUN cd ${CURL_VERSION} && \
./configure --prefix=/build/install \
--enable-static \
--disable-shared \
--with-nghttp2=/usr/local \
--with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
--with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
--with-openssl=/build/boringssl/build \
LIBS="-pthread" \
Expand All @@ -99,12 +93,21 @@ RUN mkdir out && \
ln -s curl-impersonate-chrome out/curl-impersonate && \
strip out/curl-impersonate

# Verify that the resulting 'curl' has all the necessary features.
RUN ./out/curl-impersonate -V | grep -q zlib && \
./out/curl-impersonate -V | grep -q brotli && \
./out/curl-impersonate -V | grep -q nghttp2 && \
./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL

# Verify that the resulting 'curl' is really statically compiled
RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto)

RUN rm -Rf /build/install

# Re-compile libcurl dynamically
RUN cd ${CURL_VERSION} && \
./configure --prefix=/build/install \
--with-nghttp2=/usr/local \
--with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
--with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
--with-openssl=/build/boringssl/build \
LIBS="-pthread" \
Expand All @@ -121,6 +124,10 @@ RUN ver=$(readlink -f curl-7.81.0/lib/.libs/libcurl-impersonate-chrome.so | sed
ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \
strip "out/libcurl-impersonate.so.$ver"

# Verify that the resulting 'libcurl' is really statically compiled against its
# dependencies.
RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto)

# Wrapper scripts
COPY curl_chrome* curl_edge* curl_safari* out/
# Replace /bin/bash with /bin/ash
Expand Down
4 changes: 2 additions & 2 deletions chrome/patches/curl-impersonate.patch
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ index 3e55230ee..e3ea22b96 100644
# List of files required to generate VC IDE .dsp, .vcproj and .vcxproj files
include lib/Makefile.inc
diff --git a/configure.ac b/configure.ac
index 63e320236..8c41e8501 100644
index 63e320236..86ab654c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1331,7 +1331,8 @@ if test X"$OPT_BROTLI" != Xno; then
Expand All @@ -28,7 +28,7 @@ index 63e320236..8c41e8501 100644
if test -n "$PREFIX_BROTLI"; then
- LIB_BROTLI="-lbrotlidec"
+ # curl-impersonate: Use static libbrotli
+ LIB_BROTLI="-Wl,-Bstatic -lbrotlidec-static -lbrotlicommon-static -Wl,-Bdynamic"
+ LIB_BROTLI="-lbrotlidec-static -lbrotlicommon-static"
LD_BROTLI=-L${PREFIX_BROTLI}/lib$libsuff
CPP_BROTLI=-I${PREFIX_BROTLI}/include
DIR_BROTLI=${PREFIX_BROTLI}/lib$libsuff
Expand Down
8 changes: 0 additions & 8 deletions chrome/patches/libnghttp2-pc.patch

This file was deleted.

Loading

0 comments on commit 3f1c350

Please sign in to comment.