Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer sysroot matching subdir when there are multiple #5404

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion conda_build/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
"linux": (elffile,),
}

GNU_ARCH_MAP = {
"ppc64le": "powerpc64le",
"32": "i686",
"64": "x86_64",
}


def fix_shebang(f, prefix, build_python, osx_is_app=False):
path = join(prefix, f)
Expand Down Expand Up @@ -1406,8 +1412,20 @@ def check_overlinking_impl(
list(diffs)[1:3],
)
sysroots_files[srs] = sysroot_files

def sysroot_matches_subdir(path):
kenodegard marked this conversation as resolved.
Show resolved Hide resolved
# The path looks like <PREFIX>/aarch64-conda-linux-gnu/sysroot/
# We check that the triplet "aarch64-conda-linux-gnu"
# matches the subdir for eg: linux-aarch64.
sysroot_arch = Path(path).parent.name.split("-")[0]
subdir_arch = subdir.split("-")[-1]
return sysroot_arch == GNU_ARCH_MAP.get(subdir_arch, subdir_arch)

sysroots_files = OrderedDict(
sorted(sysroots_files.items(), key=lambda x: -len(x[1]))
sorted(
sysroots_files.items(),
key=lambda x: (not sysroot_matches_subdir(x[0]), -len(x[1])),
)
)

all_needed_dsos, needed_dsos_for_file = _collect_needed_dsos(
Expand Down
19 changes: 19 additions & 0 deletions news/5404-sysroot-prefer
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* On Linux platforms, prefer the sysroot matching the target_platform when cross-compiling (#5403).

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
8 changes: 8 additions & 0 deletions tests/test-recipes/metadata/_sysroot_detection/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

mkdir -p ${PREFIX}/bin

# Delete the x86_64 libc.so.6 to make sure we find the powerpc libc.so.6
rm -f ${BUILD_PREFIX}/x86_64-conda-linux-gnu/sysroot/lib64/libc.so.6

${CC} ${CFLAGS} main.c -o ${PREFIX}/bin/sysroot-detection
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target_platform:
- linux-ppc64le
5 changes: 5 additions & 0 deletions tests/test-recipes/metadata/_sysroot_detection/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>

int main() {
return 0;
}
15 changes: 15 additions & 0 deletions tests/test-recipes/metadata/_sysroot_detection/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% set version = "1" %}

package:
name: sysroot_detection
version: {{ version }}

source:
path: main.c

build:
number: 0

requirements:
build:
- {{ compiler('c') }}
12 changes: 12 additions & 0 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,18 @@ def test_overdepending_detection(testing_config, variants_conda_build_sysroot):
api.build(recipe, config=testing_config, variants=variants_conda_build_sysroot)


@pytest.mark.skipif(not on_linux, reason="cannot compile for linux-ppc64le")
def test_sysroots_detection(testing_config, variants_conda_build_sysroot):
recipe = os.path.join(metadata_dir, "_sysroot_detection")
testing_config.activate = True
testing_config.error_overlinking = True
testing_config.error_overdepending = True
testing_config.channel_urls = [
"conda-forge",
]
api.build(recipe, config=testing_config, variants=variants_conda_build_sysroot)


@pytest.mark.skipif(sys.platform != "darwin", reason="macOS-only test (at present)")
def test_macos_tbd_handling(testing_config, variants_conda_build_sysroot):
"""
Expand Down
Loading