Repository navigation
Expand file tree
/
Copy pathbuild.mcpp
More file actions
63 lines (61 loc) · 3.59 KB
/
Copy pathbuild.mcpp
File metadata and controls
63 lines (61 loc) · 3.59 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
// The plugin of openkal-platform (mcpp SPEC-013 §12): it provides the `okb`
// package format. `mcpp pack --pkg-format okb` stages the universal package,
// and this program's action makes it one okb (openkal-image docs/okb.md) with
// `okld bundle --package`, which reads the package's mcpp-package.json
// (mcpp SPEC-014 §4.5): the images of each architecture and the entry. The
// okb is written beside the staged tree, in the project's `target/dist/`.
//
// ITS IMAGES STORED, OR COMPRESSED (0.23.0): stored by default, an okb whose
// images are mapped where they lie; `--compress gzip` (or `[pack] compress =
// "gzip"`, which mcpp 2026.11.3.1 and later state as MCPP_PACK_COMPRESS) stores
// them compressed, an okb kept small on disk that a runner expands into its
// cache when it first runs it --- the economy form (mcpp design 2026-11-03
// part 4 §16). `zstd' and `xz' are a tar's, and refused.
import mcpp;
import mcpp.plugins; // the package reader
import mcpp.plugins.platform; // provide_format
import std;
namespace pf = mcpp::plugins::platform;
int main() {
if (std::string_view(mcpp::target()).ends_with("-openkal")) {
// Keep source relocations without making debug support depend on a
// profile's name. Prune ordinary static link relocations before the
// image's notes/placement are written; those appended bytes must not
// pass through objcopy afterwards.
// The API path is UTF-8, including on Windows. Preserve those bytes
// for the command and convert explicitly only for filesystem queries.
auto objcopy = std::format("{}/bin/llvm-objcopy", mcpp::toolchain_dir());
if (!std::filesystem::is_regular_file(std::filesystem::u8path(objcopy))) objcopy += ".exe";
if (!std::filesystem::is_regular_file(std::filesystem::u8path(objcopy))) {
std::println(std::cerr, "openkal-platform: the selected LLVM toolchain has no llvm-objcopy");
return 1;
}
mcpp::seal(0, objcopy.c_str());
for (const char* word : {"--remove-section=.rela.*", "--remove-section=!.rela.debug_*",
"--remove-section=!.rela.dyn", "--remove-section=!.rela.plt", "{}"})
mcpp::seal(0, word);
for (const char* word : {"okld", "note", "{}"}) mcpp::seal(1, word);
for (const char* word : {"okld", "place", "{}"}) mcpp::seal(2, word);
for (const char* word : {"okld", "check", "{}", "--with", "{needed}"}) mcpp::seal(3, word);
}
const char* stated_compress = std::getenv("MCPP_PACK_COMPRESS");
const std::string compress = stated_compress ? stated_compress : "";
if (!compress.empty() && !compress.starts_with("gzip") && !compress.starts_with("none")) {
std::println(std::cerr, "openkal-platform: an okb stores its images compressed with DEFLATE (--compress gzip) "
"or as they are (--compress none); --compress {} is a tar's", compress);
return 1;
}
const auto stated = pf::provide_format("okb",
[&](const mcpp::plugins::package::info& p, mcpp::action& a) {
const auto out = std::format("{}/{}-{}.okb",
std::filesystem::path(p.root).parent_path().generic_string(), p.name, p.version);
a.arg(mcpp::dep_bin("openkal-tools", "okld"))
.arg("bundle").arg(out.c_str())
.arg("--package").arg("${mcpp.stage_dir}");
if (compress.starts_with("gzip")) a.arg("--compress");
a.input((p.root + "/mcpp-package.json").c_str())
.output(out.c_str());
return true;
});
return stated ? 0 : 1;
}