-
Notifications
You must be signed in to change notification settings - Fork 455
-
Hi
Here is my Cross.toml
[target.x86_64-pc-windows-gnu]
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt update",
# tls
"apt install --assume-yes nasm",
# protobuf
"apt install --assume-yes protobuf-compiler:$CROSS_DEB_ARCH",
"apt install --assume-yes openssl",
"apt install --assume-yes git",
]
I'm trying
let hash = Command::new("git").args(&["rev-parse", "HEAD"]).output()?;
let git_hash = String::from_utf8(hash.stdout)?;
p!("BUILD.rs -> git hash ...{}", git_hash);
It emits empty string.
I also tried vergen_git2 and apt install --assume-yes libgit2, but result is pretty the same - it cant find repo, or so.
Beta Was this translation helpful? Give feedback.
All reactions
Looks like a found a problem.
stderr was fatal: not a git repository (or any parent up to mount point /home/sc/t/bur)
real problem was what my repo is not equal to workspace root.
I have something like
git_repo
.git
my_rust_project
when I run cross build, my pwd is git_repo/my_rust_project, so I have mounted only my_rust_project, and ./../.git is not accessible.
Is there any way to set mount point as ./../, or should I reorganize my repository?
Replies: 2 comments 5 replies
-
Im guessing theres some output in stderr? This is probably a file ownership problem. If it is, see #1473 (reply in thread)
Beta Was this translation helpful? Give feedback.
All reactions
-
Looks like a found a problem.
stderr was fatal: not a git repository (or any parent up to mount point /home/sc/t/bur)
real problem was what my repo is not equal to workspace root.
I have something like
git_repo
.git
my_rust_project
when I run cross build, my pwd is git_repo/my_rust_project, so I have mounted only my_rust_project, and ./../.git is not accessible.
Is there any way to set mount point as ./../, or should I reorganize my repository?
Beta Was this translation helpful? Give feedback.
All reactions
-
looks like I found an answer #1294
But i cant get how lets say FTL_DIR can help me
Beta Was this translation helpful? Give feedback.
All reactions
-
got it
it'll be mounted in the container at the same path as on the host.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @enomado could you share your [build.env] section of Cross.toml? I'm running into the same issue :)
Beta Was this translation helpful? Give feedback.
All reactions
-
@merklefruit its still experimental, but last time worked
[build.env]
# i'm in /home/sc/t/bur/rust_app
volumes = [
# "A_DIRECTORY=/home/sc/t/bur",
"A_DIRECTORY=./../",
]
[target.x86_64-pc-windows-gnu]
# image = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:0.2.4"
# build-std = ["core", "alloc"]
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt update",
# for tls
"apt install --assume-yes nasm",
# for protobuf
"apt install --assume-yes protobuf-compiler:$CROSS_DEB_ARCH",
"apt install --assume-yes openssl",
"apt install --assume-yes git",
# some of them need gfor git yo work
"git config --system --add safe.directory '*'",
"git config --system --add safe.directory './../*'",
"git config --system --add safe.directory './../../*'",
"git config --system --add safe.directory './../../../*'",
"git config --system --add safe.directory './../../../../*'",
"git config --system --add safe.directory './../../../../../*'",
]
build.rs
#![allow(dead_code)]
use std::{env, fs, path::PathBuf, process::Command, str::FromStr};
use vergen_git2::{Emitter, Git2Builder};
// use vergen::Emitter;
extern crate winresource;
// use vergen::*;
fn main() {
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
let mut res = winresource::WindowsResource::new();
res.set_icon("./assets/app_icon.ico");
res.compile().unwrap();
}
// vergen(SHORT_SHA | COMMIT_DATE).unwrap();
// works in cross https://github.com/cross-rs/cross/discussions/1473#discussioncomment-9128550
gen_version_wrap();
// get_version_dirty_way_wrap()
}
macro_rules! p {
($($tokens: tt)*) => {
println!("cargo:warning={}", format!($($tokens)*))
}
}
fn get_version_dirty_way_wrap() {
match get_version_dirty_way() {
Ok(_s) => {}
Err(_x) => {}
}
}
fn get_version_dirty_way() -> anyhow::Result<String> {
let hash = Command::new("git").args(&["rev-parse", "HEAD"]).output()?;
let git_hash = String::from_utf8(hash.stdout)?;
let git_hash_err = String::from_utf8(hash.stderr)?;
let pp = PathBuf::from_str("./../../../")?;
let paths = fs::read_dir(pp).unwrap();
for path in paths {
let ppp = path.unwrap();
p!("paths, {}", &ppp.path().display());
}
let path = PathBuf::from_str("./../../../.git/refs/heads/master")?;
let contents = fs::read_to_string(path).unwrap();
p!("BUILD.rs -> git hash2 {}", contents);
p!(
"BUILD.rs -> git hash {}, {}, {}...",
git_hash,
git_hash_err,
contents
);
Ok(git_hash)
}
fn gen_version_wrap() {
match gen_version() {
Ok(_x) => {}
Err(x) => {
println!("failed to get git version. {x}")
}
}
}
fn gen_version() -> anyhow::Result<()> {
// let build = BuildBuilder::all_build()?;
// let git2 = Git2Builder::all_git()?;
let _path = env::current_dir()?;
// let repo = path.join("./../../../").canonicalize()?;
// p!("BUILD.rs -> Starting ...{}", repo.display());
// println!("The current directory is {}", path.display());
// let git2 = GitclBuilder::all_git()?;
let git2 = Git2Builder::all_git()?;
// VERGEN_GIT_SHA
// git2.at_path(repo);
Emitter::default()
// .add_instructions(&build)?
.add_instructions(&git2)?
.emit()?;
Ok(())
}
main.rs
impl AppGitHash {
pub fn get() -> Option<String> {
let hash = option_env!("VERGEN_GIT_SHA");
hash.map(|s| s[0..8].to_owned())
}
// VERGEN_GIT_SHA
}
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you!
Beta Was this translation helpful? Give feedback.