Skip to content

[boring] Compile with the sanitizer of the Dart runtime - #2893

Draft
mosuem wants to merge 1 commit into
mainfrom
boring-build-options
Draft

mosuem wants to merge 1 commit into
mainfrom
boring-build-options

Conversation

@mosuem

@mosuem mosuem commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Note

This PR was generated by an AI coding agent (Jetski) on behalf of @mosuem.

Sanitizers

The build hook ignored input.config.code.sanitizer. So dart test -p vm-asan loaded uninstrumented BoringSSL, and package:webcrypto's ASan CI job (google/webcrypto.dart#424) no longer checks BoringSSL since it moved to package:boring. Now, like webcrypto's old build hook:

  • With a sanitizer, the checkout build compiles with Clang and -fsanitize=address|memory|thread, via BSSL_DART_SANITIZER in src/CMakeLists.txt.
  • The fetch build mode builds from source in that case, because the prebuilt libraries aren't instrumented. It never uses an uninstrumented library with a sanitizer. If CMake, Ninja, or Clang are missing, the hook fails.
  • A new asan CI job runs test/boring_test.dart with -p vm-asan. Locally, it passes, and the built library references 41 __asan_* symbols, compared with none without a sanitizer.

.inc build inputs

BoringSSL has 91 .inc files, such as crypto/fipsmodule/*.cc.inc, which the checkout build didn't list as dependencies, so it didn't rebuild when they changed. google/webcrypto.dart#429 fixed the same issue.

Testing

Rebased on 0.5.1-wip. Locally on Linux x64: dart test (34 passed, 5 skipped) and dart test -c cli -p vm-asan test/boring_test.dart.

@mosuem
mosuem requested a review from a team as a code owner November 17, 2026 15:13
@github-actions github-actions Bot added type-infra A repository infrastructure change or enhancement package:boring labels Nov 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request adds support for compiling BoringSSL with sanitizers (ASan, MSan, or TSan) when the Dart runtime uses them, which automatically triggers building from source. It also enables the 'OPENSSL_SMALL' compilation flag to reduce the tree-shaken library size at the cost of slower P-256 operations. The review feedback suggests simplifying the build mode override logic in 'pkgs/boring/hook/build.dart' to leverage Dart's flow analysis and eliminate the need for a null assertion operator on the sanitizer variable.

Comment thread pkgs/boring/hook/build.dart Resolved
@mosuem
mosuem added this pull request to stack #2895 November 17, 2026 15:24
Base automatically changed from boring-bn-ulong-uintptr to main November 18, 2026 08:38
@mosuem
mosuem force-pushed the boring-build-options branch from 56ca107 to a000c1c Compare November 18, 2026 08:38
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Health

Publish ✔️
Package Version Status Publish tag (post-merge)
package:boring ⭐ 0.5.1-wip WIP (no publish necessary)
  • 12 already published.
  • 30 WIP (no publish necessary).

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

This check can be disabled by tagging the PR with skip-publish-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check (for example, for non-user-visible changes when the package version is already at -wip).

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
boring None 0.5.0 0.5.1-wip 0.5.1-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Unused Dependencies ✔️
Package Status
boring ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

License Headers ✔️
// 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.

Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/html/test/differential_test.dart
pkgs/html/test/dom_parsing_test.dart
pkgs/html/test/mxss_test.dart
pkgs/html/test/noah_ark_clause_limit_test.dart

This check can be disabled by tagging the PR with skip-license-check.

Coverage ⚠️
File Coverage
pkgs/boring/hook/build.dart 💔 Not covered

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

sanitizer != null && buildOptions.buildMode == BuildModeEnum.fetch
? BuildModeEnum.checkout
: buildOptions.buildMode;
if (buildMode != buildOptions.buildMode) {

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.

What kind of failure do you get if you don't have the toolchain to support this? I'm worried that this kind of optionality with fallbacks is making the package more complex than it needs to be.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You mean in case I specify a sanitizer but don't want to build? We could just throw here.

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.

If you throw, you cannot run any tests even ones that don't use boringssl in your project at all if package:boring is in your dependency graph.

Fallbacks is a bad idea for sanitizers. If you don't support sanitizers you should fail the hook. Sanitizers running with half instrumented code give all kinds of weird results.

'CMAKE_INSTALL_PREFIX': installDir.toFilePath(),
// The Dart SDK's sanitizer runtimes come from Clang, so compile with
// Clang instead of the compiler of the build config's toolchain.
if (sanitizer != null) ...{

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.

This seems fragile. Maybe build hooks can help with this somehow? @dcharkes

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.

Why do we need this?
The Dart SDK doesn't provide toolchains at all in the cCompilerConfig? What build config are you referring to?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We use native_toolchain_cmake, which does pass a toolchain. But this is probably not the right place to make that fix...

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.

Are you saying native_toolchain_cmake has a bug when you specify santizers? then it should be fixed there.

Comment thread pkgs/boring/src/CMakeLists.txt Outdated

# Symbol prefixing: all BoringSSL symbols become bssl_dart_<symbol>
add_definitions(-DBORINGSSL_PREFIX=bssl_dart)
# Smaller precomputed tables, mainly for P-256, in exchange for slower

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.

The size difference didn't seem very important (~15%?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well I think 15% is a lot.. But happy to push optimizations to a later stage.

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.

When compiling from source, you could make it configurable via a user-define.
For precompiled, every combination of options would lead to an exponential set of predefined dylibs, so we have to chose a default.

Comment thread pkgs/boring/CHANGELOG.md Outdated
@@ -1,4 +1,11 @@
## 0.4.3-wip
- BoringSSL is compiled with `OPENSSL_SMALL`, which for example makes the

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.

I think that this should be two changes:

  1. sanitizer support
  2. OPENSSL_SMALL support

The build hook ignored the `sanitizer` of the build config, so for example
`dart test -p vm-asan` loaded an uninstrumented BoringSSL, and
package:webcrypto's ASan CI job (google/webcrypto.dart#424) no longer
checks BoringSSL since it moved to package:boring.

- With a sanitizer, compile BoringSSL with it and Clang, like
  package:webcrypto's build hook did. The prebuilt libraries aren't
  instrumented, so the `fetch` build mode builds from source in that case.
- Add an `asan` CI job.
- List BoringSSL's `.inc` files as dependencies of the `checkout` build, like
  google/webcrypto.dart#429.
@mosuem
mosuem force-pushed the boring-build-options branch from a000c1c to e241a3e Compare November 19, 2026 13:30
@mosuem mosuem changed the title [boring] Compile with OPENSSL_SMALL and the sanitizer of the Dart runtime [boring] Compile with the sanitizer of the Dart runtime Nov 19, 2026
@mosuem
mosuem marked this pull request as draft November 19, 2026 13:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package:boring type-infra A repository infrastructure change or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants