hermit-run 0.5.0

Hermit: a deterministic Linux execution engine for reproducible runs, record and replay, and concurrency-race search.
Documentation
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# @lint-ignore BUCKLINT missing-oncall-call-severe This file is unowned -

# DO NOT EDIT THIS FILE WITHOUT ADDING AN ONCALL - YOUR CHANGES

# WILL BE DELETED. UNLESS THERE IS AN ONCALL ADDED THIS FILE WILL BE

# DELETED WITHOUT NOTICE - DO NOT DEPEND ON IT.
load("@fbcode_macros//build_defs:native_rules.bzl", "buck_sh_test")
load("@fbsource//tools/build_defs:rust_binary.bzl", "rust_binary")
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")

oncall("hermit")

hermit_build_env = {
    "CARGO_PKG_VERSION": "0.5.0",
    "HERMIT_BUILD_DATE": "unknown",
    "HERMIT_BUILD_GIT_SHA": "unknown",
    "HERMIT_REVERIE_PIN": "ee9fbe258e39ca90983b840285f684e1bea1762c",
}

# The shadow release entrypoint supplies these values from Git/Cargo metadata
# using Buck config arguments (never shell-expanded source text). The supported
# entrypoint is `scripts/build-buck-release.rs`, which derives and validates all
# four values before selecting these shadow targets.
#
# Regular builds and CI (ci/buck-e2e, `validate --build buck-*`) instead pass
# -c hermit_release.unstamped=true: the same release feature set and linkage
# with the ordinary build identity (no commit hash, no build date), so a commit
# that changes no compiled source rebuilds nothing and stays cached. Without
# that flag the release targets still refuse to compile unstamped.
release_unstamped = read_root_config("hermit_release", "unstamped", "false") == "true"

# The release targets' cargo features, passed to both as their last argument,
# `**release_features`.
# A stamped build adds the buck-release-provenance cfg. Each case spells out its
# whole list because scripts/check-buck-reindeer-features.rs reads only literal
# `features` lists, never a variable or a concatenation.
release_features = {"features": [
    "dbt",
    "e9patch",
    "liteinst",
    "sabre",
]} if release_unstamped else {"features": [
    "buck-release-provenance",
    "dbt",
    "e9patch",
    "liteinst",
    "sabre",
]}
release_build_env = hermit_build_env if release_unstamped else {
    "CARGO_PKG_VERSION": read_root_config("hermit_release", "version", ""),
    "HERMIT_BUILD_DATE": read_root_config("hermit_release", "build_date", ""),
    "HERMIT_BUILD_GIT_SHA": read_root_config("hermit_release", "hermit_sha", ""),
    "HERMIT_REVERIE_PIN": read_root_config("hermit_release", "reverie_sha", ""),
}
release_lzma_target = read_root_config(
    "hermit_release",
    "lzma_target",
    "gh_facebook_buck2_shims_meta//third-party/xz:lzma",
)
release_unwind_target = read_root_config(
    "hermit_release",
    "unwind_target",
    "gh_facebook_buck2_shims_meta//third-party/libunwind:unwind-ptrace",
)

