-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
90 lines (72 loc) · 2.4 KB
/
build.rs
File metadata and controls
90 lines (72 loc) · 2.4 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
//! Build script for tach-core
//!
//! Enforces Docker container development environment at compile time.
//! WSL2 causes kernel instability with userfaultfd and jemalloc.
use std::fs;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-env-changed=TACH_ALLOW_NATIVE_BUILD");
println!("cargo:rerun-if-changed=.git/HEAD");
if let Ok(output) = std::process::Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
&& output.status.success()
{
let hash = String::from_utf8_lossy(&output.stdout);
println!("cargo:rustc-env=GIT_HASH={}", hash.trim());
}
// Check if we're allowing native builds (escape hatch for CI)
if std::env::var("TACH_ALLOW_NATIVE_BUILD").is_ok() {
println!("cargo:warning=Native build allowed via TACH_ALLOW_NATIVE_BUILD");
return;
}
// Check if we're in a Docker container
if is_docker_environment() {
return; // All good
}
// Check if we're in WSL2
if is_wsl2() {
panic!(
r#"
========================================
ERROR: WSL2 BUILDS ARE NOT ALLOWED
========================================
WSL2 causes kernel instability with userfaultfd and jemalloc.
You MUST build inside the Docker container.
RECOMMENDED - Use Docker:
docker compose up -d
docker compose exec dev bash
BYPASS (NOT RECOMMENDED):
TACH_ALLOW_NATIVE_BUILD=1 cargo build --release
WARNING: Bypassing may cause kernel crashes, permission errors, and flaky tests.
"#
);
}
// Native Linux - warn but allow (CI systems, etc.)
println!(
"cargo:warning=Building outside Docker container. Use 'docker compose exec dev bash' for full feature support."
);
}
fn is_docker_environment() -> bool {
// Method 1: Check for /.dockerenv file
if Path::new("/.dockerenv").exists() {
return true;
}
// Method 2: Check cgroup for docker/container references
if let Ok(cgroup) = fs::read_to_string("/proc/1/cgroup")
&& (cgroup.contains("docker") || cgroup.contains("containerd") || cgroup.contains("lxc"))
{
return true;
}
// Method 3: Check for container environment variable
if std::env::var("container").is_ok() {
return true;
}
false
}
fn is_wsl2() -> bool {
if let Ok(version) = fs::read_to_string("/proc/version") {
return version.to_lowercase().contains("microsoft");
}
false
}