Skip to content
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
23 changes: 17 additions & 6 deletions .github/workflows/boring_binaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
precompile:
name: Precompile (${{ matrix.target-os }}-${{ matrix.target-arch }}${{ matrix.ios-sdk && format('-{0}', matrix.ios-sdk) || '' }})
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}

Check failure on line 46 in .github/workflows/boring_binaries.yaml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-images

boring_binaries.yaml:46: unpinned image references: container image is unpinned

Check failure on line 46 in .github/workflows/boring_binaries.yaml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-images

boring_binaries.yaml:46: unpinned image references: container image is unpinned
permissions:
contents: read
id-token: write # To sign the provenance attestations of the libraries.
Expand All @@ -60,16 +61,21 @@
# `macOSDeploymentTargets` and `iOSDeploymentTarget` in
# tool/precompile_binaries.dart.
include:
# The oldest available Ubuntu, so the libraries only require glibc
# 2.35.
- os: ubuntu-22.04
# Built in manylinux_2_28 (AlmaLinux 8) containers, so the libraries
# run on glibc 2.28 and later, for example on Debian 10, Ubuntu 20.04,
# and RHEL 8, not only on the runner's glibc. Older glibc can't run
# the actions (Node.js) in the container. Keep `max-glibc` in sync
# with `prebuiltLinuxGlibc` in lib/src/hook_helpers/libc.dart.
- os: ubuntu-24.04
container: quay.io/pypa/manylinux_2_28_x86_64
target-os: linux
target-arch: x64
max-glibc: '2.35'
- os: ubuntu-22.04-arm
max-glibc: '2.28'
- os: ubuntu-24.04-arm
container: quay.io/pypa/manylinux_2_28_aarch64
target-os: linux
target-arch: arm64
max-glibc: '2.35'
max-glibc: '2.28'
- os: macos-15
target-os: macos
target-arch: arm64
Expand Down Expand Up @@ -111,6 +117,11 @@
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
# The manylinux images have GCC, CMake, and Make, but setup-dart needs
# unzip.
- name: Install unzip (manylinux)
if: matrix.container
run: dnf install -y unzip
- uses: dart-lang/setup-dart@6afc89df92d6eb3834022f73cd65adc8cdfcb92d
with:
sdk: stable
Expand Down
5 changes: 5 additions & 0 deletions pkgs/boring/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 0.4.3-wip
- The prebuilt Linux libraries run on glibc 2.28 and later (for example
Debian 10, Ubuntu 20.04, and RHEL 8), instead of 2.35. On systems with an
older glibc or another C library, such as musl on Alpine Linux, the
`fetch` build mode fails with a hint to use `buildMode: checkout`, instead
of bundling a library that fails to load.
- BoringSSL is compiled with `OPENSSL_SMALL`, which for example makes the
tree-shaken library of `package:webcrypto` about 19% smaller, and P-256
operations about 2x slower.
Expand Down
11 changes: 6 additions & 5 deletions pkgs/boring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ hooks:
- **`local`**: Uses a custom prebuilt dynamic library at `localPath`, which is
bundled as is, without [tree-shaking](#tree-shaking).

Prebuilt libraries exist for Linux (x64 and arm64), macOS (arm64 and x64),
Windows (x64), Android (arm, arm64 and x64; API 21 and later), and iOS (arm64,
and the arm64 and x64 simulators; iOS 12 and later). Other targets require
`buildMode: checkout`, which requires CMake, Ninja, and a C toolchain (Clang or
GCC, Xcode, MSVC, or the Android NDK), plus NASM on Windows.
Prebuilt libraries exist for Linux (x64 and arm64; glibc 2.28 and later, not
musl), macOS (arm64 and x64), Windows (x64), Android (arm, arm64 and x64; API 21
and later), and iOS (arm64, and the arm64 and x64 simulators; iOS 12 and later).
Other targets require `buildMode: checkout`, which requires CMake, Ninja, and a
C toolchain (Clang or GCC, Xcode, MSVC, or the Android NDK), plus NASM on
Windows.

When the Dart runtime uses a sanitizer, for example with `dart test -p
vm-asan`, the `fetch` build mode compiles BoringSSL from source with that
Expand Down
13 changes: 13 additions & 0 deletions pkgs/boring/lib/src/hook_helpers/fetch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:crypto/crypto.dart' show sha256;
import 'package:hooks/hooks.dart';

import 'hashes.dart' show fileHashes, releaseRepository, releaseTag;
import 'libc.dart' show currentGlibcVersion, unsupportedLinuxLibcReason;
import 'targets.dart'
show libraryFileName, releaseAssetName, releaseAssetUrl, targetTripleFor;

Expand Down Expand Up @@ -58,6 +59,18 @@ Future<Uri> fetchPrebuiltLibrary(
);
}

// The prebuilt libraries would fail to load on another C library. Only the
// C library of this machine is known, so this only checks builds for it, as
// in `dart run` and `dart test`.
if (targetOS == OS.linux &&
OS.current == OS.linux &&
targetArch == Architecture.current) {
final reason = unsupportedLinuxLibcReason(currentGlibcVersion());
if (reason != null) {
throw BuildError(message: '$reason\n$_checkoutHint');
}
}

