Skip to content

Plan Import machinery

ebenali edited this page Dec 4, 2026 · 1 revision

Plan: Import machinery (F1)

Roadmap milestone F1 (Phase 0). Large upstream projects (LLVM, GCC, Mesa, Linux DRM, linux-firmware) are imported the same way: pristine upstream source, build lists generated from upstream's own build system, and a component model that decides what gets built. T1 (LLVM 23), T2 (GCC 16) and G1 (Mesa 26) are its first users; DRM, which already works this way, is moved onto it first, so the machinery is proved on an import whose output is known.

What every import has

  1. Pristine source. dist/ is byte-identical to an upstream tag. Imports are commits on a vendor/<project> branch, tagged <project>-<tag>, merged into trunk; git diff between two tags is exactly upstream's change. A paths file maps upstream paths to dist/ and keeps the import to what the build uses. Local changes never go into dist/: they go into compatibility code, or into a replacement file outside dist/ that the build lists instead, with a comment saying why (the DRM rules, made general).
  2. License classification. Every built file is classified by its SPDX tag (or its header when it has none). Files outside the project's expected license need an entry in an allowlist and, for GPL-only files in a permissive project, a build switch.
  3. Build description, generated. A reader runs upstream's build system and extracts, per target: its kind (library, program, kernel module, host tool, header set), its sources, per-file flags, include paths and defines, its dependencies, and the files generated at build time with the commands that make them (TableGen, mkregtable, Python code generators). All readers write the same intermediate description, so the emitters do not care which build system it came from.
  4. Configuration results, kept. config.h and similar files come from running upstream's configure step against the target's sysroot, per architecture, and are committed, together with the command line that made them. They are checked on the target when libc changes (as in C2a, where 353 kept results were updated).
  5. Emitted BSD make files. From the description: Makefiles for libraries and programs using bsd.lib.mk/bsd.prog.mk, files.* lists and srcs.mk for kernel code, set list entries, and mtree entries. Generated files carry a header naming the generator and the upstream tag; they are never edited by hand.
  6. A regeneration check. verify re-imports and regenerates and fails on any difference: pristine dist/, committed generated files equal to what the generators produce now. It is a maintainer and CI step; build.sh never runs a generator.

Components and presets

A project declares its components in components (one file per project): name, one-line description, the targets it owns, the components it needs (in this project or another), the set its files go to, and whether it is on by default. Components are coarse: for LLVM, roughly clang, lld, the LLVM binary tools, lldb, compiler-rt builtins, sanitizers, libunwind, libc++/libc++abi, OpenMP, clang-tools-extra, libclc; not one per library.

  • Each component is an MK variable (MKLLVM_LLD, MKMESA_VULKAN), so it is also a set-list keyword with no further work: the set tools already treat every MK variable as a selector.
  • Everything is on by default: full strength. Lighter systems come from presets: named, additive sets of components (PRESET=minimal, PRESET=server, PRESET=desktop), set with build.sh -V. An explicit MK setting overrides the preset.
  • The dependency closure is computed when bsd.own.mk is read, from a generated bsd.components.mk: turning a component on turns on what it needs; turning off something an enabled component needs is an error that names both, not a silent change.
  • make -f mkvars.mk lists components, their state and why (default, preset, explicit, needed by X).

Readers

build system used by how
Kbuild DRM GNU make evaluates each directory's Kbuild with the Kconfig options set (today's kbuild2netbsd)
CMake LLVM, compiler-rt, libc++ the CMake file API (codemodel and toolchains replies) for targets, sources and flags; ninja -t commands/-t graph for custom commands such as TableGen
meson Mesa, libdrm meson introspect (targets, sources, per-target arguments, custom targets)
autoconf + make GCC, binutils configure for the config headers; the source and flag lists from upstream's makefiles evaluated with make -n and the object lists (the mechanism decided with T2)

Where it lives

  • external/import/: the shared Python 3 package (paths, import, verify, license classification, the intermediate description, the emitters, the component closure) and one reader per build system. Python is needed only by the maintainer at import time; the build never runs it.
  • Per project, next to its dist/: import.conf (upstream repository, tag, paths), components, the license allowlist, and any per-project hooks (the DRM wrapper renaming, LLVM's TableGen rules).
  • Today's per-project tools (tools/import, verify-dist, license-check, kbuild2netbsd under DRM; firmware.sh) become thin calls into the package and are then removed.

Steps

Each step has its proof: the same output before and after, or a build that matches upstream's.

  1. Vendor tools. import, verify and license classification in the package, driven by import.conf. Proof: DRM's dist/ re-imported from v7.3.7 is byte-identical, and the license report equals today's.
  2. Description and make emitter; Kbuild reader. kbuild2netbsd ported onto the intermediate description. Proof: every generated DRM list (files.*, srcs.mk, the renamed wrappers) is unchanged, for x86_64 and aarch64.
  3. CMake reader. Proved on LLVM 23's runtimes (libunwind, libc++abi, libc++, compiler-rt builtins) and on llvm-tblgen: built through the generated makefiles, each library has the same object list and exported symbols as the CMake build of the same tag. This is the base T1 starts from.
  4. meson reader. Proved on libdrm from xsrc against its meson build, the same way: same objects, same symbols. This is the base G1 starts from.
  5. Components and presets. bsd.components.mk generation, the closure in bsd.own.mk, the listing in mkvars.mk; DRM's existing switches (MKDRM_GPL, the drivers) as the first components. Proof: the default build's set lists are unchanged; a preset that drops a component removes exactly its files; turning off a needed component fails with both names.
  6. Book chapter: how an import works, for maintainers.

autoconf comes with T2, where it is needed; LLVM's full component list comes with T1.

Clone this wiki locally