-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace symlinks in the output of cargo build scripts (#3067)
#2948 breaks building of rdkafka with `cmake` because of dangling symlinks. When building with latest version we get the following error: ``` ERROR: /home/wincent/.cache/bazel/_bazel_wincent/394c4c1d21c5490d4a70260a2cfccaf5/external/rules_rust~~crate~crates__rdkafka-sys-4.8.0-2.3.0/BUILD.bazel:68:19: error while validating output tree artifact external/rules_rust~~crate~crates__rdkafka-sys-4.8.0-2.3.0/_bs.out_dir: child lib/cmake/RdKafka/FindLZ4.cmake is a dangling symbolic link ERROR: /home/wincent/.cache/bazel/_bazel_wincent/394c4c1d21c5490d4a70260a2cfccaf5/external/rules_rust~~crate~crates__rdkafka-sys-4.8.0-2.3.0/BUILD.bazel:68:19: Running Cargo build script rdkafka-sys failed: not all outputs were created or valid Target @@rules_rust~~crate~crates__rdkafka-0.37.0//:rdkafka failed to build Use --verbose_failures to see the command lines of failed build steps. ERROR: /home/wincent/.cache/bazel/_bazel_wincent/394c4c1d21c5490d4a70260a2cfccaf5/external/rules_rust~~crate~crates__rdkafka-sys-4.8.0-2.3.0/BUILD.bazel:18:13 Compiling Rust rlib rdkafka_sys v4.8.0+2.3.0 (7 files) failed: not all outputs were created or valid ```
- Loading branch information
Showing
5 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/cargo_build_script/resolve_abs_symlink_out_dir/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
load("//cargo:defs.bzl", "cargo_build_script") | ||
load("//rust:defs.bzl", "rust_test") | ||
|
||
# We are testing the cargo build script behavior that it correctly resolves absolute path symlinks in the out_dir. | ||
# Additionally, it keeps out_dir relative symlinks intact. | ||
|
||
cargo_build_script( | ||
name = "symlink_build_rs", | ||
srcs = ["build.rs"], | ||
data = ["data.txt"], | ||
edition = "2018", | ||
) | ||
|
||
rust_test( | ||
name = "test", | ||
srcs = ["test.rs"], | ||
data = [":symlink_build_rs"], | ||
edition = "2018", | ||
deps = [":symlink_build_rs"], | ||
) |
28 changes: 28 additions & 0 deletions
28
test/cargo_build_script/resolve_abs_symlink_out_dir/build.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
#[cfg(target_family = "unix")] | ||
fn symlink(original: impl AsRef<Path>, link: impl AsRef<Path>) { | ||
std::os::unix::fs::symlink(original, link).unwrap(); | ||
} | ||
|
||
#[cfg(target_family = "windows")] | ||
fn symlink(original: impl AsRef<Path>, link: impl AsRef<Path>) { | ||
std::os::windows::fs::symlink_file(original, link).unwrap(); | ||
} | ||
|
||
fn main() { | ||
let path = "data.txt"; | ||
if !PathBuf::from(path).exists() { | ||
panic!("File does not exist in path."); | ||
} | ||
let out_dir = std::env::var("OUT_DIR").unwrap(); | ||
let out_dir = PathBuf::from(&out_dir); | ||
let original_cwd = std::env::current_dir().unwrap(); | ||
std::fs::copy(&path, &out_dir.join("data.txt")).unwrap(); | ||
std::env::set_current_dir(&out_dir).unwrap(); | ||
std::fs::create_dir("nested").unwrap(); | ||
symlink("data.txt", "relative_symlink.txt"); | ||
symlink("../data.txt", "nested/relative_symlink.txt"); | ||
std::env::set_current_dir(&original_cwd).unwrap(); | ||
println!("{}", out_dir.display()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Resolved symlink file or relative symlink |
17 changes: 17 additions & 0 deletions
17
test/cargo_build_script/resolve_abs_symlink_out_dir/test.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#[test] | ||
pub fn test_compile_data_resolved_symlink() { | ||
let data = include_str!(concat!(env!("OUT_DIR"), "/data.txt")); | ||
assert_eq!("Resolved symlink file or relative symlink\n", data); | ||
} | ||
|
||
#[test] | ||
pub fn test_compile_data_relative_symlink() { | ||
let data = include_str!(concat!(env!("OUT_DIR"), "/relative_symlink.txt")); | ||
assert_eq!("Resolved symlink file or relative symlink\n", data); | ||
} | ||
|
||
#[test] | ||
pub fn test_compile_data_relative_nested_symlink() { | ||
let data = include_str!(concat!(env!("OUT_DIR"), "/nested/relative_symlink.txt")); | ||
assert_eq!("Resolved symlink file or relative symlink\n", data); | ||
} |