Newer
Older
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
# `rules_patchelf`
> A Bazel ruleset for patching ELF binaries.
## Getting Started
Add the following to `MODULE.bazel`:
```py
bazel_dep(name="rules_patchelf", version="...")
```
Use `patchelf_unpack` to unpack the downloaded packages and patch the ELF interpreter path:
```py
patchelf_unpack(
name = "patched",
# `rules_distroless#apt` extension is *highly* recommended
srcs = ["@debian-bookworm-qemu//:packages"],
filters = [
"usr/share/doc/**", # No need to unpack documentation
"lib64/ld-linux-*.so.?", # Remove dangling symlink
],
)
```
Use `patchelf_launcher` to launch a binary from the unpacked directory:
```py
patchelf_launcher(
name = "qemu-system-x86_64",
srcs = [
":patched",
"@rules_patchelf//patchelf/launcher/elf/interpreter/debian",
"@rules_patchelf//patchelf/launcher/library/path/debian",
],
env = {
"TMPDIR": "./tmp",
},
)
```
Run the binary:
```console
$ bazelisk run -- :qemu-system-x86_64 --version
QEMU emulator version 7.2.13 (Debian 1:7.2+dfsg-7+deb12u7)
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
```
## Release Registry
The project publishes the relevant files to GitLab releases for use when a version has not been added to the upstream [BCR][bcr].
This is often the case for pre-release versions.
Add the following to `.bazelrc`:
```
# `bzlmod` pre-release registries
common --registry https://bcr.bazel.build
common --registry=https://gitlab.arm.com/bazel/rules_patchelf/-/releases/v1.0.0-alpha.1/downloads
```
Then a GitLab release version can be used in `bazel_dep`.
## Hermeticity
The project uses `rules_python`. Enable `--@rules_python//python/config_settings:bootstrap_impl=script` to enable hermetic Python execution.
The project uses `patchelf`. Enable a hermetic C/C++ toolchain to build the `patchelf` binary. `hermetic_cc_toolchain` is one option.
Otherwise, the module is entirely hermetic.
[bcr]: https://registry.bazel.build/