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

Feature/winbuild #13

Closed
wants to merge 22 commits into from
Closed
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
80 changes: 80 additions & 0 deletions .github/workflows/build-win.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build for windows
on:
push:
branches:
- main
- feature/*
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/[email protected]
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
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
mingw-w64-x86_64-gcc
mingw-w64-x86_64-go

- 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
run: ./win/dll2lib.bat 64 build\dist\libcurl.dll

- name: Build tarball
shell: msys2 {0}
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
77 changes: 77 additions & 0 deletions win/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

set -ex

mkdir build/
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
unzip -q -o boringssl.zip
mv boringssl-${BORING_SSL_COMMIT} boringssl

cd boringssl

patchfile=../../chrome/patches/boringssl-old-ciphers.patch
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=1
ninja -C lib crypto ssl
mv lib/crypto/libcrypto.a lib/libcrypto.a
mv lib/ssl/libssl.a lib/libssl.a

cd ..

export ZLIB_PATH=zlib_stub
export ZSTD_PATH=zstd_stub
export BROTLI_PATH=brotli_stub
export BROTLI_LIBS='-lbrotlidec -lbrotlicommon'
export NGHTTP2_PATH=nghttp2_stub
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
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
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
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 -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/
mv src/*.exe ../dist/

cd ..
dist/curl -V
29 changes: 29 additions & 0 deletions win/dll2lib.bat
Original file line number Diff line number Diff line change
@@ -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
Loading