final fileName = libraryFileName(targetOS, static: static);
final cachedFile = File.fromUri(
input.outputDirectoryShared
Expand Down
56 changes: 56 additions & 0 deletions pkgs/boring/lib/src/hook_helpers/libc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:ffi';

/// The oldest glibc that the prebuilt Linux libraries run on.
///
/// Keep in sync with `max-glibc` of the Linux targets in
/// `.github/workflows/boring_binaries.yaml`, which checks the libraries.
const prebuiltLinuxGlibc = (2, 28);

/// The version of the GNU C library (glibc) of this process, or `null` if the
/// process doesn't use glibc, for example on Alpine Linux, which uses musl.
(int, int)? currentGlibcVersion() {
final process = DynamicLibrary.process();
if (!process.providesSymbol('gnu_get_libc_version')) {
return null;
}
final gnuGetLibcVersion = process
.lookupFunction<Pointer<Uint8> Function(), Pointer<Uint8> Function()>(
'gnu_get_libc_version',
);
final version = gnuGetLibcVersion();
final bytes = <int>[];
for (var i = 0; version[i] != 0; i++) {
bytes.add(version[i]);
}
return parseGlibcVersion(String.fromCharCodes(bytes));
}

/// Parses the major and minor version from a glibc version string, such as
/// `2.35` or `2.39.9000`.
(int, int)? parseGlibcVersion(String version) {
final match = RegExp(r'^(\d+)\.(\d+)').firstMatch(version);
if (match == null) {
return null;
}
return (int.parse(match[1]!), int.parse(match[2]!));
}

/// Why the prebuilt Linux libraries can't run with the C library
/// [glibcVersion] (see [currentGlibcVersion]), or `null` if they can.
String? unsupportedLinuxLibcReason((int, int)? glibcVersion) {
final (minMajor, minMinor) = prebuiltLinuxGlibc;
if (glibcVersion == null) {
return 'The prebuilt Linux libraries require glibc, but this system uses '
'another C library, such as musl on Alpine Linux.';
}
final (major, minor) = glibcVersion;
if (major < minMajor || (major == minMajor && minor < minMinor)) {
return 'The prebuilt Linux libraries require glibc $minMajor.$minMinor or '
'newer, but this system has glibc $major.$minor.';
}
return null;
}
36 changes: 36 additions & 0 deletions pkgs/boring/test/hook_helpers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'package:boring/src/hook_helpers/build_options.dart';
import 'package:boring/src/hook_helpers/fetch.dart';
import 'package:boring/src/hook_helpers/hashes.dart';
import 'package:boring/src/hook_helpers/libc.dart';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To use DynamicLibrary in the test to robustly detect glibc presence, we need to import dart:ffi.

Suggested change
import 'package:boring/src/hook_helpers/libc.dart';
import 'dart:ffi';
import 'package:boring/src/hook_helpers/libc.dart';

import 'package:boring/src/hook_helpers/targets.dart';
import 'package:code_assets/code_assets.dart';
import 'package:hooks/hooks.dart';
Expand Down Expand Up @@ -136,6 +137,41 @@ void main() {
});
});

group('libc.dart', () {
test('parses glibc versions', () {
expect(parseGlibcVersion('2.35'), equals((2, 35)));
expect(parseGlibcVersion('2.39.9000'), equals((2, 39)));
expect(parseGlibcVersion('unknown'), isNull);
});

test('accepts glibc from prebuiltLinuxGlibc on', () {
final (major, minor) = prebuiltLinuxGlibc;
expect(unsupportedLinuxLibcReason((major, minor)), isNull);
expect(unsupportedLinuxLibcReason((major, minor + 7)), isNull);
expect(unsupportedLinuxLibcReason((major + 1, 0)), isNull);
});

test('rejects older glibc and other C libraries', () {
final (major, minor) = prebuiltLinuxGlibc;
expect(
unsupportedLinuxLibcReason((major, minor - 1)),
contains('require glibc $major.$minor or newer'),
);
expect(unsupportedLinuxLibcReason(null), contains('musl'));
});

test('finds the glibc of this process', () {
final version = currentGlibcVersion();
if (Platform.isLinux) {
// The CI runners use glibc.
expect(version, isNotNull);
expect(unsupportedLinuxLibcReason(version), isNull);
} else {
expect(version, isNull);
}
});
Comment on lines +163 to +172

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The test currently assumes that any Linux platform runs glibc (Platform.isLinux implies version != null). However, on non-glibc Linux distributions (such as Alpine Linux which uses musl), currentGlibcVersion() will return null, causing this test to fail. Since this PR specifically aims to support and detect non-glibc environments, the test should be robust against them.

Instead of checking Platform.isLinux, we can check if the process actually provides the gnu_get_libc_version symbol.

Suggested change
test('finds the glibc of this process', () {
final version = currentGlibcVersion();
if (Platform.isLinux) {
// The CI runners use glibc.
expect(version, isNotNull);
expect(unsupportedLinuxLibcReason(version), isNull);
} else {
expect(version, isNull);
}
});
test('finds the glibc of this process', () {
final version = currentGlibcVersion();
final hasGlibc = DynamicLibrary.process().providesSymbol('gnu_get_libc_version');
if (hasGlibc) {
expect(version, isNotNull);
expect(unsupportedLinuxLibcReason(version), isNull);
} else {
expect(version, isNull);
}
});

});

group('fetchPrebuiltLibrary', () {
test('throws a BuildError when no prebuilt binary exists for target', () {
final builder = BuildInputBuilder()
Expand Down
Loading