Skip to content

Commit 782078b

Browse files
ryanskeithjaimergp
andauthored
Support dynamic cdt_name that should help fix CI issues. (#5837)
* Adding in code to check for cdt_name. Also adding tests. * Adding documentation. * Update conda_build/environ.py Co-authored-by: jaimergp <jaimergp@users.noreply.github.com> * Update docs/source/user-guide/environment-variables.rst Co-authored-by: jaimergp <jaimergp@users.noreply.github.com> * Updating test to use 'el' instead of 'cos6' in linux. * Mistype! el8. The 8 in important. * Adding in cdt_linking specific change. * Trying a workaround to fix the CI. * It may be using conda-forge so let's try conda-forge cdt. * So I guess we were not using cf actually. Out of curosity, let's try. * Trying to simplify cdt test to be more universal. * simplifying even more. * Simplifying test again and adding cdt_name. * This might just work. * Trying to go use conda-forge * Using conda per review suggestion. * Simplifying the cdt recipe. * Adding docs. * Updating docs. * Adding news. * Reverting change from another PR. * Fixing git branching mistake so we don't override other work. --------- Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
1 parent 02c32d4 commit 782078b

File tree

8 files changed

+135
-31
lines changed

8 files changed

+135
-31
lines changed

conda_build/environ.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,14 +744,18 @@ def linux_vars(m, get_default, prefix):
744744
# the GNU triplet is powerpc, not ppc. This matters.
745745
if build_arch.startswith("ppc"):
746746
build_arch = build_arch.replace("ppc", "powerpc")
747-
if (
748-
build_arch.startswith("powerpc")
749-
or build_arch.startswith("aarch64")
750-
or build_arch.startswith("s390x")
751-
):
752-
build_distro = "cos7"
747+
# Check if cdt_name is specified in the variant first
748+
# Default based on architecture if not specified
749+
if build_arch.startswith(("powerpc", "aarch64", "s390x")):
750+
default_build_distro = "cos7"
751+
else:
752+
default_build_distro = "cos6"
753+
754+
# Override with variant value if provided
755+
if m.config.variant:
756+
build_distro = m.config.variant.get("cdt_name", default_build_distro)
753757
else:
754-
build_distro = "cos6"
758+
build_distro = default_build_distro
755759
# There is also QEMU_SET_ENV, but that needs to be
756760
# filtered so it only contains the result of `linux_vars`
757761
# which, before this change was empty, and after it only

docs/source/user-guide/environment-variables.rst

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,45 @@ defined only on macOS.
191191
* - OSX_ARCH
192192
- ``i386`` or ``x86_64``, depending on Python build.
193193

194-
The environment variable listed in the following table is
195-
defined only on Linux.
194+
The environment variables listed in the following table are
195+
defined only on Linux. These variables can be set from the
196+
shell environment, variant configuration (e.g., in
197+
``conda_build_config.yaml``), or use default values.
196198

197199
.. list-table::
198200
:widths: 20 80
199201

202+
* - BUILD
203+
- GNU triplet specifying the build target, for example
204+
``x86_64-conda_cos6-linux-gnu`` or ``aarch64-conda_cos7-linux-gnu``.
205+
The distribution component (e.g., ``cos6``, ``cos7``, ``el8``) can be
206+
customized by setting the ``cdt_name`` variable in variant
207+
configuration. Defaults to ``cos6`` for most architectures, ``cos7``
208+
for ``powerpc``, ``aarch64``, and ``s390x``. If ``BUILD`` and ``cdt_name`` are both set,
209+
BUILD takes precedence.
210+
* - CFLAGS
211+
- C compiler flags. Inherited from environment or variant
212+
configuration if set, otherwise empty.
213+
* - CXXFLAGS
214+
- C++ compiler flags. Inherited from environment or variant
215+
configuration if set, otherwise empty.
216+
* - DEJAGNU
217+
- DejaGnu test framework configuration. Inherited from
218+
environment or variant configuration if set, otherwise empty.
219+
* - DISPLAY
220+
- X11 display variable. Inherited from environment or variant
221+
configuration if set, otherwise empty.
200222
* - LD_RUN_PATH
201-
- ``$PREFIX/lib``.
223+
- Runtime library search path. Defaults to ``$PREFIX/lib``.
224+
* - LDFLAGS
225+
- Linker flags. Inherited from environment or variant
226+
configuration if set, otherwise empty.
227+
* - QEMU_LD_PREFIX
228+
- QEMU library prefix for cross-compilation. Inherited from
229+
environment or variant configuration if set, otherwise empty.
230+
* - QEMU_UNAME
231+
- QEMU uname information for cross-compilation. Inherited from
232+
environment or variant configuration if set, otherwise empty.
202233

203234

204235
.. _git-env:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Enhancements
2+
3+
* <news item>
4+
5+
### Bug fixes
6+
7+
* Fixed BUILD environment variable to respect `cdt_name` variant configuration. Previously, BUILD was hardcoded to use `cos6` or `cos7` based on architecture, ignoring the `cdt_name` variant when specified. Now, if `cdt_name` is provided in the variant configuration, it will be used in the BUILD variable; otherwise, it falls back to the architecture-based default. (#5733)
8+
9+
### Deprecations
10+
11+
* <news item>
12+
13+
### Docs
14+
15+
* <news item>
16+
17+
### Other
18+
19+
* <news item>

tests/test-recipes/metadata/_render_recipe/conda_build_config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ channel_sources:
140140
channel_targets:
141141
- conda-forge main
142142

143+
# This is synced with AnacondaRecipes/aggregate repository in the conda_build_config.yaml file.
143144
cdt_name: # [linux]
144-
- cos7 # [linux]
145-
146-
- cos7 # [linux and os.environ.get("CF_CUDA_ENABLED", "False") == "True"]
147-
- cos7 # [linux and os.environ.get("CF_CUDA_ENABLED", "False") == "True"]
145+
- el8 # [linux]
146+
- el8 # [linux and os.environ.get("CF_CUDA_ENABLED", "False") == "True"]
147+
- el8 # [linux and os.environ.get("CF_CUDA_ENABLED", "False") == "True"]
148148

149149
docker_image: # [os.environ.get("BUILD_PLATFORM", "").startswith("linux-")]
150150
# Native builds

tests/test-recipes/metadata/cdt_linking/build.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,32 @@
22

33
set -x
44

5-
echo -e "#include <GL/gl.h>\nint main() { glBegin(GL_TRIANGLES); glEnd(); return 0; }">gl.c
6-
${CC} -o ${PREFIX}/bin/links-to-opengl-cdt -x c $(pkg-config --libs gl) -Wl,-rpath-link,${PREFIX}/lib gl.c
7-
find ${PREFIX} -name "libGL*"
5+
# Simple test that CDT packages can be linked
6+
# Compile a minimal program that links against PAM and libselinux from CDT packages.
7+
# This works on main channel currently, 2025-11-11. It may be worth creating another
8+
# test that uses conda-forge.
9+
cat > cdt_test.c << 'EOF'
10+
#include <stddef.h>
11+
#include <security/pam_appl.h>
12+
#include <selinux/selinux.h>
13+
14+
int main() {
15+
// Test PAM - just check that the header is available
16+
const char *pam_strerror_result = pam_strerror(NULL, 0);
17+
(void)pam_strerror_result; // Suppress unused variable warning
18+
19+
// Test libselinux - check if SELinux is enabled
20+
int selinux_enabled = is_selinux_enabled();
21+
(void)selinux_enabled; // Suppress unused variable warning
22+
23+
return 0;
24+
}
25+
EOF
26+
27+
${CC} -o ${PREFIX}/bin/links-to-cdt -I${PREFIX}/include -L${PREFIX}/lib \
28+
-lpam -lselinux -Wl,-rpath-link,${PREFIX}/lib cdt_test.c
29+
30+
# Verify the libraries are present
31+
find ${PREFIX} -name "libpam*"
32+
find ${PREFIX} -name "libselinux*"
833
find ${PREFIX} -name "libc.so*"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cdt_name: # [linux]
2+
- el8 # [linux]

tests/test-recipes/metadata/cdt_linking/meta.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,5 @@ build:
1010
requirements:
1111
build:
1212
- {{ compiler('c') }}
13-
- pkg-config
14-
- {{ cdt('libxcb') }}
13+
- {{ cdt('pam-devel') }}
1514
- {{ cdt('libselinux-devel') }}
16-
- {{ cdt('libxi-devel') }}
17-
- {{ cdt('libx11-devel') }}
18-
- {{ cdt('libxau-devel') }}
19-
- {{ cdt('libxext-devel') }}
20-
- {{ cdt('libxfixes-devel') }}
21-
- {{ cdt('mesa-libgl-devel') }}
22-
- {{ cdt('xorg-x11-proto-devel') }}
23-
- {{ cdt('mesa-dri-drivers') }}
24-
- {{ cdt('libxdamage-devel') }}
25-
- {{ cdt('libxxf86vm') }}
26-
- expat

tests/test_environ.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Copyright (C) 2014 Anaconda, Inc
22
# SPDX-License-Identifier: BSD-3-Clause
33
import os
4+
import platform
45

5-
from conda_build.environ import create_env
6+
import pytest
7+
8+
from conda_build.environ import create_env, os_vars
9+
10+
on_linux = platform.system() == "Linux"
611

712

813
def test_environment_creation_preserves_PATH(testing_workdir, testing_config):
@@ -15,3 +20,33 @@ def test_environment_creation_preserves_PATH(testing_workdir, testing_config):
1520
subdir=testing_config.build_subdir,
1621
)
1722
assert os.environ["PATH"] == ref_path
23+
24+
25+
@pytest.mark.skipif(
26+
not on_linux, reason="BUILD variable with cdt_name is Linux-specific"
27+
)
28+
def test_build_variable_respects_cdt_name_variant(testing_metadata):
29+
"""Test that BUILD environment variable uses cdt_name from variant when specified.
30+
31+
This addresses issue #5733 where BUILD was hardcoded to cos6/cos7 based on
32+
architecture instead of respecting the cdt_name variant.
33+
"""
34+
testing_metadata.config.variant["cdt_name"] = "el8"
35+
env_vars = os_vars(testing_metadata, testing_metadata.config.host_prefix)
36+
37+
# Verify BUILD contains the cdt_name from variant
38+
assert "conda_el8" in env_vars["BUILD"]
39+
40+
41+
@pytest.mark.skipif(
42+
not on_linux, reason="BUILD variable with cdt_name is Linux-specific"
43+
)
44+
def test_build_variable_defaults_to_architecture_based_distro(testing_metadata):
45+
"""Test that BUILD variable defaults to cos6/cos7 when cdt_name is not specified."""
46+
if "cdt_name" in testing_metadata.config.variant:
47+
del testing_metadata.config.variant["cdt_name"]
48+
49+
env_vars = os_vars(testing_metadata, testing_metadata.config.host_prefix)
50+
51+
# Verify BUILD uses default cos6 or cos7 (not a custom cdt_name)
52+
assert "conda_cos6" in env_vars["BUILD"] or "conda_cos7" in env_vars["BUILD"]

0 commit comments

Comments
 (0)