Repository navigation
[boring] Run the prebuilt Linux libraries on glibc 2.28, and detect other C libraries #2894
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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'; | ||||||||||||||||||||||||||||||||||||||||||
| import 'package:boring/src/hook_helpers/targets.dart'; | ||||||||||||||||||||||||||||||||||||||||||
| import 'package:code_assets/code_assets.dart'; | ||||||||||||||||||||||||||||||||||||||||||
| import 'package:hooks/hooks.dart'; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test currently assumes that any Linux platform runs glibc ( Instead of checking
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| group('fetchPrebuiltLibrary', () { | ||||||||||||||||||||||||||||||||||||||||||
| test('throws a BuildError when no prebuilt binary exists for target', () { | ||||||||||||||||||||||||||||||||||||||||||
| final builder = BuildInputBuilder() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use
DynamicLibraryin the test to robustly detect glibc presence, we need to importdart:ffi.