Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions libs/build-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "build-utils"
version = "0.1.0"
edition = "2021"

[dependencies]
23 changes: 23 additions & 0 deletions libs/build-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::process::Command;

/// Store the current git commit hash in the `GIT_HASH` variable in rustc env.
/// If the `GIT_HASH` environment variable is already set, this function does nothing.
pub fn store_git_commit_hash_in_env() {
if std::env::var("GIT_HASH").is_ok() {
return;
}

let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();

// Sanity check on the output.
if !output.status.success() {
panic!(
"Failed to get git commit hash.\nstderr: \n{}\nstdout {}\n",
String::from_utf8(output.stderr).unwrap_or_default(),
String::from_utf8(output.stdout).unwrap_or_default(),
);
}

let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}
3 changes: 3 additions & 0 deletions libs/test-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ tracing.workspace = true
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-error = "0.2"
async-trait.workspace = true

[build-dependencies]
build-utils.path = "../build-utils"
6 changes: 1 addition & 5 deletions libs/test-cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::process::Command;

fn main() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
build_utils::store_git_commit_hash_in_env();
}
11 changes: 11 additions & 0 deletions nix/publish-engine-size.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ let
craneLib = (flakeInputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
deps = craneLib.vendorCargoDeps { inherit src; };
libSuffix = stdenv.hostPlatform.extensions.sharedLibrary;
fakeGitHash = "0000000000000000000000000000000000000000";
in
{
packages.prisma-engines = stdenv.mkDerivation {
name = "prisma-engines";
inherit src;

GIT_HASH = "${fakeGitHash}";

buildInputs = [ pkgs.openssl.out ];
nativeBuildInputs = with pkgs; [
rustToolchain
Expand Down Expand Up @@ -68,6 +71,8 @@ in
inherit src;
inherit (self'.packages.prisma-engines) buildInputs nativeBuildInputs configurePhase dontStrip;

GIT_HASH = "${fakeGitHash}";

buildPhase = "cargo build --profile=${profile} --bin=test-cli";

installPhase = ''
Expand All @@ -85,6 +90,8 @@ in
inherit src;
inherit (self'.packages.prisma-engines) buildInputs nativeBuildInputs configurePhase dontStrip;

GIT_HASH = "${fakeGitHash}";

buildPhase = "cargo build --profile=${profile} --bin=query-engine";

installPhase = ''
Expand All @@ -105,6 +112,8 @@ in
inherit src;
inherit (self'.packages.prisma-engines) buildInputs nativeBuildInputs configurePhase dontStrip;

GIT_HASH = "${fakeGitHash}";

buildPhase = ''
cargo build --profile=${profile} --bin=query-engine
cargo build --profile=${profile} -p query-engine-node-api
Expand Down Expand Up @@ -134,6 +143,8 @@ in
inherit src;
buildInputs = with pkgs; [ iconv ];

GIT_HASH = "${fakeGitHash}";

buildPhase = ''
export HOME=$(mktemp -dt wasm-engine-home-XXXX)

Expand Down
3 changes: 3 additions & 0 deletions prisma-fmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ dissimilar = "1.0.3"
once_cell = "1.9.0"
expect-test = "1"

[build-dependencies]
build-utils.path = "../libs/build-utils"

[features]
# sigh please don't ask :(
vendored-openssl = []
10 changes: 1 addition & 9 deletions prisma-fmt/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}

fn main() {
store_git_commit_hash();
build_utils::store_git_commit_hash_in_env();
}
1 change: 1 addition & 0 deletions query-engine/query-engine-c-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ once_cell = "1.19.0"

[build-dependencies]
cbindgen = "0.24.0"
build-utils.path = "../../libs/build-utils"
11 changes: 1 addition & 10 deletions query-engine/query-engine-c-abi/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
extern crate cbindgen;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extern crate removal is unrelated, opportunistic cleanup


use std::env;
use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}

fn generate_c_headers() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand All @@ -28,6 +19,6 @@ fn main() {
// Tell Cargo that if the given file changes, to rerun this build script.
println!("cargo:rerun-if-changed=src/engine.rs");
// println!("✅ Running build.rs");
store_git_commit_hash();
build_utils::store_git_commit_hash_in_env();
generate_c_headers();
}
1 change: 1 addition & 0 deletions query-engine/query-engine-node-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ query-engine-metrics = { path = "../metrics" }

[build-dependencies]
napi-build = "1"
build-utils.path = "../../libs/build-utils"
22 changes: 1 addition & 21 deletions query-engine/query-engine-node-api/build.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
extern crate napi_build;

use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();

// Sanity check on the output.
if !output.status.success() {
panic!(
"Failed to get git commit hash.\nstderr: \n{}\nstdout {}\n",
String::from_utf8(output.stderr).unwrap_or_default(),
String::from_utf8(output.stdout).unwrap_or_default(),
);
}

let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}

fn main() {
store_git_commit_hash();
build_utils::store_git_commit_hash_in_env();
napi_build::setup()
}
3 changes: 3 additions & 0 deletions query-engine/query-engine-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ tracing-futures = "0.2"
tracing-opentelemetry = "0.17.3"
opentelemetry = { version = "0.17" }

[build-dependencies]
build-utils.path = "../../libs/build-utils"

[package.metadata.wasm-pack.profile.release]
wasm-opt = false # use wasm-opt explicitly in `./build.sh`

Expand Down
10 changes: 1 addition & 9 deletions query-engine/query-engine-wasm/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}

fn main() {
store_git_commit_hash();
build_utils::store_git_commit_hash_in_env();
}
3 changes: 3 additions & 0 deletions query-engine/query-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ user-facing-errors = { path = "../../libs/user-facing-errors" }
serial_test = "*"
quaint.workspace = true
indoc.workspace = true

[build-dependencies]
build-utils.path = "../../libs/build-utils"
20 changes: 1 addition & 19 deletions query-engine/query-engine/build.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();

// Sanity check on the output.
if !output.status.success() {
panic!(
"Failed to get git commit hash.\nstderr: \n{}\nstdout {}\n",
String::from_utf8(output.stderr).unwrap_or_default(),
String::from_utf8(output.stdout).unwrap_or_default(),
);
}

let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}

fn main() {
store_git_commit_hash();
build_utils::store_git_commit_hash_in_env();
}
3 changes: 3 additions & 0 deletions schema-engine/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ connection-string.workspace = true
expect-test = "1.4.0"
quaint = { workspace = true, features = ["all-native"] }

[build-dependencies]
build-utils.path = "../../libs/build-utils"

[[bin]]
name = "schema-engine"
path = "src/main.rs"
Expand Down
20 changes: 1 addition & 19 deletions schema-engine/cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();

// Sanity check on the output.
if !output.status.success() {
panic!(
"Failed to get git commit hash.\nstderr: \n{}\nstdout {}\n",
String::from_utf8(output.stderr).unwrap_or_default(),
String::from_utf8(output.stdout).unwrap_or_default(),
);
}

let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}

fn main() {
store_git_commit_hash();
build_utils::store_git_commit_hash_in_env();
}