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

fix: render with platform and arch #63

Merged
merged 4 commits into from
Jan 10, 2025
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
9 changes: 8 additions & 1 deletion src/rattler_build_conda_compat/jinja/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rattler_build_conda_compat/recipe_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
91 changes: 91 additions & 0 deletions tests/__snapshots__/test_jinja.ambr
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -38,6 +46,9 @@
- c_stdlib_stub
- cmake
- ninja
- if: cuda
then:
- cuda-compiler
host:
- compatible_pin cmake
- subpackage_pin ${{ jolt_physics }}
Expand Down Expand Up @@ -108,6 +119,9 @@
- c_stdlib_stub
- cmake
- ninja
- if: cuda
then:
- cuda-compiler
host:
- compatible_pin cmake
- subpackage_pin ${{ jolt_physics }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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),
})
# ---
Expand Down
29 changes: 29 additions & 0 deletions tests/data/conditional_sources.yaml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions tests/data/jolt-physics/ci_support/osx_arm64_.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tests/data/jolt-physics/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ requirements:
- ${{ stdlib("c") }}
- cmake
- ninja
- if: cuda
then:
- cuda-compiler
host:
- ${{ pin_compatible('cmake') }}
- ${{ pin_subpackage(jolt_physics) }}
Expand Down
13 changes: 13 additions & 0 deletions tests/test_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading