#build #package #conda #yaml #recipe #python-packages #macos

build rattler-build

Rust 库,用于在 Windows、macOS 和 Linux 上构建 conda 软件包

1 个不稳定版本

0.7.0 2024年1月10日

#185 in 构建工具

BSD-3-Clause

610KB
14K SLoC

包含 (ELF 可执行文件/库, 18KB) test-data/binary_files/zlink

banner

License Build Status Project Chat

rattler-build:快速的 conda 软件包构建器

rattler-build 工具和库可以从简单的配方格式创建跨平台的可移动二进制文件/软件包。配方格式受到 conda-buildboa 的很大启发,并且常规 rattler-build 运行的输出是一个可以使用 mambarattlerconda 安装的软件包。

rattler-build 不依赖于 conda-buildPython,并且作为一个独立的二进制文件运行。

安装

您可以从 GitHub 发布 获取 rattler-build 的预发布版本。

或者,您可以通过 Homebrew 安装 rattler-build

brew install pavelzw/pavelzw/rattler-build

依赖项

目前 rattler-build 需要在宿主机系统上执行某些依赖项,这些依赖项作为子进程执行。我们计划通过在 Rust 中编写所需的内容来逐步减少外部依赖项的数量,以便使 rattler-build 完全自包含。

  • tar 用来解压从互联网下载的各种格式的 tar 文件。广泛使用的格式包括 .gz.bz2.xz,可能还需要安装压缩包(例如 gzipbzip2 等)。
  • patch 用于下载后的源代码打补丁
  • install_name_tool 在 macOS 上是必要的,用于重写共享库和可执行文件的 rpath 以使其相对化
  • patchelf 在 Linux 上是必需的,用于重写共享库和可执行文件的 rpathrunpath
  • git 用于检出 Git 仓库(尚未实现,但将来需要 git)
  • 在 Windows 上需要 msvc,因为我们不能将 MSVC 编译器打包到 conda-forge 中(需要在主机机器上安装)

在 Windows 上,要使用 conda-forge 获取这些依赖项,可以安装 m2-patchm2-bzip2m2-gzipm2-tar

文档

我们为 rattler-build 提供了大量的文档。您可以在这里找到该手册。

用法

rattler-build 包含两个命令:buildtest

build 命令接受一个 --recipe recipe.yaml 作为输入,并生成一个包作为输出。可以使用 test 子命令来测试现有包(测试与包一起提供)。

配方格式

注意 您可以在examples 文件夹中找到所有下面的示例,并使用 rattler-build 运行它们。

一个简单的用于 xtensor 只包含头文件的 C++ 库的示例配方

# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

context:
  name: xtensor
  version: 0.24.6
  sha256: f87259b51aabafdd1183947747edfff4cff75d55375334f2e81cee6dc68ef655

package:
  name: ${{ name|lower }}
  version: ${{ version }}

source:
  url: https://github.com/xtensor-stack/xtensor/archive/${{ version }}.tar.gz
  sha256: ${{ sha256 }}

build:
  number: 0
  # note: in the new recipe format, `skip` is a list of conditional expressions
  #       but for the "YAML format" discussion we pretend that we still use the
  #       `skip: bool` syntax
  skip: ${{ true if (win and vc14) }}
  script:
    - if: win
      then: |
        cmake -G "NMake Makefiles" -D BUILD_TESTS=OFF -D CMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% %SRC_DIR%
        nmake
        nmake install
      else: |
        cmake ${CMAKE_ARGS} -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$PREFIX $SRC_DIR -DCMAKE_INSTALL_LIBDIR=lib
        make install

requirements:
  build:
    - ${{ compiler('cxx') }}
    - cmake
    - if: unix
      then: make
  host:
    - xtl >=0.7,<0.8
  run:
    - xtl >=0.7,<0.8
  run_constrained:
    - 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
用于 `rich` Python 包的配方(使用 `noarch`)
context:
  version: "13.4.2"

package:
  name: "rich"
  version: ${{ version }}

source:
  - url: https://pypi.io/packages/source/r/rich/rich-${{ version }}.tar.gz
    sha256: d653d6bccede5844304c605d5aac802c7cf9621efd700b46c7ec2b51ea914898

build:
  # Thanks to `noarch: python` this package works on all platforms
  noarch: python
  script:
    - python -m pip install . -vv --no-deps --no-build-isolation

requirements:
  host:
    - pip
    - poetry-core >=1.0.0
    - python 3.10
  run:
    # sync with normalized deps from poetry-generated setup.py
    - markdown-it-py >=2.2.0
    - pygments >=2.13.0,<3.0.0
    - python 3.10
    - typing_extensions >=4.0.0,<5.0.0

tests:
  - python:
      imports:
        - rich
      pip_check: true

about:
  homepage: https://github.com/Textualize/rich
  license: MIT
  license_file: LICENSE
  summary: Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal
  description: |
    Rich is a Python library for rich text and beautiful formatting in the terminal.

    The Rich API makes it easy to add color and style to terminal output. Rich
    can also render pretty tables, progress bars, markdown, syntax highlighted
    source code, tracebacks, and more — out of the box.
  documentation: https://rich.pythonlang.cn
  repository: https://github.com/Textualize/rich
用于 `curl` 库的配方
context:
  version: "8.0.1"

package:
  name: curl
  version: ${{ version }}

source:
  url: http://curl.haxx.se/download/curl-${{ version }}.tar.bz2
  sha256: 9b6b1e96b748d04b968786b6bdf407aa5c75ab53a3d37c1c8c81cdb736555ccf

build:
  number: 0

requirements:
  build:
    - ${{ compiler('c') }}
    - if: win
      then:
        - cmake
        - ninja
    - if: unix
      then:
        - make
        - perl
        - pkg-config
        - libtool
  host:
    - if: linux
      then:
        - openssl

about:
  homepage: http://curl.haxx.se/
  license: MIT/X derivate (http://curl.haxx.se/docs/copyright.html)
  license_file: COPYING
  summary: tool and library for transferring data with URL syntax
  description: |
    Curl is an open source command line tool and library for transferring data
    with URL syntax. It is used in command lines or scripts to transfer data.
  documentation: https://curl.haxx.se/docs/
  repository: https://github.com/curl/curl

对于此配方,需要两个额外的脚本文件(build.shbuild.bat)。

build.sh

#!/bin/bash

# Get an updated config.sub and config.guess
cp $BUILD_PREFIX/share/libtool/build-aux/config.* .

if [[ $target_platform =~ linux.* ]]; then
    USESSL="--with-openssl=${PREFIX}"
else
    USESSL="--with-secure-transport"
fi;

./configure \
    --prefix=${PREFIX} \
    --host=${HOST} \
    ${USESSL} \
    --with-ca-bundle=${PREFIX}/ssl/cacert.pem \
    --disable-static --enable-shared

make -j${CPU_COUNT} ${VERBOSE_AT}
make install

# Includes man pages and other miscellaneous.
rm -rf "${PREFIX}/share"

build.bat

mkdir build

cmake -GNinja ^
      -DCMAKE_BUILD_TYPE=Release ^
      -DBUILD_SHARED_LIBS=ON ^
      -DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
      -DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX% ^
      -DCURL_USE_SCHANNEL=ON ^
      -DCURL_USE_LIBSSH2=OFF ^
      -DUSE_ZLIB=ON ^
      -DENABLE_UNICODE=ON ^
      %SRC_DIR%

IF %ERRORLEVEL% NEQ 0 exit 1

ninja install --verbose

依赖项

~39–75MB
~1.5M SLoC