From e8878ed30ebfe4e3b099a98e271a0d9ad8ddba5c Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 10:03:28 +0800 Subject: [PATCH 01/22] Move windows build script from other project --- .github/workflows/build-win.yaml | 78 ++++++++++++++++++++++++++++++++ win/build.sh | 72 +++++++++++++++++++++++++++++ win/dll2lib.bat | 29 ++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 .github/workflows/build-win.yaml create mode 100644 win/build.sh create mode 100644 win/dll2lib.bat diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml new file mode 100644 index 00000000..b0af8937 --- /dev/null +++ b/.github/workflows/build-win.yaml @@ -0,0 +1,78 @@ +name: Build for windows +on: + push: + branches: + - main + tags: + - "v*.*.*" + pull_request: + branches: + - main + +permissions: + contents: write + +env: + NSS_VERSION: nss-3.77 + BORING_SSL_COMMIT: d24a38200fef19150eef00cad35b138936c08767 + +jobs: + build-windows: + name: Build windows binaries + runs-on: windows-2019 + steps: + - name: configure Pagefile + uses: al-cheb/configure-pagefile-action@v1.3 + with: + minimum-size: 16GB + maximum-size: 16GB + disk-root: "C:" + + - name: Install python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Check out the repo + uses: actions/checkout@v2 + + - uses: msys2/setup-msys2@v2 + name: Install msys + with: + update: true + install: >- + git + patch + mingw-w64-x86_64-make + mingw-w64-x86_64-cmake + mingw-w64-x86_64-nasm + mingw-w64-x86_64-gcc + mingw-w64-x86_64-go + + - name: Run configure script + shell: msys2 {0} + run: | + mkdir ${{ runner.temp }}/install + ./configure --prefix=${{ runner.temp }}/install + + # - name: Setup tmate session for debugging + # uses: mxschmitt/action-tmate@v3 + + - name: Copy and patch + shell: msys2 {0} + run: ./build.sh + + - uses: ilammy/msvc-dev-cmd@v1 + + - name: Generate lib files + run: ./dll2lib.bat 64 dist\libcurl.dll + + - name: Build tarball + shell: msys2 {0} + run: tar cvzf curl-impersonate-chrome.tar.gz -C dist . + + - name: Upload release files + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: curl-impersonate-chrome.tar.gz diff --git a/win/build.sh b/win/build.sh new file mode 100644 index 00000000..7779fb52 --- /dev/null +++ b/win/build.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +set -ex + +cd boringssl + +rm -rf lib +git checkout -- . +patchfile=../curl-impersonate/chrome/patches/boringssl-old-ciphers.patch +patch -p1 < $patchfile +sed -i 's/-ggdb//g' CMakeLists.txt +sed -i 's/-Werror//g' CMakeLists.txt + +cd .. + +cd curl + +git checkout -- . +git clean -f +patchfile=../curl-impersonate/chrome/patches/curl-impersonate.patch +patch -p1 < $patchfile + +sed -i 's/-shared/-s -static -shared/g' lib/Makefile.mk +sed -i 's/-static/-s -static/g' src/Makefile.mk + +sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' lib/Makefile.mk +sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' src/Makefile.mk + +sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' lib/Makefile.mk +sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' src/Makefile.mk + +cd .. + +cd boringssl + +rm -rf lib +cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe +ninja -C lib crypto ssl +mv lib/crypto/libcrypto.a lib/libcrypto.a +mv lib/ssl/libssl.a lib/libssl.a + +cd .. + +export IPV6=1 +export ZLIB=1 +export ZLIB_PATH=zlib_stub +export ZSTD=1 +export ZSTD_PATH=zstd_stub +export BROTLI=1 +export BROTLI_PATH=brotli_stub +export BROTLI_LIBS='-lbrotlidec -lbrotlicommon' +export NGHTTP2=1 +export NGHTTP2_PATH=nghttp2_stub +export IDN2=1 +export LIBIDN2_PATH=idn2_stub +export SSL=1 +export OPENSSL_PATH=$PWD/boringssl +export OPENSSL_LIBPATH=$PWD/boringssl/lib +export OPENSSL_LIBS='-lssl -lcrypto' +export HTTP2=1 +export WEBSOCKETS=1 + +cd curl +mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable +mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable + +mkdir -p ../dist +mv lib/libcurl* ../dist/ +mv src/*.exe ../dist/ + +cd .. +dist/curl -V diff --git a/win/dll2lib.bat b/win/dll2lib.bat new file mode 100644 index 00000000..1886a616 --- /dev/null +++ b/win/dll2lib.bat @@ -0,0 +1,29 @@ +REM Usage: dll2lib [32|64] some-file.dll +REM +REM Generates some-file.lib from some-file.dll, making an intermediate +REM some-file.def from the results of dumpbin /exports some-file.dll. +REM Currently must run without path on DLL. +REM (Fix by removing path when of lib_name for LIBRARY line below?) +REM +REM Requires 'dumpbin' and 'lib' in PATH - run from VS developer prompt. +REM +REM Script inspired by http://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll +SETLOCAL +if "%1"=="32" (set machine=x86) else (set machine=x64) +set dll_file=%2 +set dll_file_no_ext=%dll_file:~0,-4% +set exports_file=%dll_file_no_ext%-exports.txt +set def_file=%dll_file_no_ext%.def +set lib_file=%dll_file_no_ext%.lib +set lib_name=%dll_file_no_ext% + +dumpbin /exports %dll_file% > %exports_file% + +echo LIBRARY %lib_name% > %def_file% +echo EXPORTS >> %def_file% +for /f "skip=19 tokens=1,4" %%A in (%exports_file%) do if NOT "%%B" == "" (echo %%B @%%A >> %def_file%) + +lib /def:%def_file% /out:%lib_file% /machine:%machine% + +REM Clean up temporary intermediate files +del %exports_file% %def_file% %dll_file_no_ext%.exp From 92de30ee2ab4d5e3e018913d61a865306240dc32 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 13:57:42 +0800 Subject: [PATCH 02/22] Add Makefile for debugging --- Makefile.win | 330 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 Makefile.win diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 00000000..d27ebd32 --- /dev/null +++ b/Makefile.win @@ -0,0 +1,330 @@ +# Makefile to build curl-impersonate +# Some Makefile tricks were taken from https://tech.davis-hansson.com/p/make/ + +SHELL := bash +.ONESHELL: +.SHELLFLAGS := -euc +.DELETE_ON_ERROR: +# MAKEFLAGS += --warn-undefined-variables +# MAKEFLAGS += --no-builtin-rules + +BROTLI_VERSION := 1.0.9 + # In case this is changed, update build-and-test-make.yml as well +BORING_SSL_COMMIT := d24a38200fef19150eef00cad35b138936c08767 +NGHTTP2_VERSION := nghttp2-1.56.0 +NGHTTP2_URL := https://github.com/nghttp2/nghttp2/releases/download/v1.56.0/nghttp2-1.56.0.tar.bz2 +CURL_VERSION := curl-8.1.1 + +brotli_install_dir := $(abspath brotli-$(BROTLI_VERSION)/out/installed) +brotli_static_libs := $(brotli_install_dir)/lib/libbrotlicommon-static.a $(brotli_install_dir)/lib/libbrotlidec-static.a +boringssl_install_dir := $(abspath boringssl/build) +boringssl_static_libs := $(boringssl_install_dir)/lib/libssl.a $(boringssl_install_dir)/lib/libcrypto.a +nghttp2_install_dir := $(abspath $(NGHTTP2_VERSION)/installed) +nghttp2_static_libs := $(nghttp2_install_dir)/lib/libnghttp2.a + +# Dependencies needed to compile the Chrome version +chrome_libs := $(brotli_static_libs) $(boringssl_static_libs) $(nghttp2_static_libs) + +# The following variables will be set by the configure script. +prefix = /usr/local +exec_prefix = ${prefix} +srcdir = /Users/yifei/repos/curl-impersonate/build/.. +host = aarch64-apple-darwin23.0.0 +host_alias = +host_cpu = aarch64 +host_os = darwin23.0.0 +build = aarch64-apple-darwin23.0.0 +# Whether to link curl-impersonate with libcurl-impersonate statically. +static_build = no +# Whether the user provided a specific find for zlib +with_zlib = +# Path to be passed to curl's --with-ca-bundle configure option. +with_ca_bundle = +# Path to be passed to curl's --with-ca-path configure option. +with_ca_path = +# Path to be passed to curl's --with-libnssckbi configure option (an option +# added for curl-impersonate). +with_libnssckbi = + +CC = gcc +CXX = g++ +STRIP = strip + +# Auto-generate Makefile help. +# Borrowed from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +help: ## Show this help message + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' +.PHONY: help +.DEFAULT_GOAL := help + +chrome-build: $(CURL_VERSION)/.chrome ## Build the Chrome version of curl-impersonate + cd $(CURL_VERSION) + # Don't pass this Makefile's MAKEFLAGS + $(MAKE) MAKEFLAGS= +.PHONY: chrome-build + +chrome-checkbuild: ## Run basic checks on the built binary +ifeq ($(host),$(build)) + 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) +else + $(info Cross compiling, skipping checkbuild) +endif +.PHONY: chrome-checkbuild + +chrome-install: ## Install the Chrome version of curl-impersonate after build + cd $(CURL_VERSION) + $(MAKE) install-exec MAKEFLAGS= + # Wrapper scripts for the Chrome version (e.g. 'curl_chrome99') + install $(srcdir)/chrome/curl_chrome* $(srcdir)/chrome/curl_edge* $(srcdir)/chrome/curl_safari* ${exec_prefix}/bin +.PHONY: chrome-install + +chrome-install-strip: ## Like 'chrome-install', but strip binaries for smaller size + cd $(CURL_VERSION) + $(MAKE) install-exec MAKEFLAGS= + # We could have used 'install-strip' but then the docs would be installed as well. + # Instead strip manually. + $(STRIP) ${exec_prefix}/bin/curl-impersonate-chrome + # Wrapper scripts for the Chrome version (e.g. 'curl_chrome99') + install $(srcdir)/chrome/curl_chrome* $(srcdir)/chrome/curl_edge* $(srcdir)/chrome/curl_safari* ${exec_prefix}/bin +.PHONY: chrome-install-strip + +chrome-uninstall: ## Uninstall the Chrome version of curl-impersonate after 'make install' + cd $(CURL_VERSION) + $(MAKE) uninstall MAKEFLAGS= + rm -Rf ${exec_prefix}/bin/curl_chrome* ${exec_prefix}/bin/curl_edge* ${exec_prefix}/bin/curl_safari* +.PHONY: chrome-uninstall + +chrome-clean: ## Clean build artifacts of the Chrome version. Use after re-running './configure' + cd $(CURL_VERSION) + $(MAKE) clean MAKEFLAGS= + rm -f .chrome +.PHONY: chrome-clean + +clean: ## Remove all build artifacts, including dependencies + rm -Rf brotli-$(BROTLI_VERSION).tar.gz brotli-$(BROTLI_VERSION) + rm -Rf $(NSS_VERSION).tar.gz $(NSS_VERSION) + rm -Rf boringssl.zip boringssl + rm -Rf $(NGHTTP2_VERSION).tar.bz2 $(NGHTTP2_VERSION) + rm -Rf $(CURL_VERSION).tar.xz $(CURL_VERSION) + +brotli-$(BROTLI_VERSION).tar.gz: + curl -L "https://github.com/google/brotli/archive/refs/tags/v${BROTLI_VERSION}.tar.gz" \ + -o "brotli-${BROTLI_VERSION}.tar.gz" + +$(brotli_static_libs): brotli-$(BROTLI_VERSION).tar.gz + tar xf brotli-$(BROTLI_VERSION).tar.gz + cd brotli-$(BROTLI_VERSION) + mkdir -p out + cd out + + # Convert autoconf style os name to CMake style os name. + case $(host_os) in \ + linux*) \ + system_name=Linux \ + ;; \ + darwin*) \ + system_name=Darwin \ + ;; \ + *) \ + system_name=$(host_os) \ + ;; \ + esac + + cmake -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=./installed \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_CXX_COMPILER=$(CXX) \ + -DCMAKE_C_COMPILER=$(CC) \ + -DCMAKE_SYSTEM_NAME=$$system_name \ + -DCMAKE_SYSTEM_PROCESSOR=$(host_cpu) \ + .. + + cmake --build . --config Release --target install + + +$(NSS_VERSION).tar.gz: + curl -L -o $(NSS_VERSION).tar.gz $(NSS_URL) + +$(nss_static_libs): $(NSS_VERSION).tar.gz + tar xf $(NSS_VERSION).tar.gz + +ifeq ($(host),$(build)) + # Native build, use NSS' build script. + cd $(NSS_VERSION)/nss + ./build.sh -o --disable-tests --static --python=python3 +else + # We are cross compiling. + # Cross compiling NSS is not supported by its build script and is poorly + # documented. We need to compile NSPR manually and only then compile nss. + case $(host_cpu) in \ + *64*) \ + use_64="1"; \ + nspr_configure_flags="--enable-64bit"; \ + ;; \ + *) \ + use_64="0"; \ + nspr_configure_flags=""; \ + ;; \ + esac + + # Cross-compile nspr separately + cd $(NSS_VERSION)/nspr + ./configure --prefix=$(nss_install_dir) \ + --disable-debug --enable-optimize \ + --target=$(host_alias) \ + $$nspr_configure_flags + $(MAKE) MAKEFLAGS= + $(MAKE) install MAKEFLAGS= + + # Now we can run ./build.sh with the already built nspr + cd ../nss + CC=$(CC) CXX=$(CXX) CCC=$(CXX) \ + ./build.sh -o --disable-tests --static --python=python3 \ + --with-nspr=$(nss_install_dir)/include/nspr:$(nss_install_dir)/lib \ + --target=$(host_cpu) \ + -Duse_system_zlib=0 \ + -Dsign_libs=0 +endif + # Hack for macOS: Remove dynamic libraries to force the linker to use the + # static ones when linking curl. + rm -Rf $(nss_install_dir)/lib/*.dylib + + +boringssl.zip: + curl -L https://github.com/google/boringssl/archive/$(BORING_SSL_COMMIT).zip \ + -o boringssl.zip + +# Patch boringssl and use a dummy '.patched' file to mark it patched +boringssl/.patched: $(srcdir)/chrome/patches/boringssl-*.patch + unzip -q -o boringssl.zip + mv boringssl-$(BORING_SSL_COMMIT) boringssl + cd boringssl/ + for p in $^; do patch -p1 < $$p; done + touch .patched + +$(boringssl_static_libs): boringssl.zip boringssl/.patched + mkdir -p $(boringssl_install_dir) + cd $(boringssl_install_dir) + + # Convert autoconf style os name to CMake style os name. + case $(host_os) in \ + linux*) \ + system_name=Linux \ + ;; \ + darwin*) \ + system_name=Darwin \ + ;; \ + *) \ + system_name=Linux \ + ;; \ + esac + + # The extra CMAKE_C_FLAGS are needed because otherwise boringssl fails to + # compile in release mode on some systems with gcc 12 (e.g. Fedora). + # In addition, guard these options with -Wno-unknown-warning-option to + # prevent clang from failing on them. + cmake -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_POSITION_INDEPENDENT_CODE=on \ + -DCMAKE_C_FLAGS="-Wno-unknown-warning-option -Wno-stringop-overflow -Wno-array-bounds" \ + -DCMAKE_CXX_COMPILER=$(CXX) \ + -DCMAKE_C_COMPILER=$(CC) \ + -DCMAKE_SYSTEM_NAME=$$system_name \ + -DCMAKE_SYSTEM_PROCESSOR=$(host_cpu) \ + -GNinja \ + .. + ninja + # Fix the directory structure so that curl can compile against it. + # See https://everything.curl.dev/source/build/tls/boringssl + mkdir -p lib + ln -sf ../crypto/libcrypto.a lib/libcrypto.a + ln -sf ../ssl/libssl.a lib/libssl.a + cp -Rf ../include . + + +$(NGHTTP2_VERSION).tar.bz2: + curl -L $(NGHTTP2_URL) -o $(NGHTTP2_VERSION).tar.bz2 + +$(nghttp2_static_libs): $(NGHTTP2_VERSION).tar.bz2 + tar -xf $(NGHTTP2_VERSION).tar.bz2 + cd $(NGHTTP2_VERSION) + + # Set up the configure flags to nghttp2. + # If the user provided the --host flag to our configure script + # (for cross compilation), then pass it on to nghttp2. + { \ + config_flags="--prefix=$(nghttp2_install_dir)"; \ + config_flags="$$config_flags --with-pic --enable-lib-only"; \ + config_flags="$$config_flags --disable-shared --disable-python-bindings"; \ + if test -n "$(host_alias)"; then \ + config_flags="$$config_flags --host=$(host_alias)"; \ + fi; \ + } + + ./configure $$config_flags + $(MAKE) MAKEFLAGS= + $(MAKE) install MAKEFLAGS= + +$(CURL_VERSION).tar.xz: + curl -L "https://curl.se/download/$(CURL_VERSION).tar.xz" \ + -o "$(CURL_VERSION).tar.xz" + +# Apply the "Chorme version" patches and mark using a dummy file +$(CURL_VERSION)/.patched-chrome: $(srcdir)/chrome/patches/curl-*.patch + rm -Rf $(CURL_VERSION) + tar -xf $(CURL_VERSION).tar.xz + cd $(CURL_VERSION) + for p in $^; do patch -p1 < $$p; done + # Re-generate the configure script + autoreconf -fi + touch .patched-chrome + rm -f .patched-ff + +# This is a small hack that flags that curl was patched and configured in the "chrome" version +$(CURL_VERSION)/.chrome: $(chrome_libs) $(CURL_VERSION).tar.xz $(CURL_VERSION)/.patched-chrome + cd $(CURL_VERSION) + + # Set up the configure flags to curl. + # If the user provided the --host flag to our configure script + # (for cross compilation), then pass it on to curl. + { \ + config_flags="--prefix=/usr/local"; \ + config_flags="$$config_flags --with-nghttp2=$(nghttp2_install_dir)"; \ + config_flags="$$config_flags --with-brotli=$(brotli_install_dir)"; \ + config_flags="$$config_flags --with-openssl=$(boringssl_install_dir)"; \ + config_flags="$$config_flags --without-zstd"; \ + config_flags="$$config_flags --enable-websockets"; \ + config_flags="$$config_flags --enable-ech"; \ + config_flags="$$config_flags USE_CURL_SSLKEYLOGFILE=true"; \ + if test "$(static_build)" = "yes"; then \ + config_flags="$$config_flags --enable-static --disable-shared"; + fi; \ + if test -n "$(host_alias)"; then \ + config_flags="$$config_flags --host=$(host_alias)"; \ + fi; \ + if test -n "$(with_zlib)"; then \ + config_flags="$$config_flags --with-zlib=$(with_zlib)"; \ + else \ + config_flags+=" --with-zlib"; \ + fi; \ + if test -n "$(with_ca_bundle)"; then \ + config_flags="$$config_flags --with-ca-bundle=$(with_ca_bundle)"; \ + fi; \ + if test -n "$(with_ca_path)"; then \ + config_flags="$$config_flags --with-ca-path=$(with_ca_path)"; \ + fi; \ + add_libs="-pthread"; \ + } + + echo "Configuring curl with: $$config_flags" + + ./configure $$config_flags LIBS="$$add_libs" + + # Remove possible leftovers from a previous compilation + $(MAKE) clean MAKEFLAGS= + touch .chrome From cce3a52dd59bede7397b3c9eda849fd456ab2eeb Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 21:35:08 +0800 Subject: [PATCH 03/22] First attempt for winbuild --- .github/workflows/build-win.yaml | 1 + win/build.sh | 62 +++++++++++++++++--------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index b0af8937..07f09d6b 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -3,6 +3,7 @@ on: push: branches: - main + - feature/* tags: - "v*.*.*" pull_request: diff --git a/win/build.sh b/win/build.sh index 7779fb52..93d8a508 100644 --- a/win/build.sh +++ b/win/build.sh @@ -2,38 +2,23 @@ set -ex -cd boringssl +mkdir build/ +cd build/ -rm -rf lib -git checkout -- . -patchfile=../curl-impersonate/chrome/patches/boringssl-old-ciphers.patch -patch -p1 < $patchfile -sed -i 's/-ggdb//g' CMakeLists.txt -sed -i 's/-Werror//g' CMakeLists.txt +# Download and patch boringssl -cd .. +BORING_SSL_COMMIT=d24a38200fef19150eef00cad35b138936c08767 +curl -L https://github.com/google/boringssl/archive/$(BORING_SSL_COMMIT).zip -o boringssl.zip +unzip -q -o boringssl.zip +mv boringssl-$(BORING_SSL_COMMIT) boringssl -cd curl +cd boringssl -git checkout -- . -git clean -f -patchfile=../curl-impersonate/chrome/patches/curl-impersonate.patch +patchfile=../../chrome/patches/boringssl-old-ciphers.patch patch -p1 < $patchfile +sed -i 's/-ggdb//g' CMakeLists.txt +sed -i 's/-Werror//g' CMakeLists.txt -sed -i 's/-shared/-s -static -shared/g' lib/Makefile.mk -sed -i 's/-static/-s -static/g' src/Makefile.mk - -sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' lib/Makefile.mk -sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' src/Makefile.mk - -sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' lib/Makefile.mk -sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' src/Makefile.mk - -cd .. - -cd boringssl - -rm -rf lib cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe ninja -C lib crypto ssl mv lib/crypto/libcrypto.a lib/libcrypto.a @@ -59,10 +44,31 @@ export OPENSSL_LIBPATH=$PWD/boringssl/lib export OPENSSL_LIBS='-lssl -lcrypto' export HTTP2=1 export WEBSOCKETS=1 +export ECH=1 + +CURL_VERSION=curl-8.1.1 + +curl -L "https://curl.se/download/$(CURL_VERSION).tar.xz" \ + -o "$(CURL_VERSION).tar.xz" +tar -xf $(CURL_VERSION).tar.xz +mv $(CURL_VERSION) curl cd curl -mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable -mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable + +patchfile=../../chrome/patches/curl-impersonate.patch +patch -p1 < $patchfile + +sed -i 's/-shared/-s -static -shared/g' lib/Makefile.mk +sed -i 's/-static/-s -static/g' src/Makefile.mk + +sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' lib/Makefile.mk +sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' src/Makefile.mk + +sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' lib/Makefile.mk +sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' src/Makefile.mk + +# mingw32-make mingw32-clean CFLAGS=-Wno-unused-variable +mingw32-make mingw32 -j CFLAGS=-Wno-unused-variable mkdir -p ../dist mv lib/libcurl* ../dist/ From b055926c592beb0a03d3461db80d8cbb4b65d773 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 21:40:56 +0800 Subject: [PATCH 04/22] Remove configure script --- .github/workflows/build-win.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index 07f09d6b..7e0475ce 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -50,12 +50,6 @@ jobs: mingw-w64-x86_64-gcc mingw-w64-x86_64-go - - name: Run configure script - shell: msys2 {0} - run: | - mkdir ${{ runner.temp }}/install - ./configure --prefix=${{ runner.temp }}/install - # - name: Setup tmate session for debugging # uses: mxschmitt/action-tmate@v3 From f3d73248ee31d1817d22a8574fc3466802548032 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 21:42:36 +0800 Subject: [PATCH 05/22] Fix directories --- .github/workflows/build-win.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index 7e0475ce..8f4d840e 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -55,12 +55,12 @@ jobs: - name: Copy and patch shell: msys2 {0} - run: ./build.sh + run: ./win/build.sh - uses: ilammy/msvc-dev-cmd@v1 - name: Generate lib files - run: ./dll2lib.bat 64 dist\libcurl.dll + run: ./win/dll2lib.bat 64 dist\libcurl.dll - name: Build tarball shell: msys2 {0} From 300bdeeef56c38ee9b5c8ff377b4cdd597c79a72 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 21:48:37 +0800 Subject: [PATCH 06/22] Fix directories again --- .github/workflows/build-win.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index 8f4d840e..bced4133 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -44,6 +44,12 @@ jobs: install: >- git patch + unzip + mingw-w64-x86_64-brotli + mingw-w64-x86_64-libidn2 + mingw-w64-x86_64-zstd + mingw-w64-x86_64-nghttp2 + mingw-w64-x86_64-zlib mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-nasm @@ -60,11 +66,11 @@ jobs: - uses: ilammy/msvc-dev-cmd@v1 - name: Generate lib files - run: ./win/dll2lib.bat 64 dist\libcurl.dll + run: ./win/dll2lib.bat 64 build\dist\libcurl.dll - name: Build tarball shell: msys2 {0} - run: tar cvzf curl-impersonate-chrome.tar.gz -C dist . + run: tar cvzf curl-impersonate-chrome.tar.gz -C ./build/dist . - name: Upload release files uses: softprops/action-gh-release@v1 From defd23bcae15b0eaf47eefcda2e9d8da587e5dea Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 21:55:23 +0800 Subject: [PATCH 07/22] Fix shell vars --- win/build.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/win/build.sh b/win/build.sh index 93d8a508..ac18907a 100644 --- a/win/build.sh +++ b/win/build.sh @@ -8,9 +8,9 @@ cd build/ # Download and patch boringssl BORING_SSL_COMMIT=d24a38200fef19150eef00cad35b138936c08767 -curl -L https://github.com/google/boringssl/archive/$(BORING_SSL_COMMIT).zip -o boringssl.zip +curl -L https://github.com/google/boringssl/archive/${BORING_SSL_COMMIT}.zip -o boringssl.zip unzip -q -o boringssl.zip -mv boringssl-$(BORING_SSL_COMMIT) boringssl +mv boringssl-${BORING_SSL_COMMIT} boringssl cd boringssl @@ -48,10 +48,10 @@ export ECH=1 CURL_VERSION=curl-8.1.1 -curl -L "https://curl.se/download/$(CURL_VERSION).tar.xz" \ - -o "$(CURL_VERSION).tar.xz" -tar -xf $(CURL_VERSION).tar.xz -mv $(CURL_VERSION) curl +curl -L "https://curl.se/download/${CURL_VERSION}.tar.xz" \ + -o "${CURL_VERSION}.tar.xz" +tar -xf ${CURL_VERSION}.tar.xz +mv ${CURL_VERSION} curl cd curl From e8eaefaf2eccfd950fd53832c4463c0408c800ab Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 22:10:59 +0800 Subject: [PATCH 08/22] why not building with libs --- win/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win/build.sh b/win/build.sh index ac18907a..aa289608 100644 --- a/win/build.sh +++ b/win/build.sh @@ -67,8 +67,8 @@ sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' src/Makefile.mk sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' lib/Makefile.mk sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' src/Makefile.mk -# mingw32-make mingw32-clean CFLAGS=-Wno-unused-variable -mingw32-make mingw32 -j CFLAGS=-Wno-unused-variable +mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable +mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable mkdir -p ../dist mv lib/libcurl* ../dist/ From 1ddfa2ff6faab969a2fd85082d4e0fd3a4ae5e1f Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 22:15:25 +0800 Subject: [PATCH 09/22] Debug --- .github/workflows/build-win.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index bced4133..2c75ed4e 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -56,8 +56,8 @@ jobs: mingw-w64-x86_64-gcc mingw-w64-x86_64-go - # - name: Setup tmate session for debugging - # uses: mxschmitt/action-tmate@v3 + - name: Setup tmate session for debugging + uses: mxschmitt/action-tmate@v3 - name: Copy and patch shell: msys2 {0} From 2325907d2ec79a1d8fa7795155cc704e17b2d21f Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 22:33:44 +0800 Subject: [PATCH 10/22] Download curl from github --- .github/workflows/build-win.yaml | 4 ++-- win/build.sh | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index 2c75ed4e..bced4133 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -56,8 +56,8 @@ jobs: mingw-w64-x86_64-gcc mingw-w64-x86_64-go - - name: Setup tmate session for debugging - uses: mxschmitt/action-tmate@v3 + # - name: Setup tmate session for debugging + # uses: mxschmitt/action-tmate@v3 - name: Copy and patch shell: msys2 {0} diff --git a/win/build.sh b/win/build.sh index aa289608..49136144 100644 --- a/win/build.sh +++ b/win/build.sh @@ -46,12 +46,11 @@ export HTTP2=1 export WEBSOCKETS=1 export ECH=1 -CURL_VERSION=curl-8.1.1 +CURL_VERSION=curl-8_1_1 -curl -L "https://curl.se/download/${CURL_VERSION}.tar.xz" \ - -o "${CURL_VERSION}.tar.xz" -tar -xf ${CURL_VERSION}.tar.xz -mv ${CURL_VERSION} curl +curl -L https://github.com/curl/curl/archive/${CURL_VERSION}.zip -o curl.zip +unzip -q -o curl.zip +mv curl-${CURL_VERSION} curl cd curl From 64707cf6a4e6d7c93a8c0ec1dd39eee256b9f3d8 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 23:09:44 +0800 Subject: [PATCH 11/22] Build with switch on --- win/build.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/win/build.sh b/win/build.sh index 49136144..966e8d6e 100644 --- a/win/build.sh +++ b/win/build.sh @@ -26,25 +26,23 @@ mv lib/ssl/libssl.a lib/libssl.a cd .. -export IPV6=1 export ZLIB=1 export ZLIB_PATH=zlib_stub -export ZSTD=1 export ZSTD_PATH=zstd_stub -export BROTLI=1 export BROTLI_PATH=brotli_stub export BROTLI_LIBS='-lbrotlidec -lbrotlicommon' -export NGHTTP2=1 export NGHTTP2_PATH=nghttp2_stub -export IDN2=1 export LIBIDN2_PATH=idn2_stub export SSL=1 export OPENSSL_PATH=$PWD/boringssl export OPENSSL_LIBPATH=$PWD/boringssl/lib export OPENSSL_LIBS='-lssl -lcrypto' + +export IPV6=1 export HTTP2=1 export WEBSOCKETS=1 export ECH=1 +export LIBS='-l' CURL_VERSION=curl-8_1_1 @@ -52,6 +50,9 @@ curl -L https://github.com/curl/curl/archive/${CURL_VERSION}.zip -o curl.zip unzip -q -o curl.zip mv curl-${CURL_VERSION} curl +# Apparently, building curl on windows has changes since this commit: +# https://github.com/curl/curl/commit/a8861b6ccdd7ca35b6115588a578e36d765c9e38 + cd curl patchfile=../../chrome/patches/curl-impersonate.patch @@ -66,8 +67,8 @@ sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' src/Makefile.mk sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' lib/Makefile.mk sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' src/Makefile.mk -mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable -mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable +# mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable +mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable CFG=-zlib,-nghttp2,-idn2,-brotli,-zstd mkdir -p ../dist mv lib/libcurl* ../dist/ From de4a375172f8a1f44103e91aeaf833cd9bdbb1ae Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 23:11:15 +0800 Subject: [PATCH 12/22] Add ssl config --- win/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win/build.sh b/win/build.sh index 966e8d6e..8d477df3 100644 --- a/win/build.sh +++ b/win/build.sh @@ -68,7 +68,7 @@ sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' lib/Makefile.mk sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' src/Makefile.mk # mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable -mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable CFG=-zlib,-nghttp2,-idn2,-brotli,-zstd +mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable CFG=-zlib,-nghttp2,-idn2,-brotli,-zstd,-ssl mkdir -p ../dist mv lib/libcurl* ../dist/ From 5f89d7d95dcb4678188e3a87d08d3654d5f7190a Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 23:21:24 +0800 Subject: [PATCH 13/22] Fix CFG --- win/build.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/win/build.sh b/win/build.sh index 8d477df3..7e2fe680 100644 --- a/win/build.sh +++ b/win/build.sh @@ -26,7 +26,6 @@ mv lib/ssl/libssl.a lib/libssl.a cd .. -export ZLIB=1 export ZLIB_PATH=zlib_stub export ZSTD_PATH=zstd_stub export BROTLI_PATH=brotli_stub @@ -38,7 +37,6 @@ export OPENSSL_PATH=$PWD/boringssl export OPENSSL_LIBPATH=$PWD/boringssl/lib export OPENSSL_LIBS='-lssl -lcrypto' -export IPV6=1 export HTTP2=1 export WEBSOCKETS=1 export ECH=1 @@ -68,7 +66,7 @@ sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' lib/Makefile.mk sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' src/Makefile.mk # mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable -mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable CFG=-zlib,-nghttp2,-idn2,-brotli,-zstd,-ssl +mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable CFG=-zlib-nghttp2-idn2-brotli-zstd-ssl-ipv6 mkdir -p ../dist mv lib/libcurl* ../dist/ From 7aa166a5e3ae94d09348ae6194415fd316346558 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sat, 30 Dec 2023 23:29:46 +0800 Subject: [PATCH 14/22] Removed extra -l option --- win/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/win/build.sh b/win/build.sh index 7e2fe680..dff7a40a 100644 --- a/win/build.sh +++ b/win/build.sh @@ -40,7 +40,6 @@ export OPENSSL_LIBS='-lssl -lcrypto' export HTTP2=1 export WEBSOCKETS=1 export ECH=1 -export LIBS='-l' CURL_VERSION=curl-8_1_1 From 21b931d548457cd8e16f25895372d25a427ab211 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sun, 31 Dec 2023 00:06:36 +0800 Subject: [PATCH 15/22] Does this work --- win/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win/build.sh b/win/build.sh index dff7a40a..905c1bec 100644 --- a/win/build.sh +++ b/win/build.sh @@ -19,7 +19,7 @@ patch -p1 < $patchfile sed -i 's/-ggdb//g' CMakeLists.txt sed -i 's/-Werror//g' CMakeLists.txt -cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe +cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release #-DCMAKE_C_COMPILER=gcc.exe ninja -C lib crypto ssl mv lib/crypto/libcrypto.a lib/libcrypto.a mv lib/ssl/libssl.a lib/libssl.a From 20fa3ee121d1fcbf4ed343b2071c50365312ab62 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sun, 31 Dec 2023 00:25:41 +0800 Subject: [PATCH 16/22] Magic move --- win/build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/win/build.sh b/win/build.sh index 905c1bec..e791e9d1 100644 --- a/win/build.sh +++ b/win/build.sh @@ -19,7 +19,7 @@ patch -p1 < $patchfile sed -i 's/-ggdb//g' CMakeLists.txt sed -i 's/-Werror//g' CMakeLists.txt -cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release #-DCMAKE_C_COMPILER=gcc.exe +cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe ninja -C lib crypto ssl mv lib/crypto/libcrypto.a lib/libcrypto.a mv lib/ssl/libssl.a lib/libssl.a @@ -64,8 +64,8 @@ sed -i 's/-DUSE_NGHTTP2/-DUSE_NGHTTP2 -DNGHTTP2_STATICLIB/g' src/Makefile.mk sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' lib/Makefile.mk sed -i 's/-lidn2/-lidn2 -lunistring -liconv/g' src/Makefile.mk -# mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable -mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable CFG=-zlib-nghttp2-idn2-brotli-zstd-ssl-ipv6 +mingw32-make -f Makefile.dist mingw32-clean CFLAGS=-Wno-unused-variable +mingw32-make -f Makefile.dist mingw32 -j CFLAGS=-Wno-unused-variable CFG=-ssl-zlib-nghttp2-idn2-brotli-zstd-ipv6 mkdir -p ../dist mv lib/libcurl* ../dist/ From 058bae4bc1be990f44a01ebdbcee2a4b31b19346 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sun, 31 Dec 2023 00:32:26 +0800 Subject: [PATCH 17/22] Does this work --- win/build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/win/build.sh b/win/build.sh index e791e9d1..b16f529b 100644 --- a/win/build.sh +++ b/win/build.sh @@ -41,6 +41,8 @@ export HTTP2=1 export WEBSOCKETS=1 export ECH=1 +export D_FORTIFY_SOURCE=0 + CURL_VERSION=curl-8_1_1 curl -L https://github.com/curl/curl/archive/${CURL_VERSION}.zip -o curl.zip From 17e6cdbc1d7438205ddae3fbe25f5d44f3289da9 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sun, 31 Dec 2023 08:07:36 +0800 Subject: [PATCH 18/22] Try this now --- win/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win/build.sh b/win/build.sh index b16f529b..4ab5433d 100644 --- a/win/build.sh +++ b/win/build.sh @@ -19,7 +19,7 @@ patch -p1 < $patchfile sed -i 's/-ggdb//g' CMakeLists.txt sed -i 's/-Werror//g' CMakeLists.txt -cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe +cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe -DCMAKE_POSITION_INDEPENDENT_CODE=on ninja -C lib crypto ssl mv lib/crypto/libcrypto.a lib/libcrypto.a mv lib/ssl/libssl.a lib/libssl.a From 8a54f2de62b2180fdf38829b476b1775fd788409 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sun, 31 Dec 2023 08:29:38 +0800 Subject: [PATCH 19/22] debug --- .github/workflows/build-win.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index bced4133..2c75ed4e 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -56,8 +56,8 @@ jobs: mingw-w64-x86_64-gcc mingw-w64-x86_64-go - # - name: Setup tmate session for debugging - # uses: mxschmitt/action-tmate@v3 + - name: Setup tmate session for debugging + uses: mxschmitt/action-tmate@v3 - name: Copy and patch shell: msys2 {0} From 0761a5c1df80519bfbcfde02d6676ce81b1235b7 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sun, 31 Dec 2023 09:03:26 +0800 Subject: [PATCH 20/22] NO ASM? --- .github/workflows/build-win.yaml | 6 +++--- win/build.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index 2c75ed4e..a458f926 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -56,13 +56,13 @@ jobs: mingw-w64-x86_64-gcc mingw-w64-x86_64-go - - name: Setup tmate session for debugging - uses: mxschmitt/action-tmate@v3 - - name: Copy and patch shell: msys2 {0} run: ./win/build.sh + # - name: Setup tmate session for debugging + # uses: mxschmitt/action-tmate@v3 + # - uses: ilammy/msvc-dev-cmd@v1 - name: Generate lib files diff --git a/win/build.sh b/win/build.sh index 4ab5433d..ab6c93c7 100644 --- a/win/build.sh +++ b/win/build.sh @@ -19,7 +19,7 @@ patch -p1 < $patchfile sed -i 's/-ggdb//g' CMakeLists.txt sed -i 's/-Werror//g' CMakeLists.txt -cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe -DCMAKE_POSITION_INDEPENDENT_CODE=on +cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe -DOPENSSL_NO_ASM ninja -C lib crypto ssl mv lib/crypto/libcrypto.a lib/libcrypto.a mv lib/ssl/libssl.a lib/libssl.a From bd2ac272ff0b4060629ac1de585df1feb96bef68 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sun, 31 Dec 2023 09:08:05 +0800 Subject: [PATCH 21/22] Fix --- win/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win/build.sh b/win/build.sh index ab6c93c7..2d77bd08 100644 --- a/win/build.sh +++ b/win/build.sh @@ -19,7 +19,7 @@ patch -p1 < $patchfile sed -i 's/-ggdb//g' CMakeLists.txt sed -i 's/-Werror//g' CMakeLists.txt -cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe -DOPENSSL_NO_ASM +cmake -G "Ninja" -S . -B lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc.exe -DOPENSSL_NO_ASM=1 ninja -C lib crypto ssl mv lib/crypto/libcrypto.a lib/libcrypto.a mv lib/ssl/libssl.a lib/libssl.a From 3cc90685ecce9aa114b681aed36f90ffd7415841 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Sun, 31 Dec 2023 09:55:14 +0800 Subject: [PATCH 22/22] Rename windows build target --- .github/workflows/build-win.yaml | 3 +- Makefile.win | 330 ------------------------------- 2 files changed, 2 insertions(+), 331 deletions(-) delete mode 100644 Makefile.win diff --git a/.github/workflows/build-win.yaml b/.github/workflows/build-win.yaml index a458f926..20609358 100644 --- a/.github/workflows/build-win.yaml +++ b/.github/workflows/build-win.yaml @@ -70,10 +70,11 @@ jobs: - name: Build tarball shell: msys2 {0} - run: tar cvzf curl-impersonate-chrome.tar.gz -C ./build/dist . + run: tar cvzf libcurl-impersonate-${{ github.ref_name }}.x86_64-win32.tar.gz -C ./build/dist . - name: Upload release files uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: + prerelease: true files: curl-impersonate-chrome.tar.gz diff --git a/Makefile.win b/Makefile.win deleted file mode 100644 index d27ebd32..00000000 --- a/Makefile.win +++ /dev/null @@ -1,330 +0,0 @@ -# Makefile to build curl-impersonate -# Some Makefile tricks were taken from https://tech.davis-hansson.com/p/make/ - -SHELL := bash -.ONESHELL: -.SHELLFLAGS := -euc -.DELETE_ON_ERROR: -# MAKEFLAGS += --warn-undefined-variables -# MAKEFLAGS += --no-builtin-rules - -BROTLI_VERSION := 1.0.9 - # In case this is changed, update build-and-test-make.yml as well -BORING_SSL_COMMIT := d24a38200fef19150eef00cad35b138936c08767 -NGHTTP2_VERSION := nghttp2-1.56.0 -NGHTTP2_URL := https://github.com/nghttp2/nghttp2/releases/download/v1.56.0/nghttp2-1.56.0.tar.bz2 -CURL_VERSION := curl-8.1.1 - -brotli_install_dir := $(abspath brotli-$(BROTLI_VERSION)/out/installed) -brotli_static_libs := $(brotli_install_dir)/lib/libbrotlicommon-static.a $(brotli_install_dir)/lib/libbrotlidec-static.a -boringssl_install_dir := $(abspath boringssl/build) -boringssl_static_libs := $(boringssl_install_dir)/lib/libssl.a $(boringssl_install_dir)/lib/libcrypto.a -nghttp2_install_dir := $(abspath $(NGHTTP2_VERSION)/installed) -nghttp2_static_libs := $(nghttp2_install_dir)/lib/libnghttp2.a - -# Dependencies needed to compile the Chrome version -chrome_libs := $(brotli_static_libs) $(boringssl_static_libs) $(nghttp2_static_libs) - -# The following variables will be set by the configure script. -prefix = /usr/local -exec_prefix = ${prefix} -srcdir = /Users/yifei/repos/curl-impersonate/build/.. -host = aarch64-apple-darwin23.0.0 -host_alias = -host_cpu = aarch64 -host_os = darwin23.0.0 -build = aarch64-apple-darwin23.0.0 -# Whether to link curl-impersonate with libcurl-impersonate statically. -static_build = no -# Whether the user provided a specific find for zlib -with_zlib = -# Path to be passed to curl's --with-ca-bundle configure option. -with_ca_bundle = -# Path to be passed to curl's --with-ca-path configure option. -with_ca_path = -# Path to be passed to curl's --with-libnssckbi configure option (an option -# added for curl-impersonate). -with_libnssckbi = - -CC = gcc -CXX = g++ -STRIP = strip - -# Auto-generate Makefile help. -# Borrowed from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html -help: ## Show this help message - @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -.PHONY: help -.DEFAULT_GOAL := help - -chrome-build: $(CURL_VERSION)/.chrome ## Build the Chrome version of curl-impersonate - cd $(CURL_VERSION) - # Don't pass this Makefile's MAKEFLAGS - $(MAKE) MAKEFLAGS= -.PHONY: chrome-build - -chrome-checkbuild: ## Run basic checks on the built binary -ifeq ($(host),$(build)) - 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) -else - $(info Cross compiling, skipping checkbuild) -endif -.PHONY: chrome-checkbuild - -chrome-install: ## Install the Chrome version of curl-impersonate after build - cd $(CURL_VERSION) - $(MAKE) install-exec MAKEFLAGS= - # Wrapper scripts for the Chrome version (e.g. 'curl_chrome99') - install $(srcdir)/chrome/curl_chrome* $(srcdir)/chrome/curl_edge* $(srcdir)/chrome/curl_safari* ${exec_prefix}/bin -.PHONY: chrome-install - -chrome-install-strip: ## Like 'chrome-install', but strip binaries for smaller size - cd $(CURL_VERSION) - $(MAKE) install-exec MAKEFLAGS= - # We could have used 'install-strip' but then the docs would be installed as well. - # Instead strip manually. - $(STRIP) ${exec_prefix}/bin/curl-impersonate-chrome - # Wrapper scripts for the Chrome version (e.g. 'curl_chrome99') - install $(srcdir)/chrome/curl_chrome* $(srcdir)/chrome/curl_edge* $(srcdir)/chrome/curl_safari* ${exec_prefix}/bin -.PHONY: chrome-install-strip - -chrome-uninstall: ## Uninstall the Chrome version of curl-impersonate after 'make install' - cd $(CURL_VERSION) - $(MAKE) uninstall MAKEFLAGS= - rm -Rf ${exec_prefix}/bin/curl_chrome* ${exec_prefix}/bin/curl_edge* ${exec_prefix}/bin/curl_safari* -.PHONY: chrome-uninstall - -chrome-clean: ## Clean build artifacts of the Chrome version. Use after re-running './configure' - cd $(CURL_VERSION) - $(MAKE) clean MAKEFLAGS= - rm -f .chrome -.PHONY: chrome-clean - -clean: ## Remove all build artifacts, including dependencies - rm -Rf brotli-$(BROTLI_VERSION).tar.gz brotli-$(BROTLI_VERSION) - rm -Rf $(NSS_VERSION).tar.gz $(NSS_VERSION) - rm -Rf boringssl.zip boringssl - rm -Rf $(NGHTTP2_VERSION).tar.bz2 $(NGHTTP2_VERSION) - rm -Rf $(CURL_VERSION).tar.xz $(CURL_VERSION) - -brotli-$(BROTLI_VERSION).tar.gz: - curl -L "https://github.com/google/brotli/archive/refs/tags/v${BROTLI_VERSION}.tar.gz" \ - -o "brotli-${BROTLI_VERSION}.tar.gz" - -$(brotli_static_libs): brotli-$(BROTLI_VERSION).tar.gz - tar xf brotli-$(BROTLI_VERSION).tar.gz - cd brotli-$(BROTLI_VERSION) - mkdir -p out - cd out - - # Convert autoconf style os name to CMake style os name. - case $(host_os) in \ - linux*) \ - system_name=Linux \ - ;; \ - darwin*) \ - system_name=Darwin \ - ;; \ - *) \ - system_name=$(host_os) \ - ;; \ - esac - - cmake -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=./installed \ - -DCMAKE_INSTALL_LIBDIR=lib \ - -DCMAKE_CXX_COMPILER=$(CXX) \ - -DCMAKE_C_COMPILER=$(CC) \ - -DCMAKE_SYSTEM_NAME=$$system_name \ - -DCMAKE_SYSTEM_PROCESSOR=$(host_cpu) \ - .. - - cmake --build . --config Release --target install - - -$(NSS_VERSION).tar.gz: - curl -L -o $(NSS_VERSION).tar.gz $(NSS_URL) - -$(nss_static_libs): $(NSS_VERSION).tar.gz - tar xf $(NSS_VERSION).tar.gz - -ifeq ($(host),$(build)) - # Native build, use NSS' build script. - cd $(NSS_VERSION)/nss - ./build.sh -o --disable-tests --static --python=python3 -else - # We are cross compiling. - # Cross compiling NSS is not supported by its build script and is poorly - # documented. We need to compile NSPR manually and only then compile nss. - case $(host_cpu) in \ - *64*) \ - use_64="1"; \ - nspr_configure_flags="--enable-64bit"; \ - ;; \ - *) \ - use_64="0"; \ - nspr_configure_flags=""; \ - ;; \ - esac - - # Cross-compile nspr separately - cd $(NSS_VERSION)/nspr - ./configure --prefix=$(nss_install_dir) \ - --disable-debug --enable-optimize \ - --target=$(host_alias) \ - $$nspr_configure_flags - $(MAKE) MAKEFLAGS= - $(MAKE) install MAKEFLAGS= - - # Now we can run ./build.sh with the already built nspr - cd ../nss - CC=$(CC) CXX=$(CXX) CCC=$(CXX) \ - ./build.sh -o --disable-tests --static --python=python3 \ - --with-nspr=$(nss_install_dir)/include/nspr:$(nss_install_dir)/lib \ - --target=$(host_cpu) \ - -Duse_system_zlib=0 \ - -Dsign_libs=0 -endif - # Hack for macOS: Remove dynamic libraries to force the linker to use the - # static ones when linking curl. - rm -Rf $(nss_install_dir)/lib/*.dylib - - -boringssl.zip: - curl -L https://github.com/google/boringssl/archive/$(BORING_SSL_COMMIT).zip \ - -o boringssl.zip - -# Patch boringssl and use a dummy '.patched' file to mark it patched -boringssl/.patched: $(srcdir)/chrome/patches/boringssl-*.patch - unzip -q -o boringssl.zip - mv boringssl-$(BORING_SSL_COMMIT) boringssl - cd boringssl/ - for p in $^; do patch -p1 < $$p; done - touch .patched - -$(boringssl_static_libs): boringssl.zip boringssl/.patched - mkdir -p $(boringssl_install_dir) - cd $(boringssl_install_dir) - - # Convert autoconf style os name to CMake style os name. - case $(host_os) in \ - linux*) \ - system_name=Linux \ - ;; \ - darwin*) \ - system_name=Darwin \ - ;; \ - *) \ - system_name=Linux \ - ;; \ - esac - - # The extra CMAKE_C_FLAGS are needed because otherwise boringssl fails to - # compile in release mode on some systems with gcc 12 (e.g. Fedora). - # In addition, guard these options with -Wno-unknown-warning-option to - # prevent clang from failing on them. - cmake -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_POSITION_INDEPENDENT_CODE=on \ - -DCMAKE_C_FLAGS="-Wno-unknown-warning-option -Wno-stringop-overflow -Wno-array-bounds" \ - -DCMAKE_CXX_COMPILER=$(CXX) \ - -DCMAKE_C_COMPILER=$(CC) \ - -DCMAKE_SYSTEM_NAME=$$system_name \ - -DCMAKE_SYSTEM_PROCESSOR=$(host_cpu) \ - -GNinja \ - .. - ninja - # Fix the directory structure so that curl can compile against it. - # See https://everything.curl.dev/source/build/tls/boringssl - mkdir -p lib - ln -sf ../crypto/libcrypto.a lib/libcrypto.a - ln -sf ../ssl/libssl.a lib/libssl.a - cp -Rf ../include . - - -$(NGHTTP2_VERSION).tar.bz2: - curl -L $(NGHTTP2_URL) -o $(NGHTTP2_VERSION).tar.bz2 - -$(nghttp2_static_libs): $(NGHTTP2_VERSION).tar.bz2 - tar -xf $(NGHTTP2_VERSION).tar.bz2 - cd $(NGHTTP2_VERSION) - - # Set up the configure flags to nghttp2. - # If the user provided the --host flag to our configure script - # (for cross compilation), then pass it on to nghttp2. - { \ - config_flags="--prefix=$(nghttp2_install_dir)"; \ - config_flags="$$config_flags --with-pic --enable-lib-only"; \ - config_flags="$$config_flags --disable-shared --disable-python-bindings"; \ - if test -n "$(host_alias)"; then \ - config_flags="$$config_flags --host=$(host_alias)"; \ - fi; \ - } - - ./configure $$config_flags - $(MAKE) MAKEFLAGS= - $(MAKE) install MAKEFLAGS= - -$(CURL_VERSION).tar.xz: - curl -L "https://curl.se/download/$(CURL_VERSION).tar.xz" \ - -o "$(CURL_VERSION).tar.xz" - -# Apply the "Chorme version" patches and mark using a dummy file -$(CURL_VERSION)/.patched-chrome: $(srcdir)/chrome/patches/curl-*.patch - rm -Rf $(CURL_VERSION) - tar -xf $(CURL_VERSION).tar.xz - cd $(CURL_VERSION) - for p in $^; do patch -p1 < $$p; done - # Re-generate the configure script - autoreconf -fi - touch .patched-chrome - rm -f .patched-ff - -# This is a small hack that flags that curl was patched and configured in the "chrome" version -$(CURL_VERSION)/.chrome: $(chrome_libs) $(CURL_VERSION).tar.xz $(CURL_VERSION)/.patched-chrome - cd $(CURL_VERSION) - - # Set up the configure flags to curl. - # If the user provided the --host flag to our configure script - # (for cross compilation), then pass it on to curl. - { \ - config_flags="--prefix=/usr/local"; \ - config_flags="$$config_flags --with-nghttp2=$(nghttp2_install_dir)"; \ - config_flags="$$config_flags --with-brotli=$(brotli_install_dir)"; \ - config_flags="$$config_flags --with-openssl=$(boringssl_install_dir)"; \ - config_flags="$$config_flags --without-zstd"; \ - config_flags="$$config_flags --enable-websockets"; \ - config_flags="$$config_flags --enable-ech"; \ - config_flags="$$config_flags USE_CURL_SSLKEYLOGFILE=true"; \ - if test "$(static_build)" = "yes"; then \ - config_flags="$$config_flags --enable-static --disable-shared"; - fi; \ - if test -n "$(host_alias)"; then \ - config_flags="$$config_flags --host=$(host_alias)"; \ - fi; \ - if test -n "$(with_zlib)"; then \ - config_flags="$$config_flags --with-zlib=$(with_zlib)"; \ - else \ - config_flags+=" --with-zlib"; \ - fi; \ - if test -n "$(with_ca_bundle)"; then \ - config_flags="$$config_flags --with-ca-bundle=$(with_ca_bundle)"; \ - fi; \ - if test -n "$(with_ca_path)"; then \ - config_flags="$$config_flags --with-ca-path=$(with_ca_path)"; \ - fi; \ - add_libs="-pthread"; \ - } - - echo "Configuring curl with: $$config_flags" - - ./configure $$config_flags LIBS="$$add_libs" - - # Remove possible leftovers from a previous compilation - $(MAKE) clean MAKEFLAGS= - touch .chrome