Skip to content

Commit

Permalink
Fix wheels' bundled libcurl.so incompatibility with Debian [HACK]
Browse files Browse the repository at this point in the history
Linux wheels are (currently) built on AlmaLinux, so the libcurl.so
bundled into the wheel follows Alma/Red Hat/Fedora conventions for the
location of its certificate bundle. This fails when the wheel is used on
a Debian/Ubuntu platform with a different convention for this location.
When not overridden by $CURL_CA_BUNDLE, work around this by specifying
the expected Debian bundle location if the Red Hat one isn't present.

Fixes #1257 via a hacky work around.

(Take care to preserve this patch when importing HTSlib in future.)
  • Loading branch information
jmarshall committed Feb 4, 2025
1 parent 82634f1 commit b18dde8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions htslib/hfile_libcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ DEALINGS IN THE SOFTWARE. */
#ifndef _WIN32
# include <sys/select.h>
#endif
#include <sys/stat.h>
#include <assert.h>

#include "hfile_internal.h"
Expand Down Expand Up @@ -1246,6 +1247,19 @@ libcurl_open(const char *url, const char *modes, http_headers *headers)
if (env_curl_ca_bundle) {
err |= curl_easy_setopt(fp->easy, CURLOPT_CAINFO, env_curl_ca_bundle);
}
#if defined __linux__ && defined BUILDING_WHEEL
else {
// Linux wheels are (currently) built on AlmaLinux, so the libcurl.so bundled
// into the wheel follows Alma/Red Hat/Fedora conventions for the location of
// its certificate bundle. This fails when the wheel is used on a Debian/Ubuntu
// platform with a different convention for this location. When not overridden
// by $CURL_CA_BUNDLE, work around this by specifying the expected Debian bundle
// location if the Red Hat one isn't present.
struct stat st;
if (stat("/etc/pki", &st) < 0 && errno == ENOENT)
err |= curl_easy_setopt(fp->easy, CURLOPT_CAINFO, "/etc/ssl/certs/ca-certificates.crt");
}
#endif
}
err |= curl_easy_setopt(fp->easy, CURLOPT_USERAGENT, curl.useragent.s);
if (fp->headers.callback) {
Expand Down
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def set_compiler_envvars():
del os.environ[var]


def format_macro_option(name, value):
return f"-D{name}={value}" if value is not None else f"-D{name}"


def configure_library(library_dir, env_options=None, options=[]):

configure_script = os.path.join(library_dir, "configure")
Expand Down Expand Up @@ -532,6 +536,9 @@ def run(self):

define_macros = []

if os.environ.get("CIBUILDWHEEL", "0") == "1":
define_macros.append(("BUILDING_WHEEL", None))

suffix = sysconfig.get_config_var('EXT_SUFFIX')

internal_htslib_libraries = [
Expand Down Expand Up @@ -567,7 +574,8 @@ def prebuild_libchtslib(ext, force):
# TODO Eventually by running configure here, we can set these
# extra flags for configure instead of hacking on ALL_CPPFLAGS.
args = " ".join(ext.extra_compile_args)
run_make(["ALL_CPPFLAGS=-I. " + args + " $(CPPFLAGS)", "lib-static"])
defines = " ".join([format_macro_option(*pair) for pair in ext.define_macros])
run_make(["ALL_CPPFLAGS=-I. " + args + " " + defines + " $(CPPFLAGS)", "lib-static"])
else:
log.warning("skipping 'libhts.a' (already built)")

Expand Down

0 comments on commit b18dde8

Please sign in to comment.