Skip to content
Merged
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
207 changes: 207 additions & 0 deletions net/curl-impersonate/Portfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem 1.0
PortGroup cmake 1.1
PortGroup github 1.0
PortGroup legacysupport 1.1

legacysupport.newest_darwin_requires_legacy 16
# Pre-10.12 Apple libc++ does not support all needed features.
# This does not affect macOS versions using libsdtc++.
legacysupport.use_mp_libcxx yes

github.setup lexiforest curl-impersonate 2.0.0 v
revision 0
categories net www
maintainers {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
license MIT

description active fork of curl-impersonate with more versions and build targets
long_description \
An {*}${description}.

distname ${github.project}-${version}
github.tarball_from archive

# curl-impersonate uses specific versions of dependencies and links them statically.
# See: https://github.com/lexiforest/curl-impersonate/blob/ec41b71ce888806bfec56ada7a7258d333eb3d19/CMakeLists.txt
set boringssl_hash 156c7b75ae9b8c3b3f847acf264f17594c3859fb
set brotli_version 1.2.0
set curl_version 8.21.0
set libidn_version 2.3.7
set nghttp2_version 1.63.0
set nghttp3_version 1.15.0
set ngtcp2_version 1.20.0
set zlib_version 1.3.1
set zstd_version 1.5.7

set curl_tag [string map {. _} ${curl_version}]

distfiles-append \
${boringssl_hash}${extract.suffix}:boringssl \
v${brotli_version}${extract.suffix}:brotli \
curl-${curl_tag}${extract.suffix}:curl \
libidn2-${libidn_version}${extract.suffix}:libidn \
v${nghttp2_version}${extract.suffix}:nghttp2 \
nghttp3-${nghttp3_version}${extract.suffix}:nghttp3 \
ngtcp2-${ngtcp2_version}${extract.suffix}:ngtcp2 \
zlib-${zlib_version}${extract.suffix}:zlib \
zstd-${zstd_version}${extract.suffix}:zstd

master_sites-append \
https://github.com/google/boringssl/archive/:boringssl \
https://github.com/google/brotli/archive/refs/tags/:brotli \
https://github.com/curl/curl/archive/refs/tags/:curl \
https://ftp.gnu.org/gnu/libidn/:libidn \
https://github.com/nghttp2/nghttp2/archive/refs/tags/:nghttp2 \
https://github.com/ngtcp2/nghttp3/releases/download/v${nghttp3_version}/:nghttp3 \
https://github.com/ngtcp2/ngtcp2/releases/download/v${ngtcp2_version}/:ngtcp2 \
https://github.com/madler/zlib/releases/download/v${zlib_version}/:zlib \
https://github.com/facebook/zstd/releases/download/v${zstd_version}/:zstd

checksums ${distname}${extract.suffix} \
rmd160 7b86ca2cb6132bedd2d91fc44ff7c875d3d160cb \
sha256 a9827cfce8246e78b86e26f012ae9fcb9bc05822009cd7ce4c9e130af6bdfb6f \
size 207780 \
${boringssl_hash}${extract.suffix} \
rmd160 2606447aeebd42ef2ee5fc948713f0aa3666450b \
sha256 4cbd70611e6400616fd5a58f42e19e7bafd568c674ecb3a6418c43ae1e3ac93b \
size 74515087 \
v${brotli_version}${extract.suffix} \
rmd160 949e0c56045b760b854714f45b0912936a9be53a \
sha256 816c96e8e8f193b40151dad7e8ff37b1221d019dbcb9c35cd3fadbfe6477dfec \
size 646315 \
curl-${curl_tag}${extract.suffix} \
rmd160 bb9ba1116f1ce6e91fa609d6a5d6803f614c9aae \
sha256 ec753aa6f408a3ca9f0d6d5f7a77417aecd1544db13c03ae5d443612bf367364 \
size 3592963 \
libidn2-${libidn_version}${extract.suffix} \
rmd160 511eb10830342dc546824c5e48bb6ef0022382ab \
sha256 4c21a791b610b9519b9d0e12b8097bf2f359b12f8dd92647611a929e6bfd7d64 \
size 2155214 \
v${nghttp2_version}${extract.suffix} \
rmd160 fa3d04976a104cf66338997f6fa55d1c465623d6 \
sha256 f3da0627bee7a6a60f5a4eb6de8d17d25e99f50f87b0fc0c20676c682bf31098 \
size 1070155 \
nghttp3-${nghttp3_version}${extract.suffix} \
rmd160 37d60d4b7c56836ec03cb94bd2a528781b40c6ab \
sha256 0e431c81eb2d3df5ced048d6e942925ff922ad053e76a0274eea7b164c9b776e \
size 655937 \
ngtcp2-${ngtcp2_version}${extract.suffix} \
rmd160 839f587fb815485782b20d8891bf718a5db1af56 \
sha256 daa3398640a1fe1823ad8e2b1b88562b8da7888a47edd8c8ba03c75cfd9c8bb6 \
size 1204305 \
zlib-${zlib_version}${extract.suffix} \
rmd160 52945a1a5a1bd51ac676a0b9197bdaacbc537fd6 \
sha256 9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23 \
size 1512791 \
zstd-${zstd_version}${extract.suffix} \
rmd160 9a07d2d7b2cc9c6acd48dbf593ae1bace4590c94 \
sha256 eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3 \
size 2434947

set dep_src_dir ${worksrcpath}/deps/src
set dep_build_dir ${worksrcpath}/deps/build
set dep_inst_dir ${worksrcpath}/deps/install

post-extract {
xinstall -d ${dep_src_dir}

move ${workpath}/boringssl-${boringssl_hash} ${dep_src_dir}/boringssl
move ${workpath}/brotli-${brotli_version} ${dep_src_dir}/brotli
move ${workpath}/curl-curl-${curl_tag} ${dep_src_dir}/curl
move ${workpath}/libidn2-${libidn_version} ${dep_src_dir}/libidn2
move ${workpath}/nghttp2-${nghttp2_version} ${dep_src_dir}/nghttp2
move ${workpath}/nghttp3-${nghttp3_version} ${dep_src_dir}/nghttp3
move ${workpath}/ngtcp2-${ngtcp2_version} ${dep_src_dir}/ngtcp2
move ${workpath}/zlib-${zlib_version} ${dep_src_dir}/zlib
move ${workpath}/zstd-${zstd_version} ${dep_src_dir}/zstd
}

cmake.out_of_source no
cmake.generator Ninja

set py_ver 3.14
set py_ver_nodot [string map {. {}} ${py_ver}]
configure.python ${prefix}/bin/python${py_ver}

# Prefer system libiconv, it works fine back to powerpc:
set iconv_prefix /usr
# macOS 11+ do not have libiconv in filesystem however, so there we need a port:
if {${os.platform} eq "darwin" && ${os.major} > 19} {
set iconv_prefix ${prefix}
depends_lib-append port:libiconv
}

depends_build-append \
port:autoconf \
port:automake \
port:libtool \
path:bin/perl:perl5 \
path:bin/pkg-config:pkgconfig

depends_run-append path:share/curl/curl-ca-bundle.crt:curl-ca-bundle

compiler.c_standard 2011
compiler.cxx_standard 2020

patch.pre_args-replace -p0 -p1

patchfiles-append 0001-CMakeLists.patch \
0002-libiconv.patch \
0003-boringssl.patch

if {${os.major} < 11 && [string match *gcc* ${configure.compiler}]} {
patchfiles-append 0004-zstd.patch
}

post-patch {
reinplace "s,@PREFIX@,${prefix},g" ${worksrcpath}/CMakeLists.txt
reinplace "s,@ICONV_PREFIX@,${iconv_prefix}," ${worksrcpath}/CMakeLists.txt
}

configure.pre_args-replace \
-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

# Defaults which normal curl uses as well:
configure.args-append \
-DCURL_CA_BUNDLE=${prefix}/share/curl/curl-ca-bundle.crt \
-DCURL_SUBPROJECT_FORCE_OPENSSL_PATHS=ON \
-DUSE_APPLE_SECTRUST=OFF \
-DUSE_LIBIDN2=ON

# asm does not exist for powerpc in boringssl and may not exist/work on other exotic archs.
if {${configure.build_arch} ni [list arm64 x86_64]} {
configure.args-append \
-DDISABLE_BORINGSSL_ASM=ON
}

if {${cxx_stdlib} eq "libc++"} {
configure.args-append \
-DCURL_IMPERSONATE_CXX_RUNTIME_LIBRARY:STRING=c++
} else {
configure.args-append \
-DCURL_IMPERSONATE_CXX_RUNTIME_LIBRARY:STRING=stdc++
}

# USE_LIBIDN2 requires prebuilt libidn2, which upstream does with a standalone script.
pre-configure {
xinstall -d ${dep_build_dir}/libidn2
system -W ${dep_build_dir}/libidn2 "PKG_CONFIG_PATH=\"${dep_inst_dir}/lib/pkgconfig\" \
CPPFLAGS= LDFLAGS= LIBRARY_PATH= \
${dep_src_dir}/libidn2/configure --prefix=${worksrcpath}/deps/install --disable-nls \
--disable-shared --enable-static --with-pic --with-included-libunistring \
--with-libiconv-prefix=${iconv_prefix} --without-libintl-prefix && make V=1 MAKEFLAGS=-j${build.jobs} && make install MAKEFLAGS="
}

universal_variant no

post-destroot {
move ${destroot}${prefix}/include/curl ${destroot}${prefix}/include/${name}
platform darwin {
set dlib ${prefix}/lib/lib${name}.dylib
system "install_name_tool -id ${dlib} ${destroot}${dlib}"
system "install_name_tool -change @rpath/libcurl-impersonate.4.dylib ${dlib} ${destroot}${prefix}/bin/${name}"
}
}
118 changes: 118 additions & 0 deletions net/curl-impersonate/files/0001-CMakeLists.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
--- a/CMakeLists.txt 2026-07-26 12:23:17.000000000 +0800
+++ b/CMakeLists.txt 2026-08-05 17:40:54.000000000 +0800
@@ -184,8 +184,7 @@

# zlib
ExternalProject_Add(zlib
- URL "${ZLIB_URL}"
- URL_HASH "${ZLIB_URL_HASH}"
+ DOWNLOAD_COMMAND ""
SOURCE_DIR "${DEPS_SRC_DIR}/zlib"
BINARY_DIR "${DEPS_BUILD_DIR}/zlib"
INSTALL_DIR "${DEPS_INSTALL_DIR}"
@@ -199,8 +198,7 @@

# zstd
ExternalProject_Add(zstd
- URL "${ZSTD_URL}"
- URL_HASH "${ZSTD_URL_HASH}"
+ DOWNLOAD_COMMAND ""
SOURCE_DIR "${DEPS_SRC_DIR}/zstd"
BINARY_DIR "${DEPS_BUILD_DIR}/zstd"
INSTALL_DIR "${DEPS_INSTALL_DIR}"
@@ -219,8 +217,7 @@
# brotli
_track_external_project_patch(brotli _brotli_patch_file _brotli_patch_changed)
ExternalProject_Add(brotli
- URL "${BROTLI_URL}"
- URL_HASH "${BROTLI_URL_HASH}"
+ DOWNLOAD_COMMAND ""
SOURCE_DIR "${DEPS_SRC_DIR}/brotli"
BINARY_DIR "${DEPS_BUILD_DIR}/brotli"
INSTALL_DIR "${DEPS_INSTALL_DIR}"
@@ -263,8 +260,7 @@
boringssl _boringssl_patch_file _boringssl_patch_changed
)
ExternalProject_Add(boringssl
- URL "${BORINGSSL_URL}"
- URL_HASH "${BORINGSSL_URL_HASH}"
+ DOWNLOAD_COMMAND ""
SOURCE_DIR "${DEPS_SRC_DIR}/boringssl"
BINARY_DIR "${DEPS_BUILD_DIR}/boringssl"
PATCH_COMMAND ${PATCH_EXE} -p1 -i "${_boringssl_patch_file}"
@@ -292,8 +288,7 @@

# nghttp2
ExternalProject_Add(nghttp2
- URL "${NGHTTP2_URL}"
- URL_HASH "${NGHTTP2_URL_HASH}"
+ DOWNLOAD_COMMAND ""
SOURCE_DIR "${DEPS_SRC_DIR}/nghttp2"
BINARY_DIR "${DEPS_BUILD_DIR}/nghttp2"
INSTALL_DIR "${DEPS_INSTALL_DIR}"
@@ -314,8 +309,7 @@
# nghttp3
_track_external_project_patch(nghttp3 _nghttp3_patch_file _nghttp3_patch_changed)
ExternalProject_Add(nghttp3
- URL "${NGHTTP3_URL}"
- URL_HASH "${NGHTTP3_URL_HASH}"
+ DOWNLOAD_COMMAND ""
SOURCE_DIR "${DEPS_SRC_DIR}/nghttp3"
BINARY_DIR "${DEPS_BUILD_DIR}/nghttp3"
INSTALL_DIR "${DEPS_INSTALL_DIR}"
@@ -347,8 +341,7 @@
endif()
ExternalProject_Add(ngtcp2
LIST_SEPARATOR |
- URL "${NGTCP2_URL}"
- URL_HASH "${NGTCP2_URL_HASH}"
+ DOWNLOAD_COMMAND ""
SOURCE_DIR "${DEPS_SRC_DIR}/ngtcp2"
BINARY_DIR "${DEPS_BUILD_DIR}/ngtcp2"
INSTALL_DIR "${DEPS_INSTALL_DIR}"
@@ -473,8 +466,8 @@
endif()
if(APPLE)
list(APPEND _curl_staged_dependency_args
- "-DCMAKE_IGNORE_PREFIX_PATH=/usr/local|/opt/homebrew"
- "-DCMAKE_IGNORE_PATH=/usr/local/include|/usr/local/lib|/opt/homebrew/include|/opt/homebrew/lib"
+ "-DCMAKE_IGNORE_PREFIX_PATH=@PREFIX@"
+ "-DCMAKE_IGNORE_PATH=@PREFIX@/include|@PREFIX@/lib"
)
endif()
if(USE_LIBIDN2 AND NOT WIN32)
@@ -497,8 +490,6 @@
else()
list(APPEND _curl_platform_flags "-Dssize_t=long")
endif()
-elseif(APPLE)
- list(APPEND _curl_platform_flags -DUSE_APPLE_SECTRUST=ON)
endif()
if(CMAKE_MSVC_RUNTIME_LIBRARY)
list(APPEND _curl_platform_flags "-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}")
@@ -514,6 +505,15 @@
string(STRIP "${_curl_shared_linker_flags}" _curl_shared_linker_flags)
list(APPEND _curl_platform_flags "-DCMAKE_EXE_LINKER_FLAGS=${_curl_exe_linker_flags}")
list(APPEND _curl_platform_flags "-DCMAKE_SHARED_LINKER_FLAGS=${_curl_shared_linker_flags}")
+elseif(APPLE)
+ set(_curl_exe_linker_flags "${CMAKE_EXE_LINKER_FLAGS}")
+ set(_curl_shared_linker_flags "${CMAKE_SHARED_LINKER_FLAGS}")
+ string(APPEND _curl_exe_linker_flags " -l${CURL_IMPERSONATE_CXX_RUNTIME_LIBRARY}")
+ string(APPEND _curl_shared_linker_flags " -l${CURL_IMPERSONATE_CXX_RUNTIME_LIBRARY}")
+ string(STRIP "${_curl_exe_linker_flags}" _curl_exe_linker_flags)
+ string(STRIP "${_curl_shared_linker_flags}" _curl_shared_linker_flags)
+ list(APPEND _curl_platform_flags "-DCMAKE_EXE_LINKER_FLAGS=${_curl_exe_linker_flags}")
+ list(APPEND _curl_platform_flags "-DCMAKE_SHARED_LINKER_FLAGS=${_curl_shared_linker_flags}")
endif()

set(_curl_openssl_flags)
@@ -539,8 +539,7 @@

ExternalProject_Add(curl
LIST_SEPARATOR |
- URL "${CURL_URL}"
- URL_HASH "${CURL_URL_HASH}"
+ DOWNLOAD_COMMAND ""
SOURCE_DIR "${DEPS_SRC_DIR}/curl"
BINARY_DIR "${DEPS_BUILD_DIR}/curl"
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
39 changes: 39 additions & 0 deletions net/curl-impersonate/files/0002-libiconv.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8dafe03..eae4ce1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -478,10 +478,32 @@ if(APPLE)
)
endif()
if(USE_LIBIDN2 AND NOT WIN32)
- # The prebuild makes libidn2 self-contained with its included libunistring.
+ # The prebuild makes libidn2 self-contained with its included libunistring,
+ # except for iconv: libunistring's striconveh.c calls the plain POSIX
+ # iconv()/iconv_open()/iconv_close() symbols, which are not part of
+ # a static archive's own link requirements, so they must be supplied again
+ # here when libidn2.a gets linked into curl. On Apple platforms iconv is
+ # not part of libSystem's implicit re-exports (unlike on glibc) and always
+ # needs to be linked explicitly; pinning the absolute path to Apple's
+ # /usr/lib/libiconv.dylib (rather than a bare -liconv) guarantees this
+ # resolves to the system copy even when a package manager's own libiconv
+ # is reachable on the linker search path.
+ #
+ # LIBIDN2_LIBRARY must carry both paths as one CMake list value (curl's
+ # FindLibidn2.cmake forwards it verbatim into an INTERFACE_LINK_LIBRARIES
+ # property). This ExternalProject_Add(curl ...) call's CONFIGURE_COMMAND
+ # is a plain command list, so a literal ";" here would already be split
+ # into separate command-line words by CMake's own configure-time list
+ # handling before it ever reaches the nested cmake invocation - use the
+ # same LIST_SEPARATOR token ("|", declared below) already used for
+ # CMAKE_IGNORE_PREFIX_PATH/CMAKE_IGNORE_PATH above for the same reason.
+ set(_libidn2_link_libs "${DEPS_INSTALL_DIR}/lib/libidn2.a")
+ if(APPLE)
+ string(APPEND _libidn2_link_libs "|@ICONV_PREFIX@/lib/libiconv.dylib")
+ endif()
list(APPEND _curl_staged_dependency_args
"-DLIBIDN2_INCLUDE_DIR=${DEPS_INSTALL_DIR}/include"
- "-DLIBIDN2_LIBRARY=${DEPS_INSTALL_DIR}/lib/libidn2.a"
+ "-DLIBIDN2_LIBRARY=${_libidn2_link_libs}"
)
endif()

Loading