Skip to content

Hooks: Allow per-OS defines - #413

Merged
simolus3 merged 4 commits into
simolus3:mainfrom
palmoni5:hook-per-os-defines
Sep 29, 2026
Merged

simolus3 merged 4 commits into
simolus3:mainfrom
palmoni5:hook-per-os-defines

Conversation

@palmoni5

Copy link
Copy Markdown
Contributor

#406 made source and name accept a map with per-OS entries and a default. This PR extends
the same syntax to defines, so one source: source build can use different compile-time options
per target. For example, SQLITE_WIN32_MALLOC only on Windows, or a smaller set of options on
mobile:

hooks:
  user_defines:
    sqlite3:
      source: source
      path: path/to/sqlite3.c
      defines:
        windows:
          - SQLITE_WIN32_MALLOC
        default:
          default_options: false
          defines:
            - SQLITE_THREADSAFE=1

Behavior:

  • Each entry accepts the same formats as defines today: a list, or a map with default_options
    and defines.
  • A map counts as per-OS only when its keys are OS names (OS.name, as for source) or
    default. The existing keys (default_options, defines) are neither, so existing
    configurations keep their meaning (there's a test for that).
  • A map that mixes both kinds of keys throws an ArgumentError instead of being silently
    misread.
  • If the target OS has no entry and there's no default, the default options are used, the same
    as when defines is missing.

I only did this for defines. path, additional_flags and the other source: source options
(including additional_sources from #395) could get the same treatment, but I wanted to check with
you before widening the change.

Tests

  • New tests in test/hook/description_test.dart cover the entry for the target OS, the default
    fallback, a missing entry, a plain options map, and mixed keys.
  • End to end on Windows: source: source with SQLite 3.53.4 and
    defines: {windows: {defines: [SQLITE_ENABLE_RBU]}, default: [...]} builds a library where
    usedCompileOption('ENABLE_RBU') and usedCompileOption('ENABLE_FTS5') are both true, so the
    Windows entry is applied on top of the default options.
  • dart analyze --fatal-infos and dart format --set-exit-if-changed in sqlite3: clean.
  • dart test in sqlite3 (VM, Windows): 196 passed, 5 skipped.

🤖 Generated with Claude Code

Like source and name, the defines user-define can now be a map from operating system names (or default) to the defines to use for that target.
The iOS expectation wasn't formatted, which fails the format check in CI. Also test that a defines map without OS keys keeps its existing meaning.
Comment thread sqlite3/doc/hook.md Outdated
Instead of a separate example for per-OS defines, state that the map syntax already described for source is available for defines as well.
@palmoni5

Copy link
Copy Markdown
Contributor Author

Thanks! Done in a25e5ba: I removed the separate example and paragraph, and the existing paragraph now says the map syntax is available for source and defines.

@simolus3
simolus3 merged commit f37ce7f into simolus3:main Sep 29, 2026
10 checks passed
@palmoni5
palmoni5 deleted the hook-per-os-defines branch September 29, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants