Skip to content

Instantly share code, notes, and snippets.

@matthewfeickert
Last active August 10, 2024 17:38
Show Gist options
  • Save matthewfeickert/df8c3cc32c17e2f4bc996806c45ddd36 to your computer and use it in GitHub Desktop.
Save matthewfeickert/df8c3cc32c17e2f4bc996806c45ddd36 to your computer and use it in GitHub Desktop.
Build and install a conda package with rattler-build
# build products
output/
example
# pixi environments
.pixi
*.egg-info

Build and install a conda package with rattler-build

Setup

pixi global install rattler-build  # good to have anyway
micromamba env create --yes --file environment.yml
micromamba activate local-conda-package-install-example

Build

rattler-build build  # defaults to --recipe recipe.yaml
$ tree -L 2 output/
output/
├── bld
│   └── rattler-build_xtensor_1723239688
├── linux-64
│   ├── repodata.json
│   └── xtensor-0.24.6-hb0f4dca_0.conda
├── noarch
│   └── repodata.json
└── src_cache
    ├── 0_24_6_f87259b5
    └── 0_24_6_f87259b5.tar.gz

6 directories, 4 files

Install

micromamba install --channel ./output/ xtensor

Use

# Linux
$ g++ -I $CONDA_PREFIX/include/ example.cpp -o example
# macOS
$ clang++ -I $CONDA_PREFIX/include/ example.cpp -o example
$ ./example
# {  7.,  11.,  14.}

References

name: local-conda-package-install-example
channels:
- conda-forge
dependencies:
- rattler-build >=0.19.0
- cxx-compiler >=1.7.0
#include <iostream>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xview.hpp>
int main(int argc, char* argv[])
{
xt::xarray<double> arr1
{{1.0, 2.0, 3.0},
{2.0, 5.0, 7.0},
{2.0, 5.0, 7.0}};
xt::xarray<double> arr2
{5.0, 6.0, 7.0};
xt::xarray<double> res = xt::view(arr1, 1) + arr2;
std::cout << res << std::endl;
return 0;
}
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json
context:
name: xtensor
version: 0.24.6
package:
name: ${{ name|lower }}
version: ${{ version }}
source:
url: https://github.com/xtensor-stack/xtensor/archive/${{ version }}.tar.gz
sha256: f87259b51aabafdd1183947747edfff4cff75d55375334f2e81cee6dc68ef655
build:
number: 0
script:
- if: win
then: |
cmake -G "Ninja" -D BUILD_TESTS=OFF -D CMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% %SRC_DIR%
ninja install
else: |
cmake ${CMAKE_ARGS} -G "Ninja" -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$PREFIX $SRC_DIR -DCMAKE_INSTALL_LIBDIR=lib
ninja install
requirements:
build:
- ${{ compiler('cxx') }}
- cmake
- ninja
host:
- xtl >=0.7,<0.8
run:
- xtl >=0.7,<0.8
run_constraints:
- xsimd >=8.0.3,<10
tests:
- script:
- if: unix or emscripten
then:
- test -d ${PREFIX}/include/xtensor
- test -f ${PREFIX}/include/xtensor/xarray.hpp
- test -f ${PREFIX}/share/cmake/xtensor/xtensorConfig.cmake
- test -f ${PREFIX}/share/cmake/xtensor/xtensorConfigVersion.cmake
- if: win
then:
- if not exist %LIBRARY_PREFIX%\include\xtensor\xarray.hpp (exit 1)
- if not exist %LIBRARY_PREFIX%\share\cmake\xtensor\xtensorConfig.cmake (exit 1)
- if not exist %LIBRARY_PREFIX%\share\cmake\xtensor\xtensorConfigVersion.cmake (exit 1)
about:
homepage: https://github.com/xtensor-stack/xtensor
license: BSD-3-Clause
license_file: LICENSE
summary: The C++ tensor algebra library
description: Multi dimensional arrays with broadcasting and lazy computing
documentation: https://xtensor.readthedocs.io
repository: https://github.com/xtensor-stack/xtensor
extra:
recipe-maintainers:
- some-maintainer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment