Skip to content

Commit

Permalink
build: Update env vars for build process
Browse files Browse the repository at this point in the history
Use the standard `SOURCE_DATE_EPOCH` instead of `GIT_COMMIT_TIME`.
Set `GIT_HEAD` properly.
  • Loading branch information
cloudhead committed Jun 20, 2024
1 parent 6598e77 commit 589c375
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"pre-release".to_owned()
};

// Set a build-time `GIT_COMMIT_TIME` env var which includes the commit time.
let commit_time = env::var("GIT_COMMIT_TIME").unwrap_or_else(|_| {
// Set a build-time `SOURCE_DATE_EPOCH` env var which includes the commit time.
let commit_time = env::var("SOURCE_DATE_EPOCH").unwrap_or_else(|_| {
Command::new("git")
.arg("log")
.arg("-1")
Expand All @@ -47,7 +47,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});

println!("cargo::rustc-env=RADICLE_VERSION={version}");
println!("cargo::rustc-env=GIT_COMMIT_TIME={commit_time}");
println!("cargo::rustc-env=SOURCE_DATE_EPOCH={commit_time}");
println!("cargo::rustc-env=GIT_HEAD={hash}");

Ok(())
Expand Down
1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ARG TZ
ARG LC_ALL
ARG SOURCE_DATE_EPOCH
ARG RADICLE_VERSION
ARG GIT_HEAD

# Copy cargo configuration we're going to use to specify compiler options.
RUN mkdir -p .cargo && cp build/config.toml .cargo/config.toml
Expand Down
1 change: 1 addition & 0 deletions build/build
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ main() {
--build-arg TZ \
--build-arg LC_ALL \
--build-arg RADICLE_VERSION=$version \
--build-arg GIT_HEAD=$rev \
--arch amd64 --tag $image -f ./build/Dockerfile - < $gitarchive

echo "Creating container (radicle-build-container).."
Expand Down
2 changes: 1 addition & 1 deletion radicle-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const RADICLE_VERSION: &str = env!("RADICLE_VERSION");
pub const DESCRIPTION: &str = "Radicle command line interface";
pub const GIT_HEAD: &str = env!("GIT_HEAD");
pub const TIMESTAMP: &str = env!("GIT_COMMIT_TIME");
pub const TIMESTAMP: &str = env!("SOURCE_DATE_EPOCH");
pub const VERSION: Version = Version {
name: NAME,
version: RADICLE_VERSION,
Expand Down
2 changes: 1 addition & 1 deletion radicle-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub const VERSION: Version = Version {
name: env!("CARGO_PKG_NAME"),
commit: env!("GIT_HEAD"),
version: env!("RADICLE_VERSION"),
timestamp: env!("GIT_COMMIT_TIME"),
timestamp: env!("SOURCE_DATE_EPOCH"),
};

pub mod prelude {
Expand Down
2 changes: 1 addition & 1 deletion radicle-remote-helper/src/git-remote-rad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const VERSION: Version = Version {
name: "git-remote-rad",
commit: env!("GIT_HEAD"),
version: env!("RADICLE_VERSION"),
timestamp: env!("GIT_COMMIT_TIME"),
timestamp: env!("SOURCE_DATE_EPOCH"),
};

fn main() {
Expand Down

0 comments on commit 589c375

Please sign in to comment.