Skip to content

Commit 6f6e343

Browse files
committed
Add binary info to root endpoint
1 parent 8be1329 commit 6f6e343

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ json-patch = "*"
131131
ariadne = { path = "../../packages/ariadne" }
132132

133133
clap = { version = "4.5", features = ["derive"] }
134+
iana-time-zone = "0.1.61"
134135

135136
[target.'cfg(not(target_env = "msvc"))'.dependencies]
136137
tikv-jemallocator = { version = "0.6.0", features = ["profiling", "unprefixed_malloc_on_supported_platforms"] }
@@ -139,3 +140,8 @@ jemalloc_pprof = { version = "0.7.0", features = ["flamegraph"] }
139140

140141
[dev-dependencies]
141142
actix-http = "3.4.0"
143+
144+
[build-dependencies]
145+
dotenv-build = "0.1.1"
146+
chrono = "0.4.38"
147+
iana-time-zone = "0.1.60"

apps/labrinth/build.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
use std::path::Path;
2+
use std::process::Command;
3+
4+
use chrono::Local;
5+
use dotenv_build::Config;
6+
17
fn main() {
8+
let output = Command::new("git")
9+
.arg("rev-parse")
10+
.arg("HEAD")
11+
.output()
12+
.expect("`git` invocation to succeed");
13+
14+
let git_hash = String::from_utf8(output.stdout)
15+
.expect("valid UTF-8 output from `git` invocation");
16+
17+
println!("cargo::rerun-if-changed=.git/HEAD");
18+
println!("cargo::rustc-env=GIT_HASH={}", git_hash.trim());
19+
20+
let timedate_fmt = Local::now().format("%F @ %I:%M %p");
21+
let timezone_fmt = iana_time_zone::get_timezone()
22+
.map(|tz| format!(" ({tz})"))
23+
.unwrap_or_default();
24+
25+
let comptime = timedate_fmt.to_string() + timezone_fmt.as_str();
26+
27+
println!("cargo::rustc-env=COMPILATION_DATE={comptime}");
28+
29+
// trick to get compilation profile
30+
let profile = std::env::var("OUT_DIR")
31+
.expect("OUT_DIR to be set")
32+
.split(std::path::MAIN_SEPARATOR)
33+
.nth_back(3)
34+
.unwrap_or("unknown")
35+
.to_string();
36+
37+
println!("cargo::rustc-env=COMPILATION_PROFILE={profile}");
38+
39+
dotenv_build::output(Config {
40+
filename: Path::new(".build.env"),
41+
recursive_search: true,
42+
fail_if_missing_dotenv: false,
43+
})
44+
.unwrap();
45+
246
println!("cargo:rerun-if-changed=migrations");
347
}

apps/labrinth/src/routes/index.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ pub async fn index_get() -> HttpResponse {
77
"name": "modrinth-labrinth",
88
"version": env!("CARGO_PKG_VERSION"),
99
"documentation": "https://docs.modrinth.com",
10-
"about": "Welcome traveler!"
10+
"about": "Welcome traveler!",
11+
12+
"build_info": {
13+
"comp_date": env!("COMPILATION_DATE"),
14+
"git_hash": env!("GIT_HASH", "unknown"),
15+
"profile": env!("COMPILATION_PROFILE"),
16+
}
1117
});
1218

1319
HttpResponse::Ok().json(data)

0 commit comments

Comments
 (0)