Skip to content

Commit

Permalink
test: make sure rpath is inserted (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw authored Jan 25, 2024
1 parent 2719561 commit 406686c
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 50 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ jobs:
with:
pixi-version: v0.10.0
cache: true

- name: Build docs for test
run: |
pixi run build-docs
docs-release:
# Don't run on forks
if: startsWith(github.event.ref, 'refs/tags/v')
if: startsWith(github.event.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -72,7 +72,7 @@ jobs:
- name: Deploy with mike 🚀
env:
RELEASE_VERSION: ${{ steps.extract_branch.outputs.tag }}
run: |
run: |
pixi run deploy-latest
docs-dev:
Expand All @@ -97,4 +97,4 @@ jobs:
- name: Deploy with mike 🚀
run: |
pixi run deploy-dev
pixi run deploy-dev
2 changes: 2 additions & 0 deletions .github/workflows/end-to-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.10.0
- if: runner.os == 'macOS'
run: pixi global install patchelf
# build in release mode so that it's reasonably fast to run the tests
- run: cargo build --release
- run: cargo test --release -p rust-tests -- --test-threads 1
Expand Down
2 changes: 1 addition & 1 deletion docs/recipe_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -1262,4 +1262,4 @@ Now, by default building `libarchive` will use the dynamic build of `bzip2`. Whe

Features work by requiring a special build string. When compiling with features, the build string will be composed of all features and the build hash. For example, the following active features [zlib, bzip2] will be first alphabetically sorted and then concatenated to a build string of the form `+bzip2+zlib_h123123_0`. A deactivated feature will be prefixed with a `-`. To match packages against required build time features boa will compose a regex-based match string. E.g. when asking for at least `[bzip2]`, boa will use a build string of the form `+bzip2*`.

-->
-->
6 changes: 3 additions & 3 deletions examples/cmpcdt/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# cdt in actual recipe code

package:
name: async-cairo
name: async-cairo
version: dev

requirements:
host:
- if: linux
then: ${{ cdt("cairo") }}
then: ${{ cdt("cairo") }}
run:
- if: cmp("python", "==3.3")
then: asyncio
84 changes: 49 additions & 35 deletions rust-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,33 @@ mod tests {
.then(|| Self::WithBinary(path.as_ref().display().to_string()))
}

fn build<K: AsRef<Path>, T: AsRef<Path>, N: AsRef<Path>>(
fn build<K: AsRef<Path>, T: AsRef<Path>>(
&self,
recipe: K,
output_dir: T,
variant_config: Option<N>,
variant_config: Option<&str>,
target_platform: Option<&str>,
) -> Output {
let rs = recipe.as_ref().display().to_string();
let od = output_dir.as_ref().display().to_string();
let iter = [
let mut iter = vec![
"build",
"--recipe",
rs.as_str(),
"--output-dir",
od.as_str(),
];
if let Some(target_platform) = target_platform {
iter.push("--target-platform");
iter.push(target_platform);
}
if let Some(variant_config_path) = variant_config {
self.with_args(iter.into_iter().chain([
"--variant-config",
variant_config_path.as_ref().display().to_string().as_str(),
]))
} else {
self.with_args(iter)
iter.push("--variant-config");
iter.push(variant_config_path);
}
self.with_args(iter)
}

fn with_args(&self, args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> Output {
let (command, dir, cmd_args) = match self {
RattlerBuild::WithCargo(path) => (
Expand Down Expand Up @@ -211,7 +214,7 @@ mod tests {
let recipes = recipes();
let tmp = tmp("test_run_exports_from");
let rattler_build =
rattler().build::<_, _, &str>(recipes.join("run_exports_from"), tmp.as_dir(), None);
rattler().build::<_, _>(recipes.join("run_exports_from"), tmp.as_dir(), None, None);
// ensure rattler build succeeded
assert!(rattler_build.status.success());
let pkg = get_extracted_package(tmp.as_dir(), "run_exports_test");
Expand All @@ -233,8 +236,7 @@ mod tests {
fn test_run_exports() {
let recipes = recipes();
let tmp = tmp("test_run_exports");
let rattler_build =
rattler().build::<_, _, &str>(recipes.join("run_exports"), tmp.as_dir(), None);
let rattler_build = rattler().build(recipes.join("run_exports"), tmp.as_dir(), None, None);
// ensure rattler build succeeded
assert!(rattler_build.status.success());
let pkg = get_extracted_package(tmp.as_dir(), "run_exports_test");
Expand Down Expand Up @@ -291,8 +293,7 @@ mod tests {
#[test]
fn test_pkg_hash() {
let tmp = tmp("test_pkg_hash");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("pkg_hash"), tmp.as_dir(), None);
let rattler_build = rattler().build(recipes().join("pkg_hash"), tmp.as_dir(), None, None);

assert!(rattler_build.status.success());

Expand All @@ -307,8 +308,7 @@ mod tests {
#[test]
fn test_license_glob() {
let tmp = tmp("test_license_glob");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("globtest"), tmp.as_dir(), None);
let rattler_build = rattler().build(recipes().join("globtest"), tmp.as_dir(), None, None);

assert!(rattler_build.status.success());

Expand Down Expand Up @@ -373,8 +373,7 @@ mod tests {
#[test]
fn test_python_noarch() {
let tmp = tmp("test_python_noarch");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("toml"), tmp.as_dir(), None);
let rattler_build = rattler().build(recipes().join("toml"), tmp.as_dir(), None, None);

assert!(rattler_build.status.success());

Expand All @@ -389,8 +388,7 @@ mod tests {
#[test]
fn test_git_source() {
let tmp = tmp("test_git_source");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("llamacpp"), tmp.as_dir(), None);
let rattler_build = rattler().build(recipes().join("llamacpp"), tmp.as_dir(), None, None);

assert!(rattler_build.status.success());

Expand All @@ -405,7 +403,7 @@ mod tests {
#[test]
fn test_package_content_test_execution() {
let tmp = tmp("test_package_content_test_execution");
// let rattler_build = rattler().build::<_, _, &str>(
// let rattler_build = rattler().build(
// recipes().join("package-content-tests/rich-recipe.yaml"),
// tmp.as_dir(),
// None,
Expand All @@ -422,18 +420,20 @@ mod tests {

// assert!(rattler_build.status.success());

let rattler_build = rattler().build::<_, _, &str>(
let rattler_build = rattler().build(
recipes().join("package-content-tests/recipe-test-succeed.yaml"),
tmp.as_dir(),
None,
None,
);

assert!(rattler_build.status.success());

let rattler_build = rattler().build::<_, _, &str>(
let rattler_build = rattler().build(
recipes().join("package-content-tests/recipe-test-fail.yaml"),
tmp.as_dir(),
None,
None,
);

assert!(rattler_build.status.code() == Some(1));
Expand All @@ -442,18 +442,20 @@ mod tests {
#[test]
fn test_test_execution() {
let tmp = tmp("test_test_execution");
let rattler_build = rattler().build::<_, _, &str>(
let rattler_build = rattler().build(
recipes().join("test-execution/recipe-test-succeed.yaml"),
tmp.as_dir(),
None,
None,
);

assert!(rattler_build.status.success());

let rattler_build = rattler().build::<_, _, &str>(
let rattler_build = rattler().build(
recipes().join("test-execution/recipe-test-fail.yaml"),
tmp.as_dir(),
None,
None,
);

assert!(rattler_build.status.code().unwrap() == 1);
Expand All @@ -462,8 +464,7 @@ mod tests {
#[test]
fn test_noarch_flask() {
let tmp = tmp("test_noarch_flask");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("flask"), tmp.as_dir(), None);
let rattler_build = rattler().build(recipes().join("flask"), tmp.as_dir(), None, None);

assert!(rattler_build.status.success());

Expand Down Expand Up @@ -492,25 +493,23 @@ mod tests {
}
let tmp = tmp("test-sources");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("test-sources"), tmp.as_dir(), None);
rattler().build(recipes().join("test-sources"), tmp.as_dir(), None, None);

assert!(rattler_build.status.success());
}

#[test]
fn test_tar_source() {
let tmp = tmp("test_tar_source");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("tar-source"), tmp.as_dir(), None);
let rattler_build = rattler().build(recipes().join("tar-source"), tmp.as_dir(), None, None);

assert!(rattler_build.status.success());
}

#[test]
fn test_zip_source() {
let tmp = tmp("test_zip_source");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("zip-source"), tmp.as_dir(), None);
let rattler_build = rattler().build(recipes().join("zip-source"), tmp.as_dir(), None, None);

assert!(rattler_build.status.success());
}
Expand All @@ -519,10 +518,11 @@ mod tests {
fn test_dry_run_cf_upload() {
let tmp = tmp("test_polarify");
let variant = recipes().join("polarify").join("linux_64_.yaml");
let rattler_build = rattler().build::<_, _, PathBuf>(
let rattler_build = rattler().build(
recipes().join("polarify"),
tmp.as_dir(),
Some(variant),
variant.to_str(),
None,
);

assert!(rattler_build.status.success());
Expand Down Expand Up @@ -552,7 +552,21 @@ mod tests {
fn test_correct_sha256() {
let tmp = tmp("correct-sha");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("correct-sha"), tmp.as_dir(), None);
rattler().build(recipes().join("correct-sha"), tmp.as_dir(), None, None);
assert!(rattler_build.status.success());
}

#[test]
#[cfg(any(target_os = "linux", target_os = "macos"))]
fn test_rpath() {
let tmp = tmp("test_rpath");
let rattler_build = rattler().build(
recipes().join("rpath"),
tmp.as_dir(),
None,
Some("linux-64"),
);

assert!(rattler_build.status.success());
}
}
2 changes: 1 addition & 1 deletion src/linux/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl SharedObject {
rpath_allowlist: Option<&GlobSet>,
) -> Result<(), RelinkError> {
if !self.has_dynamic {
tracing::debug!("{} is not dynamically linked", self.path.display());
tracing::info!("{} is not dynamically linked", self.path.display());
return Ok(());
}

Expand Down
15 changes: 9 additions & 6 deletions src/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,26 +897,29 @@ pub fn package_conda(

tracing::info!("Copying done!");

let dynamic_linking = output.recipe.build().dynamic_linking();
let relocation_config = dynamic_linking
.and_then(|v| v.binary_relocation())
let dynamic_linking = output
.recipe
.build()
.dynamic_linking()
.cloned()
.unwrap_or_default();
let relocation_config = dynamic_linking.binary_relocation().unwrap_or_default();

if output.build_configuration.target_platform != Platform::NoArch
&& !relocation_config.no_relocation()
{
let rpath_allowlist = dynamic_linking.and_then(|dl| dl.rpath_allowlist());
let rpath_allowlist = dynamic_linking.rpath_allowlist();
let mut binaries = tmp_files.clone();
if let Some(globs) = relocation_config.relocate_paths() {
binaries.retain(|v| globs.is_match(v));
}

println!("Rpaths: {:?}", dynamic_linking.rpaths());
post::relink(
&binaries,
tmp_dir_path,
prefix,
&output.build_configuration.target_platform,
&dynamic_linking.map(|dl| dl.rpaths()).unwrap_or_default(),
&dynamic_linking.rpaths(),
rpath_allowlist,
)?;
}
Expand Down
38 changes: 38 additions & 0 deletions test-data/recipes/rpath/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

context:
name: mssql-tools
version: '18.2.1.1'

package:
name: ${{ name }}
version: ${{ version }}

source:
- url: https://packages.microsoft.com/rhel/7/prod/${{ name }}18-${{ version }}-1.x86_64.rpm
sha256: 98758f29f1b1aad13c5ce32a5cf1e849d35a97054d030ee5dccdab6aefd2aef9

build:
number: 0
script:
- bsdtar xf mssql-tools18-${{ version }}-1.x86_64.rpm
- mkdir -p $PREFIX/bin
- cp opt/mssql-tools18/bin/* $PREFIX/bin

requirements:
build:
- libarchive

tests:
- package_contents:
bin:
- sqlcmd
- bcp
- script:
# both binaries come shipped from the source without rpath
# but rattler-build should add $ORIGIN/../lib to rpath
- patchelf --print-rpath $PREFIX/bin/bcp | grep -q \$ORIGIN/../lib
- patchelf --print-rpath $PREFIX/bin/sqlcmd | grep -q \$ORIGIN/../lib
requirements:
build:
- patchelf

0 comments on commit 406686c

Please sign in to comment.