Skip to content

Commit

Permalink
Fix rust release build detection, build rs change detect, move types …
Browse files Browse the repository at this point in the history
…out of source
  • Loading branch information
prasannavl committed Apr 25, 2023
1 parent e710277 commit 0881461
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 1,287 deletions.
1 change: 0 additions & 1 deletion lib/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[build]

target-dir = "../build/artifacts"
rustflags = [
"-C", "link-arg=-z",
Expand Down
2 changes: 2 additions & 0 deletions lib/Cargo.lock

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

6 changes: 5 additions & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
CARGO ?= cargo

# RUST_TARGET is set from configure
TARGET ?= $(RUST_TARGET)
TARGET ?= x86_64-unknown-linux-gnu

# This is set from configure
RUST_DEBUG ?=
DEBUG ?= $(RUST_DEBUG)
# We use DEBUG as well, since that's the more conventional
# setup. Either of them set will result in debug builds
DEBUG ?= $(RUST_DEBUG)

TARGET_DIR ?= $(abs_builddir)/target
SPECIFIC_TARGET_DIR = $(TARGET_DIR)/$(TARGET)/$(if $(DEBUG),debug,release)
Expand Down
1 change: 1 addition & 0 deletions lib/ain-cpp-imports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ edition = "2021"
cxx = "1.0"

[build-dependencies]
anyhow = "1.0.70"
cxx-build = "1.0"
21 changes: 12 additions & 9 deletions lib/ain-cpp-imports/build.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
use anyhow::{format_err, Result};
use std::env;
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
fn main() -> Result<()> {
let pkg_name = env::var("CARGO_PKG_NAME")?;
let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);

let cpp_src_path = &manifest_path
.parent()
.and_then(|x| x.parent())
.map(|x| x.join("src"));

let cpp_src_path = match cpp_src_path.as_ref() {
Some(r) => Ok(r),
None => Err("path err"),
}?;
.map(|x| x.join("src"))
.ok_or(format_err!("path err"))?;

let ffi_rs_src_path = &manifest_path.join("src/bridge.rs");
let ffi_exports_h_path = &cpp_src_path.join("ffi/ffiexports.h");

cxx_build::bridge(ffi_rs_src_path)
.include(cpp_src_path)
.cpp_link_stdlib("stdc++")
.flag_if_supported("-std=c++17")
.flag_if_supported("-Wno-unused-parameter")
.flag("-std=c++17")
.flag("-Wno-unused-parameter")
.static_flag(true)
.compile(pkg_name.as_str());

println!(
Expand All @@ -33,6 +31,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"cargo:rerun-if-changed={}",
&ffi_exports_h_path.to_string_lossy()
);
// Using a direct path for now
let git_head_path = manifest_path.join("../../.git/HEAD");
if git_head_path.exists() {
println!("cargo:rerun-if-changed={}", git_head_path.to_string_lossy());
}

Ok(())
}
1 change: 1 addition & 0 deletions lib/ain-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ syn = { version = "2.0", default-features = false, features = ["parsing", "print
prost-build = "0.11"
tonic-build = "0.8"
prettyplease = "0.2.4"
anyhow = "1.0.70"
27 changes: 20 additions & 7 deletions lib/ain-grpc/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::{format_err, Result};
use proc_macro2::{Span, TokenStream};
use prost_build::{Config, Service, ServiceGenerator};
use quote::{quote, ToTokens};
Expand Down Expand Up @@ -369,18 +370,30 @@ fn get_path_bracketed_ty_simple(ty: &Type) -> Type {
}
}

fn main() {
let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let proto_path = manifest_path.parent().unwrap().join("proto");
fn main() -> Result<()> {
let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
let proto_path = manifest_path
.parent()
.ok_or(format_err!("path err: no parent"))?
.join("proto");

let src_path = manifest_path.join("src");
let gen_path = src_path.join("gen");
std::fs::create_dir_all(&gen_path).unwrap();
let out_dir: PathBuf = PathBuf::from(env::var("OUT_DIR")?);
let proto_rs_target_path = out_dir.join("proto");
std::fs::create_dir_all(&proto_rs_target_path)?;

let methods = generate_from_protobuf(&proto_path, Path::new(&gen_path));
modify_codegen(methods, &Path::new(&gen_path).join("types.rs"));
let methods = generate_from_protobuf(&proto_path, Path::new(&proto_rs_target_path));
modify_codegen(methods, &Path::new(&proto_rs_target_path).join("types.rs"));

println!(
"cargo:rerun-if-changed={}",
src_path.join("rpc.rs").to_string_lossy()
);
// Using a direct path for now
let git_head_path = manifest_path.join("../../.git/HEAD");
if git_head_path.exists() {
println!("cargo:rerun-if-changed={}", git_head_path.to_string_lossy());
}

Ok(())
}
2 changes: 1 addition & 1 deletion lib/ain-grpc/src/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};

pub mod types {
include!("gen/types.rs");
include!(concat!(env!("OUT_DIR"), "/proto/types.rs"));
}

impl Serialize for types::BlockResult {
Expand Down
Loading

0 comments on commit 0881461

Please sign in to comment.