rust_library(
    name = "libhermit",
    autocargo = {
        "cargo_toml_dir": ".",
        "cargo_toml_config": {
            "package": {
                "name": "hermit-run",
                "version": "0.5.0",
                "license-file": "../LICENSE",
                "readme": "README.md",
                "homepage": "https://hermetic-infra.org",
                "documentation": "https://docs.rs/hermit-run",
                "keywords": [
                    "linux",
                    "hermit",
                    "determinism",
                    "debugging"
                ],
                "categories": [
                    "development-tools::debugging",
                    "development-tools::testing"
                ]
            },
            "dependencies_override": {
                "dependencies": {
                    "hermit-test-workdir": {"optional": True},
                    "reverie-inguest": {"default-features": False, "optional": True},
                    "sha2": {"optional": True},
                    "reverie-rpc-transport": {"optional": True},
                    "reverie-sabre-stats": {"optional": True},
                },
                "dev-dependencies": {
                    "reverie-inguest": {"default-features": False, "features": ["exec-stop"]},
                },
            },
            "features": {
                "exec-stop-launcher": ["dep:reverie-inguest", "reverie-inguest/exec-stop"],
                "default": [],
                "dbt": ["dep:detcore-dbt", "dep:reverie-dbt", "dep:hermit-test-workdir"],
                "sabre": ["dep:reverie-rpc-transport", "dep:reverie-sabre-stats"],
                "e9patch": [],
                "liteinst": ["dep:reverie-liteinst", "dep:reverie-rpc-transport"],
                "native-exec": ["liteinst", "detcore-model/native-exec", "reverie-liteinst/exec-native-injection", "dep:reverie-inguest", "dep:sha2"],
                "third-party-backends": ["dbt", "sabre", "e9patch", "liteinst"],
                "kvm-native-test-support": ["reverie-kvm/native-test-support"],
                "kvm-execution-tests": [],
            },
        },
    },
    srcs = glob(
        [
            "src/**/*.rs",
            "README.md",
        ],
        exclude = [
            "src/bin/**/*.rs",
        ],
    ),
    crate = "hermit",
    env = hermit_build_env,
    # LiteInst is an optional cargo feature so the published crate leaves out
    # reverie-liteinst; the internal build keeps the backend.
    features = ["liteinst"],
    # iced-x86 decoder tables are process-lifetime globals.
    test_env = {"LSAN_OPTIONS": "detect_leaks=0"},
    deps = [
        "fbsource//third-party/rust:addr2line",
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:bincode",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:dirs",
        "fbsource//third-party/rust:goblin",
        "fbsource//third-party/rust:iced-x86",
        "fbsource//third-party/rust:libc",
        "fbsource//third-party/rust:nix",
        "fbsource//third-party/rust:object",
        "fbsource//third-party/rust:rand_pcg",
        "fbsource//third-party/rust:serde",
        "fbsource//third-party/rust:serde_json",
        "fbsource//third-party/rust:sha2",
        "fbsource//third-party/rust:tempfile",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        "fbsource//third-party/rust:tracing-log",
        "fbsource//third-party/rust:tracing-subscriber",
        "fbsource//third-party/rust:uuid",
        "//hermetic_infra/hermit/detcore:detcore",
        "//hermetic_infra/hermit/detcore-model:detcore-model",
        "//hermetic_infra/hermit/hermit-record:hermit-record",
        "//hermetic_infra/hermit/hermit-record-format:hermit-record-format",
        "//hermetic_infra/hermit/hermit-replay:hermit-replay",
        "//hermetic_infra/hermit/hermit-run-kvm:hermit-run-kvm",
        "//hermetic_infra/hermit/hermit-run-ptrace:hermit-run-ptrace",
        "//hermetic_infra/hermit/hermit-resources:hermit-resources",
        "//hermetic_infra/reverie:reverie",
        "//hermetic_infra/reverie:reverie-inguest",
        "//hermetic_infra/reverie:reverie-kvm",
        "//hermetic_infra/reverie:reverie-liteinst",
        "//hermetic_infra/reverie:reverie-ptrace",
        "//hermetic_infra/reverie:reverie-rpc-transport",
        "//hermetic_infra/reverie:reverie-sabre-stats",
        "//hermetic_infra/reverie:safeptrace",
    ],
)

