Repository navigation
Expand file tree
/
Copy pathbuild.mcpp
More file actions
91 lines (89 loc) · 4.54 KB
/
Copy pathbuild.mcpp
File metadata and controls
91 lines (89 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import mcpp;
import std;
// WHERE THIS SYSTEM'S NAMES COME FROM, PUT ON THE CONSUMER'S LINK LINE.
//
// `port/libSystem.tbd` lists the whole of what a program above openkal borrows
// from this system — two names, and a third that belongs to the object format.
// A stub is a list of names rather than code, so linking against it is what
// makes the program name `/usr/lib/libSystem.B.dylib` and bind to the real
// library when it runs.
//
// IT HAS TO BE A SEARCH PATH RATHER THAN A FILE ON THE LINE, and it has to
// come from HERE rather than from whoever is building. `link_search` reaches
// the CONSUMER's link line — the package that knows this system is not the
// package being built — and a relative path in `ldflags` would resolve against
// the build directory instead of against this package.
//
// Measured 2026-08-23: cross-linking for this system from Linux failed with
// `library not found for -lSystem`, because the only thing that had ever put
// the stub on a link line was a shell script
// (`openkal-musl/tools/cross-build-macos.sh`) that names the file directly. A
// build tool that resolves this package should not need that script.
//
// AND ONLY WHEN THIS SYSTEM'S OWN STUB IS NOT PRESENT, WHICH THE FIRST
// VERSION OF THIS FILE GOT WRONG.
//
// It said "not conditional on the host" and meant it as a principle. The
// principle was aimed at the right thing — a package should not need a shell
// script, and a cross build should not depend on where it happens — but the
// conclusion drawn from it was false, because this file is not the only thing
// that can put a `libSystem` on the search path. On this system, the SDK
// already has one, it is the vendor's, and it lists everything rather than
// three names.
//
// ⇒ Adding ours ahead of it does not augment it. `-L` is searched before the
// SDK, so `-lSystem` stops at the first match, and a program that needs
// `strlen` is told there is no such name.
//
// Measured 2026-08-22, this package's own conformance suite on a macOS
// runner, one commit after the line was added:
//
// ld64.lld: error: undefined symbol: strlen
// >>> referenced by …/xim-x-llvm/20.1.7/lib/libc++.a(stdexcept.cpp.o)
// ld64.lld: error: undefined symbol: dlopen
// ld64.lld: error: undefined symbol: __error
//
// The three names were all this system supplied to a build that was linking
// against the whole of it.
//
// ⇒ The condition is not "which machine is this" as a preference. It is the
// fact the stub exists for: a substitute is needed exactly where the thing it
// substitutes for is absent, and on this system it is never absent. Where the
// real one is present it is a SUPERSET of ours, so a program above openkal
// links against it just as well and names the same library.
int main() {
// THE QUESTION IS WHETHER THE SYSTEM'S OWN STUB IS ON THE LINK, AND mcpp
// ANSWERS IT: `MCPP_TARGET_SDK` names the SDK the link carries with
// `-isysroot`, and is empty when the link names none (mcpp 2026.11.14.1+).
// Ours is supplied exactly when a target was requested and no SDK is on
// the link — a cross link to this system from another host.
//
// THE THREE ATTEMPTS BEFORE THIS ONE EACH ASKED A NEIGHBOURING QUESTION.
//
// Always: the stub shadowed the vendor's on this system (above).
// The host: `mcpp build --target aarch64-macos` ON a Mac then had no
// `libSystem` at all, because mcpp kept the SDK off such a link for one
// day (2026-08-24):
//
// ld64.lld: error: library not found for -lSystem
//
// A requested target (`MCPP_TARGET_REQUESTED`, which is empty on a native
// build, unlike `MCPP_TARGET`): right for that day's mcpp, and wrong from
// the next, which kept `-isysroot` on every link of this system's format on
// a Mac (2026.8.25.2). The stub was put ahead of the SDK's and shadowed it
// again, on a Mac with `--target` only — a case no build here exercised
// until mcpp's canary `cxx aarch64-macos test` (2026-11-14):
//
// ld64.lld: error: undefined symbol: strlen / memcpy / pthread_create
//
// Each was a proxy for the fact; the fact is the tool's to state.
//
// An mcpp too old to set `MCPP_TARGET_SDK` leaves it empty, and the
// condition is then the previous one: such a build behaves as it did.
const char* requested = std::getenv("MCPP_TARGET_REQUESTED");
const char* sdk = std::getenv("MCPP_TARGET_SDK");
if (requested && *requested && !(sdk && *sdk))
mcpp::link_search("port");
mcpp::rerun_if_changed("port/libSystem.tbd");
return 0;
}