feat: Build c-ares locally (#1285)

c-ares (used on Linux only) was an exception to the rule of only linking
against internally-built libraries. This fixes that, to support a truly
static build of packager.
This commit is contained in:
Joey Parrish 2023-10-18 16:44:43 -07:00 committed by GitHub
parent e516608c5e
commit fac8acf5dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 42 additions and 18 deletions

View File

@ -110,7 +110,6 @@ jobs:
run: | run: |
sudo apt update && sudo apt install -y \ sudo apt update && sudo apt install -y \
cmake \ cmake \
libc-ares-dev \
ninja-build ninja-build
- name: Install Mac deps - name: Install Mac deps

3
.gitmodules vendored
View File

@ -31,3 +31,6 @@
[submodule "packager/third_party/mongoose/source"] [submodule "packager/third_party/mongoose/source"]
path = packager/third_party/mongoose/source path = packager/third_party/mongoose/source
url = https://github.com/cesanta/mongoose url = https://github.com/cesanta/mongoose
[submodule "packager/third_party/c-ares/source"]
path = packager/third_party/c-ares/source
url = https://github.com/c-ares/c-ares

View File

@ -3,7 +3,7 @@ FROM alpine:3.12 as builder
# Install utilities, libraries, and dev tools. # Install utilities, libraries, and dev tools.
RUN apk add --no-cache \ RUN apk add --no-cache \
bash curl \ bash curl \
bsd-compat-headers c-ares-dev linux-headers \ bsd-compat-headers linux-headers \
build-base cmake git ninja python3 build-base cmake git ninja python3
# Build shaka-packager from the current directory, rather than what has been # Build shaka-packager from the current directory, rather than what has been

View File

@ -12,7 +12,6 @@ for [other distros below](#notes-for-other-linux-distros).
sudo apt-get update sudo apt-get update
sudo apt-get install -y \ sudo apt-get install -y \
curl \ curl \
libc-ares-dev \
build-essential cmake git ninja-build python3 build-essential cmake git ninja-build python3
``` ```
@ -153,7 +152,7 @@ Use `apk` command to install dependencies:
```shell ```shell
apk add --no-cache \ apk add --no-cache \
bash curl \ bash curl \
bsd-compat-headers c-ares-dev linux-headers \ bsd-compat-headers linux-headers \
build-base cmake git ninja python3 build-base cmake git ninja python3
``` ```
@ -164,7 +163,6 @@ Instead of running `sudo apt-get install` to install build dependencies, run:
```shell ```shell
pacman -Suy --needed --noconfirm \ pacman -Suy --needed --noconfirm \
core/which \ core/which \
c-ares \
cmake gcc git ninja python3 cmake gcc git ninja python3
``` ```
@ -175,7 +173,6 @@ Same as Ubuntu.
```shell ```shell
apt-get install -y \ apt-get install -y \
curl \ curl \
libc-ares-dev \
build-essential cmake git ninja-build python3 build-essential cmake git ninja-build python3
``` ```
@ -186,7 +183,7 @@ Instead of running `sudo apt-get install` to install build dependencies, run:
```shell ```shell
yum install -y \ yum install -y \
which \ which \
c-ares-devel libatomic \ libatomic \
cmake gcc-c++ git ninja-build python3 cmake gcc-c++ git ninja-build python3
``` ```
@ -205,7 +202,7 @@ then same as Fedora
```shell ```shell
yum install -y \ yum install -y \
which \ which \
c-ares-devel libatomic \ libatomic \
cmake gcc-c++ git ninja-build python3 cmake gcc-c++ git ninja-build python3
``` ```
@ -216,7 +213,6 @@ Use `zypper` command to install dependencies:
```shell ```shell
zypper in -y \ zypper in -y \
curl which \ curl which \
c-ares-devel \
cmake gcc9-c++ git ninja python3 cmake gcc9-c++ git ninja python3
``` ```

View File

@ -3,7 +3,7 @@ FROM alpine:3.12
# Install utilities, libraries, and dev tools. # Install utilities, libraries, and dev tools.
RUN apk add --no-cache \ RUN apk add --no-cache \
bash curl \ bash curl \
bsd-compat-headers c-ares-dev linux-headers \ bsd-compat-headers linux-headers \
build-base cmake git ninja python3 build-base cmake git ninja python3
# Build and run this docker by mapping shaka-packager with # Build and run this docker by mapping shaka-packager with

View File

@ -3,7 +3,6 @@ FROM archlinux:latest
# Install utilities, libraries, and dev tools. # Install utilities, libraries, and dev tools.
RUN pacman -Suy --needed --noconfirm \ RUN pacman -Suy --needed --noconfirm \
core/which \ core/which \
c-ares \
cmake gcc git ninja python3 cmake gcc git ninja python3
# Build and run this docker by mapping shaka-packager with # Build and run this docker by mapping shaka-packager with

View File

@ -9,7 +9,7 @@ RUN dnf config-manager --set-enabled crb
# Install utilities, libraries, and dev tools. # Install utilities, libraries, and dev tools.
RUN yum install -y \ RUN yum install -y \
which \ which \
c-ares-devel libatomic \ libatomic \
cmake gcc-c++ git ninja-build python3 cmake gcc-c++ git ninja-build python3
# Build and run this docker by mapping shaka-packager with # Build and run this docker by mapping shaka-packager with

View File

@ -4,7 +4,6 @@ FROM debian:11
RUN apt-get update && apt-get install -y apt-utils RUN apt-get update && apt-get install -y apt-utils
RUN apt-get install -y \ RUN apt-get install -y \
curl \ curl \
libc-ares-dev \
build-essential cmake git ninja-build python3 build-essential cmake git ninja-build python3
# Build and run this docker by mapping shaka-packager with # Build and run this docker by mapping shaka-packager with

View File

@ -3,7 +3,7 @@ FROM fedora:34
# Install utilities, libraries, and dev tools. # Install utilities, libraries, and dev tools.
RUN yum install -y \ RUN yum install -y \
which \ which \
c-ares-devel libatomic \ libatomic \
cmake gcc-c++ git ninja-build python3 cmake gcc-c++ git ninja-build python3
# Build and run this docker by mapping shaka-packager with # Build and run this docker by mapping shaka-packager with

View File

@ -3,7 +3,6 @@ FROM opensuse/leap:15.5
# Install utilities, libraries, and dev tools. # Install utilities, libraries, and dev tools.
RUN zypper in -y \ RUN zypper in -y \
curl which \ curl which \
c-ares-devel \
cmake gcc9-c++ git ninja python3 cmake gcc9-c++ git ninja python3
# OpenSuse 15 doesn't have the required gcc 9+ by default, but we can install # OpenSuse 15 doesn't have the required gcc 9+ by default, but we can install

View File

@ -7,7 +7,6 @@ ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y apt-utils RUN apt-get update && apt-get install -y apt-utils
RUN apt-get install -y \ RUN apt-get install -y \
curl \ curl \
libc-ares-dev \
build-essential cmake git ninja-build python3 build-essential cmake git ninja-build python3
# Build and run this docker by mapping shaka-packager with # Build and run this docker by mapping shaka-packager with

View File

@ -27,6 +27,7 @@ endif()
# These all use EXCLUDE_FROM_ALL so that only the referenced targets get built. # These all use EXCLUDE_FROM_ALL so that only the referenced targets get built.
add_subdirectory(abseil-cpp EXCLUDE_FROM_ALL) add_subdirectory(abseil-cpp EXCLUDE_FROM_ALL)
add_subdirectory(c-ares EXCLUDE_FROM_ALL)
add_subdirectory(curl EXCLUDE_FROM_ALL) add_subdirectory(curl EXCLUDE_FROM_ALL)
add_subdirectory(googletest EXCLUDE_FROM_ALL) add_subdirectory(googletest EXCLUDE_FROM_ALL)
add_subdirectory(json EXCLUDE_FROM_ALL) add_subdirectory(json EXCLUDE_FROM_ALL)

View File

@ -0,0 +1,18 @@
# Copyright 2023 Google LLC. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
# CMake build file to host c-ares configuration.
set(CARES_STATIC ON)
set(CARES_SHARED OFF)
set(CARES_INSTALL OFF)
set(CARES_STATIC_PIC OFF)
set(CARES_BUILD_TESTS OFF)
set(CARES_BUILD_CONTAINER_TESTS OFF)
set(CARES_BUILD_TOOLS OFF)
# With these set in scope of this folder, load the library's own CMakeLists.txt.
add_subdirectory(source)

1
packager/third_party/c-ares/source vendored Submodule

@ -0,0 +1 @@
Subproject commit e8fe27eaa841ed32a4f82bef7a72c4e04e7f86a7

View File

@ -16,8 +16,12 @@ set(CURL_USE_LIBSSH2 OFF)
set(CURL_ZLIB OFF) set(CURL_ZLIB OFF)
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
# Use libcares to fix static linking on Linux. # Use c-ares to fix static linking on Linux. Set USE_ARES directly, not the
set(ENABLE_ARES ON) # ENABLE_ARES option that triggers a search for c-ares on the system.
set(USE_ARES 1)
# This is necessary when we hack the c-ares search, because we break the
# export target. We didn't need it anyway.
set(CURL_ENABLE_EXPORT_TARGET OFF)
endif() endif()
if(WIN32) if(WIN32)
@ -40,3 +44,9 @@ endif()
# With these set in scope of this folder, load the library's own CMakeLists.txt. # With these set in scope of this folder, load the library's own CMakeLists.txt.
add_subdirectory(source) add_subdirectory(source)
# Our enabling of c-ares doesn't automatically set a dependency between libcurl
# and c-ares. Fix that now.
if(USE_ARES)
target_link_libraries(libcurl c-ares)
endif()