From edf378c7a41bb7bfff7b091a0d8c119c69de3021 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Fri, 10 Jan 2025 07:28:39 -0500 Subject: [PATCH] fix: render with platform and arch (#63) --- src/rattler_build_conda_compat/jinja/jinja.py | 9 +- .../recipe_sources.py | 2 +- tests/__snapshots__/test_jinja.ambr | 91 +++++++++++++++++++ tests/data/conditional_sources.yaml | 29 ++++++ .../jolt-physics/ci_support/osx_arm64_.yaml | 20 ++++ tests/data/jolt-physics/recipe.yaml | 3 + tests/test_jinja.py | 13 +++ 7 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 tests/data/conditional_sources.yaml create mode 100644 tests/data/jolt-physics/ci_support/osx_arm64_.yaml diff --git a/src/rattler_build_conda_compat/jinja/jinja.py b/src/rattler_build_conda_compat/jinja/jinja.py index 9b50a8b..173a36c 100644 --- a/src/rattler_build_conda_compat/jinja/jinja.py +++ b/src/rattler_build_conda_compat/jinja/jinja.py @@ -46,7 +46,14 @@ def jinja_env(variant_config: Mapping[str, str] | None = None) -> SandboxedEnvir target_platform = variant_config["target_platform"] if target_platform != "noarch": # set `linux` / `win` - extra_vars[target_platform.split("-")[0]] = True + platform, arch = target_platform.split("-") + extra_vars[platform] = True + if arch == "64": + extra_vars["x86_64"] = True + elif arch == "32": + extra_vars["x86"] = True + else: + extra_vars[arch] = True if target_platform.startswith("win"): extra_vars["unix"] = False diff --git a/src/rattler_build_conda_compat/recipe_sources.py b/src/rattler_build_conda_compat/recipe_sources.py index af7a66e..b2e64ff 100644 --- a/src/rattler_build_conda_compat/recipe_sources.py +++ b/src/rattler_build_conda_compat/recipe_sources.py @@ -148,7 +148,7 @@ def render(template: str | list[str], context: dict[str, str]) -> str | list[str for elem in visit_conditional_list( sources, - lambda x, combination=combination: _eval_selector(x, combination), # type: ignore[misc] + lambda x, combination=env.globals: _eval_selector(x, combination), # type: ignore[misc] ): # we need to explicitly cast here elem_dict = typing.cast(dict[str, Any], elem) diff --git a/tests/__snapshots__/test_jinja.ambr b/tests/__snapshots__/test_jinja.ambr index 0d49818..62381a8 100644 --- a/tests/__snapshots__/test_jinja.ambr +++ b/tests/__snapshots__/test_jinja.ambr @@ -1,4 +1,12 @@ # serializer version: 1 +# name: test_conditional_source_render + set({ + Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-linux.tar.gz', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_linux_version }}-linux.tar.gz', context={'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='eb1a9aa834a969a8ccbbb04061274623659a1fb273abda4413b47fe59e7ee412', md5=None), + Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-macos-arm64.tar.gz', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_osx_version }}-macos-arm64.tar.gz', context={'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='fa96331edf06dd2342cb27771367516296067e94961ec6e600add1c2eed9c41d', md5=None), + Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-windows.zip', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_win_version }}-windows.zip', context={'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='e63c0b75d50097194c425489a08cec9c0374ab7b8eafe5b015c076bb2432fa19', md5=None), + Source(url='https://blpapi.bloomberg.com/repository/releases/python/blpapi-3.24.11.tar.gz', template='https://blpapi.bloomberg.com/repository/releases/python/${{ name }}-${{ version }}.tar.gz', context={'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='94dc699df262187b3afe4f163526aac67fb5982b008efe851836e9f1cd5358c1', md5=None), + }) +# --- # name: test_context_rendering ''' context: @@ -38,6 +46,9 @@ - c_stdlib_stub - cmake - ninja + - if: cuda + then: + - cuda-compiler host: - compatible_pin cmake - subpackage_pin ${{ jolt_physics }} @@ -108,6 +119,9 @@ - c_stdlib_stub - cmake - ninja + - if: cuda + then: + - cuda-compiler host: - compatible_pin cmake - subpackage_pin ${{ jolt_physics }} @@ -178,6 +192,82 @@ - c_stdlib_stub - cmake - ninja + - if: cuda + then: + - cuda-compiler + host: + - compatible_pin cmake + - subpackage_pin ${{ jolt_physics }} + + build: + number: 0 + script: + - if: win + then: | + cmake -GNinja ^ + %CMAKE_ARGS% ^ + -DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^ + -DBUILD_SHARED_LIBS=ON ^ + -DCMAKE_BUILD_TYPE=Distribution ^ + -DCROSS_PLATFORM_DETERMINISTIC=ON ^ + -DTARGET_VIEWER=OFF ^ + -DTARGET_SAMPLES=OFF ^ + -DTARGET_HELLO_WORLD=OFF ^ + -DTARGET_UNIT_TESTS=OFF ^ + -DTARGET_PERFORMANCE_TEST=OFF ^ + -S %SRC_DIR%\Build + cmake --build . --target install + else: | + cmake -GNinja \ + $CMAKE_ARGS \ + -DCMAKE_INSTALL_PREFIX=$PREFIX \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_BUILD_TYPE=Distribution \ + -DCROSS_PLATFORM_DETERMINISTIC=ON \ + -DTARGET_VIEWER=OFF \ + -DTARGET_SAMPLES=OFF \ + -DTARGET_HELLO_WORLD=OFF \ + -DTARGET_UNIT_TESTS=OFF \ + -DTARGET_PERFORMANCE_TEST=OFF \ + -S $SRC_DIR/Build + cmake --build . --target install + + about: + homepage: https://github.com/jrouwe/JoltPhysics + license: MIT + license_file: LICENSE + summary: A multi core friendly rigid body physics and collision detection library. + description: A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West. + documentation: https://jrouwe.github.io/JoltPhysics/ + repository: https://github.com/jrouwe/JoltPhysics + + extra: + recipe-maintainers: + - baszalmstra + - context: + version: 5.1.0 + + package: + name: jolt-physics + version: 5.1.0 + + source: + - url: https://github.com/jrouwe/JoltPhysics/archive/refs/tags/v5.1.0.zip + sha256: 10fcc863ae2b9d48c2f22d8b0204034820e57a55f858b7c388ac9579d8cf4095 + - if: win + then: + url: https://win.com/jolt-physics.zip + sha256: 10fcc863ae2b9d48c2f22d8b0204034820e57a55f858b7c388ac9579d8cf4095 + + requirements: + build: + - cxx_compiler_stub + - c_stdlib_stub + - cmake + - ninja + - if: cuda + then: + - cuda-compiler host: - compatible_pin cmake - subpackage_pin ${{ jolt_physics }} @@ -240,6 +330,7 @@ Source(url='https://win.com', template='https://win.com', context={'name': 'foobar', 'version': '1.2.3'}, sha256='xxx', md5=None), Source(url=['https://foo.com/linux-64/zip.zip', 'https://mirror.com/linux-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None), Source(url=['https://foo.com/osx-64/zip.zip', 'https://mirror.com/osx-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None), + Source(url=['https://foo.com/osx-arm64/zip.zip', 'https://mirror.com/osx-arm64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None), Source(url=['https://foo.com/win-64/zip.zip', 'https://mirror.com/win-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='xxx', md5=None), }) # --- diff --git a/tests/data/conditional_sources.yaml b/tests/data/conditional_sources.yaml new file mode 100644 index 0000000..a0d7891 --- /dev/null +++ b/tests/data/conditional_sources.yaml @@ -0,0 +1,29 @@ +context: + name: blpapi + version: "3.24.11" + blpapicpp_linux_version: ${{ version }}.1 + blpapicpp_win_version: ${{ version }}.1 + blpapicpp_osx_version: ${{ version }}.1 + +package: + name: ${{ name|lower }} + version: ${{ version }} + +source: + - url: https://blpapi.bloomberg.com/repository/releases/python/${{ name }}-${{ version }}.tar.gz + sha256: 94dc699df262187b3afe4f163526aac67fb5982b008efe851836e9f1cd5358c1 + - if: linux + then: + url: https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_linux_version }}-linux.tar.gz + sha256: eb1a9aa834a969a8ccbbb04061274623659a1fb273abda4413b47fe59e7ee412 + target_directory: blpapi + - if: win + then: + url: https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_win_version }}-windows.zip + sha256: e63c0b75d50097194c425489a08cec9c0374ab7b8eafe5b015c076bb2432fa19 + target_directory: blpapi + - if: osx and arm64 + then: + url: https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_osx_version }}-macos-arm64.tar.gz + sha256: fa96331edf06dd2342cb27771367516296067e94961ec6e600add1c2eed9c41d + target_directory: blpapi diff --git a/tests/data/jolt-physics/ci_support/osx_arm64_.yaml b/tests/data/jolt-physics/ci_support/osx_arm64_.yaml new file mode 100644 index 0000000..f271588 --- /dev/null +++ b/tests/data/jolt-physics/ci_support/osx_arm64_.yaml @@ -0,0 +1,20 @@ +MACOSX_DEPLOYMENT_TARGET: +- '11.0' +MACOSX_SDK_VERSION: +- '11.0' +c_stdlib: +- macosx_deployment_target +c_stdlib_version: +- '11.0' +channel_sources: +- conda-forge +channel_targets: +- conda-forge main +cxx_compiler: +- clangxx +cxx_compiler_version: +- '16' +macos_machine: +- x86_64-apple-darwin13.4.0 +target_platform: +- osx-arm64 diff --git a/tests/data/jolt-physics/recipe.yaml b/tests/data/jolt-physics/recipe.yaml index 0404d95..d4a6258 100644 --- a/tests/data/jolt-physics/recipe.yaml +++ b/tests/data/jolt-physics/recipe.yaml @@ -19,6 +19,9 @@ requirements: - ${{ stdlib("c") }} - cmake - ninja + - if: cuda + then: + - cuda-compiler host: - ${{ pin_compatible('cmake') }} - ${{ pin_subpackage(jolt_physics) }} diff --git a/tests/test_jinja.py b/tests/test_jinja.py index bee67f7..b2228b8 100644 --- a/tests/test_jinja.py +++ b/tests/test_jinja.py @@ -66,3 +66,16 @@ def test_multi_source_render(snapshot) -> None: sources = render_all_sources(recipe_yaml, variants) assert sources == snapshot + + +def test_conditional_source_render(snapshot) -> None: + jolt_physics = test_data / "conditional_sources.yaml" + # reuse the ci_support variants + variants = (test_data / "jolt-physics" / "ci_support").glob("*.yaml") + + recipe_yaml = load_yaml(jolt_physics.read_text()) + variants = [load_yaml(variant.read_text()) for variant in variants] + + sources = render_all_sources(recipe_yaml, variants) + assert len(sources) == 4 + assert sources == snapshot