rust_binary(
    name = "hermit",
    autocargo = {
        "cargo_toml_dir": ".",
        "cargo_toml_config": {
            "package": {
                "name": "hermit-run",
                "version": "0.5.0",
                "license-file": "../LICENSE",
                "readme": "README.md",
                "homepage": "https://hermetic-infra.org",
                "documentation": "https://docs.rs/hermit-run",
                "keywords": [
                    "linux",
                    "hermit",
                    "determinism",
                    "debugging"
                ],
                "categories": [
                    "development-tools::debugging",
                    "development-tools::testing"
                ]
            },
            "dependencies_override": {
                "dependencies": {
                    "hermit-test-workdir": {"optional": True},
                    "reverie-inguest": {"default-features": False, "optional": True},
                    "sha2": {"optional": True},
                    "reverie-rpc-transport": {"optional": True},
                    "reverie-sabre-stats": {"optional": True},
                },
                "dev-dependencies": {
                    "reverie-inguest": {"default-features": False, "features": ["exec-stop"]},
                },
            },
            "features": {
                "exec-stop-launcher": ["dep:reverie-inguest", "reverie-inguest/exec-stop"],
                "default": [],
                "dbt": ["dep:detcore-dbt", "dep:reverie-dbt", "dep:hermit-test-workdir"],
                "sabre": ["dep:reverie-rpc-transport", "dep:reverie-sabre-stats"],
                "e9patch": [],
                "liteinst": ["dep:reverie-liteinst", "dep:reverie-rpc-transport"],
                "native-exec": ["liteinst", "detcore-model/native-exec", "reverie-liteinst/exec-native-injection", "dep:reverie-inguest", "dep:sha2"],
                "third-party-backends": ["dbt", "sabre", "e9patch", "liteinst"],
                "kvm-native-test-support": ["reverie-kvm/native-test-support"],
                "kvm-execution-tests": [],
            },
        },
    },
    srcs = glob(["src/bin/**/*.rs"]),
    env = hermit_build_env,
    # Signal-handler messages intentionally live for the process lifetime.
    test_env = {"LSAN_OPTIONS": "detect_leaks=0"},
    test_srcs = glob([
        "src/bin/**/*.rs",
        "test-resources/**/*.json",
        "tests/common/readonly_proc.rs",
        "tests/fixtures/staged-summary.gitignore",
    ]),
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:bincode",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:colored",
        "fbsource//third-party/rust:diff",
        "fbsource//third-party/rust:dirs",
        "fbsource//third-party/rust:libc",
        "fbsource//third-party/rust:nix",
        "fbsource//third-party/rust:num_cpus",
        "fbsource//third-party/rust:pretty_assertions",
        "fbsource//third-party/rust:rand",
        "fbsource//third-party/rust:rand_pcg",
        "fbsource//third-party/rust:regex",
        "fbsource//third-party/rust:serde",
        "fbsource//third-party/rust:serde_json",
        "fbsource//third-party/rust:sha2",
        "fbsource//third-party/rust:serde_yaml",
        "fbsource//third-party/rust:shell-words",
        "fbsource//third-party/rust:tempfile",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        "fbsource//third-party/rust:tracing-appender",
        "fbsource//third-party/rust:tracing-subscriber",
        "fbsource//third-party/rust:uuid",
        ":libhermit",
        "//common/rust/build_info:build_info",
        "//common/rust/shed/fbinit:fbinit",
        "//hermetic_infra/hermit/common/test-workdir:hermit-test-workdir",
        "//hermetic_infra/hermit/detcore:detcore",
        "//hermetic_infra/hermit/detcore-model:detcore-model",
        "//hermetic_infra/reverie:reverie",
        "//hermetic_infra/reverie:reverie-inguest",
        "//hermetic_infra/reverie:reverie-ptrace",
    ],
)

rust_library(
    name = "_libhermit-release",
    srcs = glob(
        [
            "src/**/*.rs",
            "README.md",
        ],
        exclude = [
            "src/bin/**/*.rs",
        ],
    ),
    crate = "hermit",
    env = release_build_env,
    preferred_linkage = "static",
    deps = [
        "fbsource//third-party/rust:addr2line",
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:bincode",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:dirs",
        "fbsource//third-party/rust:goblin",
        "fbsource//third-party/rust:iced-x86",
        "fbsource//third-party/rust:libc",
        "fbsource//third-party/rust:nix",
        "fbsource//third-party/rust:object",
        "fbsource//third-party/rust:rand_pcg",
        "fbsource//third-party/rust:reverie-dbt",
        "fbsource//third-party/rust:serde",
        "fbsource//third-party/rust:serde_json",
        "fbsource//third-party/rust:tempfile",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        "fbsource//third-party/rust:tracing-log",
        "fbsource//third-party/rust:tracing-subscriber",
        "fbsource//third-party/rust:uuid",
        "//hermetic_infra/hermit/detcore:detcore",
        "//hermetic_infra/hermit/detcore-dbt:detcore-dbt",
        "//hermetic_infra/hermit/detcore-model:detcore-model",
        "//hermetic_infra/hermit/hermit-record:hermit-record",
        "//hermetic_infra/hermit/hermit-record-format:hermit-record-format",
        "//hermetic_infra/hermit/hermit-replay:hermit-replay",
        "//hermetic_infra/hermit/hermit-run-kvm:hermit-run-kvm",
        "//hermetic_infra/hermit/hermit-run-ptrace:hermit-run-ptrace",
        "//hermetic_infra/hermit/hermit-resources:hermit-resources",
        "//hermetic_infra/reverie:reverie",
        "//hermetic_infra/reverie:reverie-kvm",
        "//hermetic_infra/reverie:reverie-liteinst",
        "//hermetic_infra/reverie:reverie-ptrace",
        "//hermetic_infra/reverie:reverie-rpc-transport",
        "//hermetic_infra/reverie:reverie-sabre-stats",
        "//hermetic_infra/reverie:safeptrace",
    ],
    **release_features
)

