Get the Nix build working. (#335)

V3_GIT_ORIGIN_REV_ID: e70e2a42b2445b4bcf4e9ee7db771b475c32d2f9
This commit is contained in:
Samir Talwar 2024-03-06 18:50:32 +01:00 committed by hasura-bot
parent dea588255b
commit 078b0d3487
4 changed files with 61 additions and 24 deletions

View File

@ -1,3 +1,7 @@
use std::fmt::Display;
use std::path::PathBuf;
use std::sync::Arc;
use axum::{ use axum::{
body::HttpBody, body::HttpBody,
extract::State, extract::State,
@ -8,23 +12,22 @@ use axum::{
Extension, Json, Router, Extension, Json, Router,
}; };
use clap::Parser; use clap::Parser;
use ::engine::authentication::{AuthConfig, AuthConfig::V1 as V1AuthConfig, AuthModeConfig};
use engine::{schema::GDS, VERSION};
use hasura_authn_core::Session;
use hasura_authn_jwt::auth as jwt_auth;
use hasura_authn_jwt::jwt;
use hasura_authn_webhook::webhook;
use lang_graphql as gql;
use std::path::PathBuf;
use std::{fmt::Display, sync::Arc};
use tower_http::trace::TraceLayer; use tower_http::trace::TraceLayer;
use tracing_util::{ use tracing_util::{
add_event_on_active_span, set_status_on_current_span, AttributeVisibility, ErrorVisibility, add_event_on_active_span, set_status_on_current_span, AttributeVisibility, ErrorVisibility,
SpanVisibility, TraceableError, TraceableHttpResponse, SpanVisibility, TraceableError, TraceableHttpResponse,
}; };
use engine::authentication::{AuthConfig, AuthConfig::V1 as V1AuthConfig, AuthModeConfig};
use engine::{schema::GDS, VERSION};
use hasura_authn_core::Session;
use hasura_authn_jwt::auth as jwt_auth;
use hasura_authn_jwt::jwt;
use hasura_authn_webhook::webhook;
use lang_graphql as gql;
#[derive(Parser)] #[derive(Parser)]
#[command(version = VERSION)]
struct ServerOptions { struct ServerOptions {
#[arg(long, value_name = "METADATA_FILE", env = "METADATA_PATH")] #[arg(long, value_name = "METADATA_FILE", env = "METADATA_PATH")]
metadata_path: PathBuf, metadata_path: PathBuf,

View File

@ -1,12 +1,27 @@
fn main() { fn main() -> Result<(), String> {
// Cargo sets the PROFILE environment variable // Ensure that we rebuild if the version is specified.
let profile = std::env::var("PROFILE").unwrap(); println!("cargo:rerun-if-env-changed=RELEASE_VERSION");
if profile == "release" {
// For release builds (cargo build --release ...), set the version to the git commit short // On release builds, use the Git commit as a backup if the version is not set.
let commit_short = build_data::get_git_commit_short().unwrap(); // On debug builds, use "dev".
println!("cargo:rustc-env=CARGO_V3_ENGINE_VERSION={}", commit_short); // If we fail to get the Git information, fail.
let build_profile = std::env::var("PROFILE").map_err(|err| err.to_string())?;
let release_version = if build_profile == "release" {
match option_env!("RELEASE_VERSION") {
Some(version) => version.to_string(),
None => {
let git_commit_ref = build_data::get_git_commit_short()?;
let git_dirty = build_data::get_git_dirty().unwrap_or(false);
if git_dirty {
format!("{git_commit_ref}-dirty")
} else {
git_commit_ref
}
}
}
} else { } else {
// For non-release builds, set the version to 'dev' "dev".to_string()
println!("cargo:rustc-env=CARGO_V3_ENGINE_VERSION=dev"); };
} println!("cargo:rustc-env=CARGO_V3_ENGINE_VERSION={release_version}");
Ok(())
} }

View File

@ -33,9 +33,24 @@
in in
{ {
formatter = pkgs.nixpkgs-fmt; formatter = pkgs.nixpkgs-fmt;
packages = { packages = {
# a binary for whichever is the local computer # a binary for whichever is the local computer
default = rust.callPackage ./nix/app.nix { }; default = rust.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
};
};
apps = {
default = self.apps.${localSystem}.engine;
engine = flake-utils.lib.mkApp {
drv = self.packages.${localSystem}.default;
name = "engine";
};
agent = flake-utils.lib.mkApp {
drv = self.packages.${localSystem}.default;
name = "engine";
};
}; };
devShells = { devShells = {

View File

@ -1,6 +1,7 @@
# This is a function that returns a derivation for the compiled Rust project. # This is a function that returns a derivation for the compiled Rust project.
{ craneLib { craneLib
, lib , lib
, version
, stdenv , stdenv
, openssl , openssl
, libiconv , libiconv
@ -14,11 +15,13 @@ let
src = src =
let let
isJsonFile = path: _type: builtins.match ".*json" path != null;
isGraphqlFile = path: _type: builtins.match ".*graphql" path != null; isGraphqlFile = path: _type: builtins.match ".*graphql" path != null;
isHtmlFile = path: _type: builtins.match ".*html" path != null;
isJsonFile = path: _type: builtins.match ".*json" path != null;
isSourceFile = path: type: isSourceFile = path: type:
isJsonFile path type isGraphqlFile path type
|| isGraphqlFile path type || isHtmlFile path type
|| isJsonFile path type
|| craneLib.filterCargoSources path type; || craneLib.filterCargoSources path type;
in in
lib.cleanSourceWith { src = craneLib.path ./..; filter = isSourceFile; }; lib.cleanSourceWith { src = craneLib.path ./..; filter = isSourceFile; };
@ -45,4 +48,5 @@ craneLib.buildPackage
(buildArgs // { (buildArgs // {
inherit cargoArtifacts; inherit cargoArtifacts;
doCheck = false; doCheck = false;
RELEASE_VERSION = version;
}) })