message: build: skip re-link ckb-bin when under git control but no `.git/HEAD` file, e.g., in git worktree
diff: @@ -46,9 +46,20 @@ fn main() {
  );
  println!("cargo:rerun-if-changed=build.rs");
  - println!("cargo:rerun-if-changed=.git/HEAD");
  - let head = std::fs::read_to_string(".git/HEAD").unwrap_or_default();
  + let git_head = std::process::Command::new("git")
  + .args(&["rev-parse", "--git-dir"])
  + .output()
  + .ok()
  + .and_then(|r| String::from_utf8(r.stdout).ok())
  + .and_then(|s| s.lines().next().map(ToOwned::to_owned))
  + .map(|ref s| Path::new(s).to_path_buf())
  + .unwrap_or_else(|| Path::new(".git").to_path_buf())
  + .join("HEAD");
  + if git_head.exists() {
  + println!("cargo:rerun-if-changed={}", git_head.display());
  +
  + let head = std::fs::read_to_string(&git_head).unwrap_or_default();
  if head.starts_with("ref: ") {
  let path_str = format!(".git/{}", head[5..].trim());
  let path = Path::new(&path_str);
  @@ -57,6 +68,7 @@ fn main() {
  }
  }
  }
  + }
  for file in files_stdout.iter().flat_map(|stdout| stdout.lines()) {
  if rerun_if_changed(file) {
  