rust_binary(
    name = "_hermit-release",
    srcs = glob(["src/bin/**/*.rs"]),
    crate = "hermit",
    env = release_build_env,
    link_style = "static_pic",
    rustc_flags = [
        "-C",
        "link-arg=-Wl,--disable-new-dtags",
        "-C",
        "link-arg=-Wl,-rpath,$ORIGIN/../install_pkg/rsrcs/hermit-runtime:$ORIGIN/install/rsrcs/hermit-runtime",
    ],
    # The guarded local producer overrides this with its content-bound prebuilt
    # target. CI resolves the default declared pkg-config dependency.
    deps = [release_lzma_target, release_unwind_target] + [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:bincode",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:colored",
        "fbsource//third-party/rust:diff",
        "fbsource//third-party/rust:dirs",
        "fbsource//third-party/rust:libc",
        "fbsource//third-party/rust:nix",
        "fbsource//third-party/rust:num_cpus",
        "fbsource//third-party/rust:pretty_assertions",
        "fbsource//third-party/rust:rand",
        "fbsource//third-party/rust:rand_pcg",
        "fbsource//third-party/rust:regex",
        "fbsource//third-party/rust:reverie-dbt",
        "fbsource//third-party/rust:serde",
        "fbsource//third-party/rust:serde_json",
        "fbsource//third-party/rust:serde_yaml",
        "fbsource//third-party/rust:shell-words",
        "fbsource//third-party/rust:tempfile",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        "fbsource//third-party/rust:tracing-appender",
        "fbsource//third-party/rust:tracing-subscriber",
        "fbsource//third-party/rust:uuid",
        ":_libhermit-release",
        "//common/rust/build_info:build_info",
        "//common/rust/shed/fbinit:fbinit",
        "//hermetic_infra/hermit/common/test-workdir:hermit-test-workdir",
        "//hermetic_infra/hermit/detcore:detcore",
        "//hermetic_infra/hermit/detcore-dbt:detcore-dbt",
        "//hermetic_infra/hermit/detcore-model:detcore-model",
        "//hermetic_infra/reverie:reverie",
        "//hermetic_infra/reverie:reverie-ptrace",
    ],
    **release_features
)

configured_alias(
    name = "libhermit-release",
    actual = ":_libhermit-release",
    platform = "shim//:hermit_rust_release_platform",
    visibility = ["PUBLIC"],
)

configured_alias(
    name = "hermit-release",
    actual = ":_hermit-release",
    platform = "shim//:hermit_rust_release_platform",
    visibility = ["PUBLIC"],
)

buck_sh_test(
    name = "test_record_uptime",
    args = [
        "record",
        "start",
        "--verify",
        "--",
        "cat",
        "/proc/uptime",
    ],
    test = ":hermit",
)

buck_sh_test(
    name = "test_record_dev_urandom",
    args = [
        "record",
        "start",
        "--verify",
        "--",
        "hexdump",
        "-C",
        "-n",
        "32",
        "/dev/urandom",
    ],
    test = ":hermit",
)

buck_sh_test(
    name = "test_record_with_gdb_smoke",
    args = [
        "record",
        "start",
        "--verify-with-gdbex='b main; c; c'",
        "--",
        "hexdump",
        "-C",
        "-n",
        "32",
        "/dev/urandom",
    ],
    test = ":hermit",
)