Skip to content

Commit 044db27

Browse files
authored
0.1.0: FreeBSD, NetBSD and OpenBSD rows, their bases and runners (#1)
* The package and the procedure for adding a system * FreeBSD: the base and the runner of mcpp's x86_64-freebsd and aarch64-freebsd rows * NetBSD 10.2: x86_64-netbsd and aarch64-netbsd, their bases, and the runner of x86_64 * OpenBSD 8.0: x86_64-openbsd and aarch64-openbsd, their bases, and the runner of x86_64 * CI: every row's check built on three hosts and run where the row has a runner * NetBSD: the C++ layer is libc++ from source over the system's C library, so the rows compile import std GCC 10's libstdc++ ships no module sources. The NetBSD providers name llvm.libcxx as their c++-abi layer; libc++abi unwinds through libgcc_s, which clang's NetBSD driver does not name, so the rows state it. * OpenBSD: the runner takes openbsd-disk-image 8.0-1, whose profile parses * Runners: the disk images whose profiles run the command where its files are (freebsd 14.5-1, netbsd 10.2-1) * Docs link mcpp's specifications and documents; the check names the platform once, for every row (cfg of the row's os) * runner = true, the consent to the row's runner * CI and docs: the rows build on Linux hosts (x86_64, aarch64); a macOS or Windows host does not build them yet, and what reaches the row there
1 parent f333da4 commit 044db27

7 files changed

Lines changed: 415 additions & 1 deletion

File tree

‎.github/workflows/ci.yml‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# The rows of mcpp.platforms (docs/adding-a-system.md, "A check"):
2+
#
3+
# build every row's check (checks/hello: the std module, an exception, its
4+
# arguments) is built on the Linux hosts, x86_64 and aarch64, and the
5+
# artifact is an ELF executable of the row's system and machine
6+
# (docs/adding-a-system.md, "Hosts": a macOS or Windows host does not
7+
# build these rows yet);
8+
# run on Linux x86_64, every row with a runner runs the check through
9+
# `mcpp run`: dirun boots the system's disk image under QEMU, and the
10+
# program's output and status (7) come back.
11+
name: ci
12+
13+
on:
14+
push:
15+
branches: [main]
16+
pull_request:
17+
workflow_dispatch:
18+
19+
concurrency:
20+
group: ci-${{ github.ref }}
21+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
22+
23+
env:
24+
MCPP_VERSION: "2026.11.17.1"
25+
26+
jobs:
27+
build:
28+
name: build ${{ matrix.row }} on ${{ matrix.os }}
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
os: [ubuntu-24.04, ubuntu-24.04-arm]
33+
row: [x86_64-freebsd, aarch64-freebsd, x86_64-netbsd, aarch64-netbsd, x86_64-openbsd, aarch64-openbsd]
34+
runs-on: ${{ matrix.os }}
35+
timeout-minutes: 60
36+
defaults:
37+
run:
38+
shell: bash
39+
working-directory: checks/hello
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: mcpp-community/setup-mcpp@v1
43+
with:
44+
version: ${{ env.MCPP_VERSION }}
45+
- name: Build the check for ${{ matrix.row }}
46+
run: |
47+
mcpp build --target "${{ matrix.row }}"
48+
exe=$(find "target/${{ matrix.row }}" -path '*/bin/hello' -type f | head -1)
49+
[ -n "$exe" ] || { echo "::error::no executable for ${{ matrix.row }}"; exit 1; }
50+
python3 - "$exe" "${{ matrix.row }}" <<'PY'
51+
import sys
52+
data = open(sys.argv[1], "rb").read(64)
53+
row = sys.argv[2]
54+
machine = int.from_bytes(data[18:20], "little")
55+
want = {"x86_64": 62, "aarch64": 183}[row.split("-")[0]]
56+
osabi = data[7]
57+
if data[:4] != b"\x7fELF" or machine != want:
58+
sys.exit(f"::error::{sys.argv[1]} is not an ELF executable for {row} (machine {machine})")
59+
print(f"{row}: ELF, machine {machine}, OS/ABI {osabi}")
60+
PY
61+
62+
run:
63+
name: run ${{ matrix.row }} (Linux x86_64, QEMU)
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
row: [x86_64-freebsd, aarch64-freebsd, x86_64-netbsd, x86_64-openbsd]
68+
runs-on: ubuntu-24.04
69+
timeout-minutes: 60
70+
defaults:
71+
run:
72+
shell: bash
73+
working-directory: checks/hello
74+
steps:
75+
- uses: actions/checkout@v4
76+
# A guest of the host's architecture runs with KVM.
77+
- name: KVM for the runner's emulator
78+
working-directory: .
79+
run: |
80+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm.rules
81+
sudo udevadm control --reload-rules && sudo udevadm trigger --name-match=kvm
82+
- uses: mcpp-community/setup-mcpp@v1
83+
with:
84+
version: ${{ env.MCPP_VERSION }}
85+
- name: Run the check on ${{ matrix.row }}
86+
run: |
87+
set +e
88+
mcpp run --target "${{ matrix.row }}" -- one "two three" | tr -d '\r' | tee run.log
89+
status=${PIPESTATUS[0]}
90+
set -e
91+
grep -q 'platforms ok: caught \["one", "two three"\]' run.log || { echo "::error::the program's output or arguments"; exit 1; }
92+
[ "$status" -eq 7 ] || { echo "::error::the program returned $status, not 7"; exit 1; }

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
.mcpp/
3+
mcpp.lock

‎README.md‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,54 @@
11
# mcpp-platforms
22

3-
Rows for systems mcpp's built-in table does not carry, as one platform package, `mcpp.platforms`.
3+
Rows for systems mcpp's built-in table does not carry, as one platform package,
4+
`mcpp.platforms`: each system's triples, the base each row links against, and a
5+
runner that boots the system to run its programs. The engine names no system;
6+
these rows are data it reads (mcpp [SPEC-013](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/platforms.md),
7+
[SPEC-016](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/targets-and-providers.md)).
8+
9+
```sh
10+
mcpp build --target x86_64-netbsd # the package index names this platform for the row
11+
mcpp run --target x86_64-netbsd # once the row's runner is enabled
12+
```
13+
14+
| Row | Base | C++ library | Runner |
15+
|---|---|---|---|
16+
| `x86_64-freebsd` | `xim:x86_64-freebsd-sysroot@14.5` | the base's libc++ | FreeBSD 14.5 in QEMU (dirun) |
17+
| `aarch64-freebsd` | `xim:aarch64-freebsd-sysroot@14.5` | the base's libc++ | FreeBSD 14.5 in QEMU (dirun) |
18+
| `x86_64-netbsd` | `xim:x86_64-netbsd-sysroot@10.2` | libc++ from source (`llvm.libcxx`) | NetBSD 10.2 in QEMU (dirun) |
19+
| `aarch64-netbsd` | `xim:aarch64-netbsd-sysroot@10.2` | libc++ from source (`llvm.libcxx`) | none |
20+
| `x86_64-openbsd` | `xim:x86_64-openbsd-sysroot@8.0` | the base's libc++ | OpenBSD 8.0 in QEMU (dirun) |
21+
| `aarch64-openbsd` | `xim:aarch64-openbsd-sysroot@8.0` | the base's libc++ | none |
22+
23+
The rows build on a Linux host, x86_64 or aarch64; a macOS or Windows host does
24+
not build them yet ([docs/adding-a-system.md](docs/adding-a-system.md#hosts)).
25+
26+
Every row compiles `import std`. NetBSD's own C++ library is GCC 10's
27+
libstdc++, which ships no module sources; its rows take the C++ layer from
28+
libc++ built over NetBSD's C library (the providers' `layers`), and the
29+
compiler runtime, libgcc_s, stays the system's.
30+
31+
A runner fetches a machine image on its first use, so it is off until a
32+
project or a machine enables it, for one row or for every row of this
33+
platform:
34+
35+
```toml
36+
[target.x86_64-netbsd]
37+
runner = true
38+
39+
[target.'cfg(platform = "platforms")']
40+
runner = true
41+
```
42+
43+
Adding a system: [docs/adding-a-system.md](docs/adding-a-system.md).
44+
45+
## Further reading
46+
47+
| Topic | mcpp document |
48+
|---|---|
49+
| What a platform is, how a project selects one, and the index's platform column | [docs/35 Platforms](https://github.com/mcpp-community/mcpp/blob/main/docs/35-platforms.md); [SPEC-013 Platforms](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/platforms.md) |
50+
| Rows, providers, systems and runners as data | [SPEC-016 Targets and providers](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/targets-and-providers.md) |
51+
| The layers of the target side and base packages (a sysroot with `mcpp.toml`) | [docs/22 The target side](https://github.com/mcpp-community/mcpp/blob/main/docs/22-target-side.md); [SPEC-002](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/target-side.md) |
52+
| Running a program on another system: runners, `enabled`, `--file` | [docs/41 Devices](https://github.com/mcpp-community/mcpp/blob/main/docs/41-devices.md); [docs/09 Commands by scenario](https://github.com/mcpp-community/mcpp/blob/main/docs/09-commands-by-scenario.md) |
53+
| `[target.<selector>]` and `cfg(...)` | [docs/04 mcpp.toml](https://github.com/mcpp-community/mcpp/blob/main/docs/04-mcpp-toml.md); [manifest semantics](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/manifest-semantics.md) |
54+
| The sysroot and disk image packages, and their dirun profiles | [xim-pkgindex docs/12 Disk image assets](https://github.com/openxlings/xim-pkgindex/blob/main/docs/12-disk-image-assets.md) |

‎checks/hello/mcpp.toml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The check of every row (.github/workflows/ci.yml): a C++ program with the std
2+
# module, an exception and its arguments, built for the row and, where the row
3+
# has a runner, run there; its status is 7.
4+
[package]
5+
name = "hello"
6+
version = "0.1.0"
7+
8+
# Every row of this repository's platform, from the working copy rather than
9+
# the package index, with its runner enabled where it has one. Before the
10+
# platform defines a row, `cfg(os = ...)` is answered by the triple as written
11+
# (mcpp SPEC-013 §3.1).
12+
[target.'cfg(any(os = "freebsd", os = "netbsd", os = "openbsd"))']
13+
platform = { path = "../.." }
14+
runner = true

‎checks/hello/src/main.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import std;
2+
3+
int main(int argc, char** argv) {
4+
std::vector<std::string> args(argv + 1, argv + argc);
5+
try {
6+
throw std::runtime_error("caught");
7+
} catch (const std::exception& e) {
8+
std::println("platforms ok: {} {}", e.what(), args);
9+
}
10+
return 7;
11+
}

‎docs/adding-a-system.md‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Adding a system
2+
3+
A system enters `mcpp.platforms` as rows of its triples, each served by a
4+
provider that names the system's base and, where the system can be booted, a
5+
runner. The semantics are mcpp's ([SPEC-013 Platforms](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/platforms.md),
6+
[SPEC-016 Targets and providers](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/targets-and-providers.md)); this
7+
document states the procedure and what each part must hold.
8+
9+
## The systems
10+
11+
| System | Rows | Base | Runner | State |
12+
|---|---|---|---|---|
13+
| FreeBSD 14.5 | `x86_64-freebsd`, `aarch64-freebsd` (mcpp's built-in rows) | the release's base set | both | `preview` |
14+
| NetBSD 10.2 | `x86_64-netbsd`, `aarch64-netbsd` | the release's base and comp sets; the C++ layer is libc++ from source (`llvm.libcxx`) | x86_64 | `preview` |
15+
| OpenBSD 8.0 | `x86_64-openbsd`, `aarch64-openbsd` | the release's base and comp sets | x86_64 | `preview` |
16+
| illumos (OmniOS r151054) | none | assembled, not published | measured | not included: see below |
17+
18+
illumos is not included. Its sysroot and disk image were assembled, and C and
19+
C++ programs linked with lld ran on OmniOS r151054. But clang's Solaris driver
20+
links only through the system's own linker: it runs `/usr/bin/ld` with Solaris
21+
options (`-C`, `-z ignore`), ignores `--ld-path` and `-B`, and refuses lld as a
22+
`-fuse-ld` name. A row can state no program that translates those options for
23+
lld. The row enters when either a platform can name the program the compiler
24+
links with, or clang's Solaris driver gives lld the GNU options.
25+
26+
## Hosts
27+
28+
The rows build on a Linux host, x86_64 or aarch64, which this repository's CI
29+
checks. A macOS or Windows host does not build them yet. Measured in the CI of
30+
0.1.0 with mcpp 2026.11.17.1, the host's own conventions reach the row:
31+
32+
| Host | What reaches the row |
33+
|---|---|
34+
| macOS | the Apple SDK's headers in the std module's compile (FreeBSD); libc++ compiled against the host's ctype definitions (NetBSD, `_CTYPE_BL`); the Mach-O linker given ELF options (OpenBSD, `ld64.lld: unknown argument '--disable-new-dtags'`) |
35+
| Windows | the sysroot's headers not opened (NetBSD, `sys/cdefs.h`); the crt objects not found and the program named `.exe` (FreeBSD) |
36+
37+
These are mcpp's to correct (the row, not the host, decides a cross build); the
38+
rows enter the build matrix of a host when it builds them.
39+
40+
## What a system brings
41+
42+
| Part | Where | Holds |
43+
|---|---|---|
44+
| The system | `[[platform.system]]` in `mcpp.toml` | `name`, the row's os word; `uname`, what `uname -s` answers there |
45+
| A row per architecture | `[[platform.define]]` | `triple`, `clang-triple` (with the release the sysroot is), `loader`, `object-format = "elf"`, `family`, `execution`, `tier = "preview"`, `standard` |
46+
| A provider per row | `[[platform.provider]]` | `serves`, `sysroot = "xim:<arch>-<system>-sysroot@<release>"`, `hosted = true`, and for a row whose image exists a `runner` with `enabled = false`; `layers` when a layer comes from a package rather than from the base (below) |
47+
| A sysroot package | xim-pkgindex, `<arch>-<system>-sysroot` | the release's own headers, crt objects, shared libraries and the static archives of the C library, the C++ run-time and the compiler run-time, with a `mcpp.toml` at its root stating the layers it provides ([mcpp docs/22](https://github.com/mcpp-community/mcpp/blob/main/docs/22-target-side.md), base packages; [SPEC-002 §2.5](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/target-side.md)) |
48+
| A disk image package | xim-pkgindex, `<system>-disk-image` | the release's official media made a bootable qcow2 with a serial console, and the dirun profile that boots it ([xim-pkgindex docs/12](https://github.com/openxlings/xim-pkgindex/blob/main/docs/12-disk-image-assets.md)) |
49+
| A check | `.github/workflows/ci.yml` | the row builds a C program and a C++ program with an exception; where it has a runner, both run and their status returns |
50+
51+
The assembly of each package is a script in xim-pkgindex `.agents/tools/`
52+
that starts from the publisher's signed or digest-listed release files and
53+
records them in the package's `PROVENANCE.md`. A change the image needs (a
54+
serial console, a login) is stated there, at its byte or as the script that
55+
made it.
56+
57+
## `import std`
58+
59+
Every row compiles `import std`. A base whose C++ library ships module sources
60+
states them (`std-module`, [mcpp docs/22](https://github.com/mcpp-community/mcpp/blob/main/docs/22-target-side.md)); FreeBSD and OpenBSD ship libc++, and
61+
their sysroots carry the module sources of its release. A system whose C++
62+
library ships none (NetBSD: GCC 10's libstdc++) takes the C++ layer from a
63+
package instead, libc++ built from source over the system's C library:
64+
65+
```toml
66+
[[platform.provider]]
67+
serves = ["x86_64-netbsd"]
68+
sysroot = "xim:x86_64-netbsd-sysroot@10.2"
69+
layers = { "c++-abi" = "llvm.libcxx@22.1.8.3" }
70+
```
71+
72+
The package replaces the base for that layer alone: the base's C++ headers and
73+
libraries leave the build, and the C library and the compiler runtime stay the
74+
system's. What the replacement needs of the compiler runtime and the driver
75+
does not name is stated for the system's rows (`[platform.build.'cfg(os =
76+
"netbsd")'] ldflags`: libc++abi unwinds through libgcc_s).
77+
78+
## The image
79+
80+
The image's profile states what the image answers: the boot prompts, the
81+
login, the shell's quoting and where a disk of files is mounted. It needs no
82+
network and no interaction beyond the profile's steps. A runner is
83+
`dirun --profile {pkg:<system>-disk-image}/dirun.toml -- {}`, with the
84+
emulator a package of xim; it stays `enabled = false`, because its first use
85+
fetches a machine image ([SPEC-016 §6](https://github.com/mcpp-community/mcpp/blob/main/docs/specs/targets-and-providers.md)). A project or a machine enables it:
86+
87+
```toml
88+
[target.x86_64-netbsd]
89+
runner = true
90+
```
91+
92+
## Tiers
93+
94+
- `preview`: the row builds in this repository's CI; where it has a runner,
95+
its programs run there.
96+
- `stable`: in addition, a project outside this repository has built and run
97+
a program of the row through mcpp's own commands (`mcpp build`, `mcpp run`,
98+
`mcpp test`), and the row's packages have had one release without a
99+
correction.
100+
- A row moves into mcpp's built-in table when its system is common enough that
101+
a project should not need a platform for it, and the engine then carries the
102+
row's data; its provider stays here.
103+
104+
## What may not be added
105+
106+
- A system name in the engine: the engine reads the rows as data.
107+
- A sysroot or image assembled from anything but the publisher's media.
108+
- A runner that needs a network or a person to finish booting.

0 commit comments

Comments
 (0)