### Example Recipe File Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md A complete example of a recipe.yaml file, demonstrating the structure and common sections. ```yaml --8<-- "docs/snippets/recipes/imagesize.yaml" ``` -------------------------------- ### Install conda-recipe-manager Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/converting_from_conda_build.md Install the conversion utility via pixi or conda. ```bash pixi global install conda-recipe-manager # or conda install -c conda-forge conda-recipe-manager ``` -------------------------------- ### Parse Recipe Examples Source: https://github.com/prefix-dev/rattler-build/blob/main/crates/rattler_build_recipe/examples/README.md Various command-line examples demonstrating basic usage, variable substitution, variant configurations, and conditional logic. ```bash cargo example parse_recipe -- examples/simple_recipe.yaml ``` ```bash cargo example parse_recipe -- examples/simple_recipe.yaml \ -Dname=mypackage \ -Dversion=1.2.3 \ -Dorg=myorg \ -Dmaintainer="Bob Smith" \ -Dunix=true \ -Dpython_version=3.11 \ -Dadjective=cool ``` ```bash cargo example parse_recipe -- recipe.yaml --variants variants.yaml ``` ```bash cargo example parse_recipe -- recipe.yaml --variants variants.yaml -Dunix=true ``` ```bash # Unix build cargo example parse_recipe -- examples/simple_recipe.yaml \ -Dname=foo -Dversion=1.0.0 -Dunix=true -Dpython_version=3.11 # Windows build cargo example parse_recipe -- examples/simple_recipe.yaml \ -Dname=foo -Dversion=1.0.0 -Dpython_version=3.11 ``` -------------------------------- ### Example zlib Recipe File Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/highlevel.md A basic example of a `recipe.yaml` file used by Rattler-Build to define package build instructions. ```yaml --8<-- "docs/snippets/recipes/zlib.yaml" ``` -------------------------------- ### CPack Installation and Configuration Source: https://github.com/prefix-dev/rattler-build/blob/main/test-data/patch_application/workdir/CMakeLists.txt Configures installation rules for targets and files, and sets up CPack variables for packaging. ```cmake install(TARGETS ${LOVE_EXE_NAME} ${LOVE_CONSOLE_EXE_NAME} ${LOVE_LIB_NAME} RUNTIME DESTINATION .) if(LOVE_EXTRA_DLLS) foreach(DLL ${LOVE_EXTRA_DLLS}) get_filename_component(DLL_NAME ${DLL} NAME) message(STATUS "Extra DLL: ${DLL_NAME}") endforeach() install(FILES ${LOVE_EXTRA_DLLS} DESTINATION .) endif() if(LOVE_MSVC_DLLS) foreach(DLL ${LOVE_MSVC_DLLS}) get_filename_component(DLL_NAME ${DLL} NAME) message(STATUS "Runtime DLL: ${DLL_NAME}") endforeach() install(FILES ${LOVE_MSVC_DLLS} DESTINATION .) endif() function(copy_text_file ARG_FILE_IN ARG_FILE_OUT) file(READ ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_FILE_IN} TMP_TXT_CONTENTS) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${ARG_FILE_OUT} ${TMP_TXT_CONTENTS}) endfunction() copy_text_file(readme.md readme.txt) copy_text_file(license.txt license.txt) copy_text_file(changes.txt changes.txt) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/changes.txt ${CMAKE_CURRENT_BINARY_DIR}/license.txt ${CMAKE_CURRENT_BINARY_DIR}/readme.txt DESTINATION .) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis/love.ico ${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis/game.ico DESTINATION .) set(CPACK_GENERATOR ZIP NSIS) set(CPACK_PACKAGE_NAME "love") set(CPACK_PACKAGE_VENDOR "love2d.org") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LOVE -- It's awesome") set(CPACK_PACKAGE_VERSION "${LOVE_VERSION_STR}") set(CPACK_PACKAGE_VERSION_MAJOR "${LOVE_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${LOVE_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${LOVE_VERSION_REV}") set(CPACK_PACKAGE_INSTALL_DIRECTORY "LOVE") set(CPACK_PACKAGE_EXECUTABLES "${LOVE_EXE_NAME};LOVE") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/readme.md") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt") set(CPACK_NSIS_EXECUTABLES_DIRECTORY .) set(CPACK_NSIS_PACKAGE_NAME "LOVE") set(CPACK_NSIS_DISPLAY_NAME "LOVE ${LOVE_VERSION_STR}") set(CPACK_NSIS_MODIFY_PATH OFF) if(LOVE_X64) set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64") else() set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES") endif() set(CPACK_NSIS_MENU_LINKS "http://love2d.org/wiki" "Documentation") ``` -------------------------------- ### Go recipe configuration Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/tutorials/go.md Example recipe file for packaging a Go application. ```yaml --8<-- "docs/snippets/recipes/temporal.yaml" ``` -------------------------------- ### Debug Rattler-Build Setup Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/debugging_builds.md Commands for debugging the build process. Use `setup` to prepare the environment, and `shell` to enter the build or work environment. ```bash rattler-build debug setup --recipe recipe.yaml ``` ```bash rattler-build debug shell ``` ```bash rattler-build debug shell --work-dir /path/to/work ``` ```bash rattler-build debug workdir ``` ```bash rattler-build debug run ``` ```bash rattler-build debug run --trace ``` ```bash rattler-build debug host-add python numpy ``` ```bash rattler-build debug build-add cmake ``` ```bash rattler-build debug create-patch --name fix ``` ```bash rattler-build debug create-patch --name fix --dry-run ``` -------------------------------- ### Rattler-build Debug Setup Usage Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/cli/rattler-build/debug/setup.md Basic usage of the `rattler-build debug setup` command. This command initiates the setup process for a debug environment. ```bash rattler-build debug setup [OPTIONS] ``` -------------------------------- ### build.sh Example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/build_script.md Example of a build.sh script for Linux and macOS. Copies a script into the package's bin directory. ```bash mkdir -p $PREFIX/bin cp $RECIPE_DIR/my_script_with_recipe.sh $PREFIX/bin/super-cool-script.sh ``` -------------------------------- ### Install Rattler-Build with Pixi Source: https://github.com/prefix-dev/rattler-build/blob/main/README.md Installs rattler-build globally using the pixi package manager. Ensure pixi is installed first. ```bash pixi global install rattler-build ``` -------------------------------- ### Install diffoscope via pixi Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/rebuild.md Installs the diffoscope utility globally using the pixi package manager. ```bash pixi global install diffoscope ``` -------------------------------- ### VS2019 and Windows 11 SDK Component Identifiers Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/windows_quirks.md These are example component identifiers that can be used with the Visual Studio Installer command-line arguments for specific versions and SDKs. ```powershell # For VS2019, use --add Microsoft.VisualStudio.ComponentGroup.VC.Tools.142.x86.x64 # For Windows 11 SDK, --add Microsoft.VisualStudio.Component.Windows11SDK.22621 ``` -------------------------------- ### Setup Debug Environment Without Building Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/debugging_builds.md Prepares a debug environment by resolving dependencies, downloading sources, and creating the build script, but does not execute the script. ```bash rattler-build debug setup --recipe recipe.yaml rattler-build debug shell ``` -------------------------------- ### Install Feedrattler Globally Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/converting_from_conda_build.md Install feedrattler globally for command-line access using `pixi global install`. This makes the `feedrattler` command available system-wide. ```bash # Globally install the tool pixi global install feedrattler ``` -------------------------------- ### Generated PyPI recipe example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/recipe_generation.md Example output of a generated recipe file for a Python package. ```yaml --8<-- "docs/snippets/recipes/jinja2-generated.yaml" ``` -------------------------------- ### Define Recipe for Header-only Library Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/tutorials/cpp.md Example recipe configuration for building a header-only library like xtensor. ```yaml --8<-- "docs/snippets/recipes/xtensor-tutorial.yaml" ``` -------------------------------- ### Package Section Example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md Defines the name and version of the package being built. Ensure version numbers are quoted to be treated as strings. ```yaml package: name: bsdiff4 version: "2.1.4" ``` -------------------------------- ### Install rattler-index Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/rattler_index.md Install rattler-index globally using pixi. This command sets up the tool for use from any directory. ```bash pixi global install rattler-index ``` -------------------------------- ### Configure NSIS Installer Assets and UI Source: https://github.com/prefix-dev/rattler-build/blob/main/test-data/patch_application/workdir/CMakeLists.txt Sets paths for installer images and icons, and defines NSIS preprocessor directives for the installer UI. ```cmake set(NSIS_LEFT_BMP "${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis\\left.bmp") set(NSIS_TOP_BMP "${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis\\top.bmp") set(NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis\\love.ico") set(NSIS_MUI_UNICON "${CMAKE_CURRENT_SOURCE_DIR}/extra/nsis\\love.ico") set(CPACK_NSIS_INSTALLER_MUI_ICON_CODE " !define MUI_WELCOMEPAGE_TITLE \"LOVE ${LOVE_VERSION_STR} Setup\" !define MUI_WELCOMEFINISHPAGE_BITMAP \"${NSIS_LEFT_BMP}\" !define MUI_HEADERIMAGE_BITMAP \"${NSIS_TOP_BMP}\" !define MUI_ICON \"${NSIS_MUI_ICON}\" !define MUI_UNICON \"${NSIS_MUI_UNICON}\" ") ``` -------------------------------- ### Example Conda-Forge Recipe Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/conda_forge.md This is a minimal example of a recipe.yaml file required for conda-forge. Ensure all required metadata fields are present. ```yaml name: "my-package" version: "0.1.0" build: number: 0 script: "{{ PYTHON }} -m pip install . -vv" requirements: host: - python >=3.8 - pip run: - python >=3.8 about: home: "https://github.com/user/my-package" license: "MIT" summary: "A short description of my-package" ``` -------------------------------- ### Recipe format before bumping Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/bump_recipe.md This is an example of a recipe file before the `bump-recipe` command is applied. It shows the structure that the command expects. ```yaml --8<-- "docs/snippets/recipes/bump-before.yaml" ``` -------------------------------- ### Recipe Dependency Example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/variants.md Shows a typical 'host' requirement for 'python' in a recipe, which will trigger variant builds. ```yaml # ... requirements: host: - python ``` -------------------------------- ### Define requirements with libcurl Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/variants.md Example of host and run requirements for a package using libcurl. ```yaml requirements: host: - libcurl run: - libcurl ``` -------------------------------- ### Define Recipe for C++ Application Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/tutorials/cpp.md Example recipe configuration for building a C++ application like poppler. ```yaml --8<-- "docs/snippets/recipes/poppler.yaml" ``` -------------------------------- ### Generate a PyPI package recipe Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/tutorials/python.md Use this command to generate a starting recipe for a package from PyPI. You can specify a version to fetch metadata for. ```bash rattler-build generate-recipe pypi ipywidgets # select an older version of the package rattler-build generate-recipe pypi ipywidgets --version 8.0.0 ``` -------------------------------- ### Install C/C++ Build Tools with Winget Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/windows_quirks.md Use this command in PowerShell to silently install the C/C++ build tools, including the necessary components for Visual Studio. ```powershell # Install C/C++ build tools with Winget (through community installer) winget install Microsoft.VisualStudio.BuildTools --silent --accept-source-agreements --accept-package-agreements \ --override "--passive --wait --norestart --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended" ``` -------------------------------- ### Define Unix CMake Installation Prefix Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/tutorials/cpp.md Standard path configuration for header and library installation on Unix systems. ```sh $PREFIX/include $PREFIX/lib ``` -------------------------------- ### Install menu items in recipe.yaml Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/system_integration.md Place a JSON menu configuration file and associated icons into the $PREFIX/Menu directory during the build process. ```yaml build: script: # ... build the package # Install the menu item - mkdir -p $PREFIX/Menu - cp $RECIPE_DIR/menu/menu.json $PREFIX/Menu/pixi-editor.json - cp $RECIPE_DIR/icons/pixi-icon.* $PREFIX/Menu/ ``` -------------------------------- ### xtensor Recipe Example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/index.md A basic recipe for the xtensor C++ header-only library. This snippet is a placeholder and requires the actual content from the specified file. ```yaml --8<-- "docs/snippets/recipes/xtensor-index.yaml" ``` -------------------------------- ### Example Variant Configuration (variants.yaml) Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/variants.md Defines special entries like zip_keys and pin_run_as_build, and lists desired versions for packages like python and numpy. ```yaml # special entry #1, the zip keys zip_keys: - [python, numpy] # special entry #2, the pin_run_as_build key pin_run_as_build: numpy: max_pin: 'x.x' # entries per package version that users are interested in python: # Note that versions are _strings_ (not numbers) - "3.8" - "3.9" - "3.10" numpy: - "1.12" - "1.12" - "1.20" ``` -------------------------------- ### Common selector expressions Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/selectors.md Examples of conditional logic for cross-platform and architecture-specific builds. ```yaml if: build_platform != target_platform ... # true if cross-platform build if: osx and arm64 ... # true for apple silicon (osx-arm64) if: linux and (aarch64 or ppc64le)) ... # true for linux ppc64le or linux-aarch64 ``` -------------------------------- ### Define Windows CMake Installation Prefix Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/tutorials/cpp.md Path configuration for header and library installation on Windows systems using the Library directory. ```sh $PREFIX/Library/include $PREFIX/Library/lib ``` -------------------------------- ### curl Library Recipe Example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/index.md A recipe for the 'curl' library. This snippet is a placeholder and requires the actual content from the specified file. ```yaml --8<-- "docs/snippets/recipes/curl-index.yaml" ``` -------------------------------- ### Example Failing Recipe Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/debugging_builds.md A sample recipe.yaml that intentionally fails during the build process. ```yaml package: name: test version: "1.0" build: script: - exit 1 ``` -------------------------------- ### Get Rattler-Build Version Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/py-rattler-build/reference/index.md Retrieves the installed version of the Rattler-Build library. ```APIDOC ## Get Rattler-Build Version ### Description Retrieves the installed version of the Rattler-Build library. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters None ### Request Example ```python from rattler_build import rattler_build_version print(rattler_build_version()) ``` ### Response #### Success Response (200) - **version** (string) - The version string of Rattler-Build. #### Response Example ``` "1.2.3" ``` ``` -------------------------------- ### recipe.yaml Build Script Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/build_script.md Example of defining build steps within recipe.yaml using conditional logic for different platforms. Ensures platform-specific commands are used. ```yaml build: script: - if: unix then: - mkdir -p $PREFIX/bin - cp $RECIPE_DIR/my_script_with_recipe.sh $PREFIX/bin/super-cool-script.sh - if: win then: - mkdir %LIBRARY_BIN% - copy %RECIPE_DIR%\my_script_with_recipe.bat %LIBRARY_BIN%\super-cool-script.bat ``` -------------------------------- ### rattler-build debug host-add Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/cli/rattler-build/debug/host-add.md Installs additional packages into the host prefix of an existing debug build. This is useful for iterating on dependencies without re-running the full debug setup. ```APIDOC ## rattler-build debug host-add ### Description Install additional packages into the host prefix. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Arguments #### Path Parameters - **SPECS** (string) - Required - Package specs to install (e.g. "python>=3.11", "cmake", "numpy 1.26.*"). May be provided more than once. ### Options #### Query Parameters - **--channel** (`-c`) (string) - Optional - Channels to search for packages in. May be provided more than once. - **--work-dir** (string) - Optional - Work directory to use (reads from last build in rattler-build-log.txt if not specified). - **--output-dir** (`-o`) (string) - Optional - Output directory containing rattler-build-log.txt. Defaults to "./output". ### Request Example ```bash rattler-build debug host-add --channel conda-forge python=3.11 "numpy 1.26.*" ``` ### Response #### Success Response (200) This command does not return a JSON response. It modifies the build environment. #### Response Example Not applicable (CLI command) ``` -------------------------------- ### Inherit from Staging Output (Short Form) Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md This example demonstrates the short form of inheriting from a staging output. It inherits all files and run exports from the specified staging cache. ```yaml outputs: - staging: name: my-build build: script: - make install # Short form — inherits all files and run exports - package: name: mylib inherit: my-build build: files: - lib/** ``` -------------------------------- ### CI workflow for custom package forge Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/tips_and_tricks.md Example GitHub Actions configuration to build and upload packages using Rattler-Build. ```yaml name: Build all packages on: push: branches: - main workflow_dispatch: pull_request: branches: - main jobs: build: strategy: matrix: include: - { target: linux-64, os: ubuntu-20.04 } - { target: win-64, os: windows-latest } # force older macos-13 to get x86_64 runners - { target: osx-64, os: macos-13 } - { target: osx-arm64, os: macos-14 } fail-fast: false runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 with: fetch-depth: 2 - uses: prefix-dev/setup-pixi@v0.5.1 with: pixi-version: v0.24.2 cache: true - name: Run code in changed subdirectories shell: bash env: TARGET_PLATFORM: ${{ matrix.target }} run: | pixi run rattler-build build --recipe-dir . \ --skip-existing=all --target-platform=$TARGET_PLATFORM \ -c conda-forge -c https://prefix.dev/rust-forge - name: Upload all packages shell: bash # do not upload on PR if: github.event_name == 'push' env: PREFIX_API_KEY: ${{ secrets.PREFIX_API_KEY }} run: | # ignore errors because we want to ignore duplicate packages for file in output/**/*.conda; do pixi run rattler-build upload prefix -c rust-forge "$file" || true done ``` -------------------------------- ### Create BLAS Mutex Package Recipe Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/variants.md Define a mutex package recipe to ensure that only one BLAS implementation can be installed at a time. This example shows how to use build variants and prioritize certain implementations. ```yaml package: name: blas_mutex version: 1.0 build: string: ${{ blas_variant }}${{ hash }}_${{ build_number }} variant: # make sure that `openblas` is preferred over `mkl` down_prioritize_variant: ${{ 1 if blas_variant == "mkl" else 0 }} ``` -------------------------------- ### Configure Run Export for Mutex Package Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/variants.md Configure a package's run_export to ensure that any dependent package also depends on the correct mutex package. This example sets up OpenBLAS to export a dependency on the `blas_mutex` package with a build string starting with 'openblas'. ```yaml package: name: openblas version: 1.0 requirements: # any package depending on openblas should also depend on the correct blas_mutex package run_export: # Add a run export on _any_ version of the blas_mutex package whose build string starts with "openblas" - blas_mutex * openblas* ``` -------------------------------- ### Consuming Optional Dependencies Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md Example of how a downstream recipe can opt into a specific extra dependency group by naming it in the `run` requirements. ```yaml requirements: run: - mypkg[extras=[plot]] ``` -------------------------------- ### GitHub Actions Workflow for Attestation Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/sigstore.md This example demonstrates a complete GitHub Actions workflow that builds and publishes packages with automatic Sigstore attestation generation using rattler-build. ```yaml name: Build and publish with attestation on: [push] jobs: build: runs-on: ubuntu-latest # These permissions are needed for OIDC authentication permissions: id-token: write contents: read steps: - uses: actions/checkout@v4 - name: Set up rattler-build uses: prefix-dev/rattler-build-action@v0.2.34 - name: Build and publish with attestation run: | rattler-build publish ./recipe.yaml \ --to https://prefix.dev/my-channel \ --generate-attestation ``` -------------------------------- ### Install Rattler-Build with Homebrew Source: https://github.com/prefix-dev/rattler-build/blob/main/README.md Installs rattler-build on macOS using the Homebrew package manager. Ensure Homebrew is installed. ```bash brew install rattler-build ``` -------------------------------- ### Install Rattler-Build using Conda/Mamba/Micromamba Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/index.md Installs rattler-build using common conda-compatible package managers. Installs from the conda-forge channel. ```bash conda install rattler-build -c conda-forge ``` ```bash mamba install rattler-build -c conda-forge ``` ```bash micromamba install rattler-build -c conda-forge ``` -------------------------------- ### Example Variant Configuration JSON Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/variants.md Shows the JSON structure of a variant configuration file used for hashing, with a specific Python version. ```json { "python": "3.8" } ``` -------------------------------- ### Basic Staging Output Example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/multi_output.md Demonstrates a basic staging output ('mylib-build') that compiles a library once, followed by package outputs ('libmylib', 'mylib-headers') that inherit from the staging cache and select specific files. ```yaml recipe: name: mylib version: 2.0.0 source: - url: https://example.com/mylib-2.0.0.tar.gz sha256: abcdef... outputs: # Staging: builds the library once - staging: name: mylib-build requirements: build: - ${{ compiler('c') }} - cmake - ninja build: script: - cmake -GNinja -DCMAKE_INSTALL_PREFIX=$PREFIX . - ninja install # Package: runtime library - package: name: libmylib inherit: mylib-build build: files: - lib/* requirements: run_exports: - ${{ pin_subpackage('libmylib') }} # Package: development headers - package: name: mylib-headers inherit: mylib-build build: files: - include/* requirements: run: - ${{ pin_subpackage('libmylib', exact=True) }} ``` -------------------------------- ### Configure Archive Formats and Assemble Packages Source: https://github.com/prefix-dev/rattler-build/blob/main/py-rattler-build/notebooks/package_assembly.ipynb Demonstrates how to check available archive extensions and create a package using the legacy .tar.bz2 format. ```python print("Available archive types:") print(f" ArchiveType.Conda -> {ArchiveType.Conda.extension()}") print(f" ArchiveType.TarBz2 -> {ArchiveType.TarBz2.extension()}") # Create a .tar.bz2 package output_dir5 = work_dir / "output5" output_dir5.mkdir() output = assemble_package( name="legacy-format", version="1.0.0", target_platform="linux-64", build_string="0", output_dir=output_dir5, files_dir=repro_dir, archive_type=ArchiveType.TarBz2, ) print(f"\nCreated: {output.path.name}") ``` -------------------------------- ### Show all available information Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/cli/rattler-build/package/inspect.md To view all available information about the package, use the `--all` option. ```bash rattler-build package inspect --all ``` -------------------------------- ### Install Feedrattler with Conda/Mamba Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/converting_from_conda_build.md Install feedrattler using conda or mamba from the conda-forge channel. This is an alternative installation method if you primarily use these package managers. ```bash # or using conda/mamba conda install -c conda-forge feedrattler ``` -------------------------------- ### Windows Filesystem Layout Example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/windows_quirks.md Illustrates the typical directory structure on Windows, including the 'Library' folder mimicking Unix, a root 'site-packages' directory, and separate 'Scripts' and 'bin' folders. ```text %PREFIX% ├── Library │ ├── lib │ ├── bin │ ├── share │ ├── etc │ └── ... ├── site-packages ├── Scripts └── bin ``` -------------------------------- ### Generated CRAN recipe example Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/recipe_generation.md Example output of a generated recipe file for an R package. ```yaml --8<-- "docs/snippets/recipes/r-dplyr-generated.yaml" ``` -------------------------------- ### Define and render a multi-output recipe Source: https://github.com/prefix-dev/rattler-build/blob/main/py-rattler-build/notebooks/multi_output_and_staging.ipynb Demonstrates creating a recipe with multiple outputs where one output depends on another as a host dependency. ```python # Multi-output recipe with inter-output dependency multi_output_yaml = """ schema_version: 1 context: name: myproject version: "2.0.0" recipe: version: ${{ version }} outputs: # First output: The library - package: name: ${{ name }}-lib build: script: interpreter: python content: | import os from pathlib import Path prefix = Path(os.environ["PREFIX"]) lib_dir = prefix / "lib" / "python" lib_dir.mkdir(parents=True, exist_ok=True) (lib_dir / "myproject_lib.py").write_text('VERSION = "2.0.0"') print(f"Created library at {lib_dir}") requirements: build: - python # Second output: Uses the library as a host dependency - package: name: ${{ name }}-tools build: script: interpreter: python content: | import os from pathlib import Path prefix = Path(os.environ["PREFIX"]) # Read and print the lib file (installed as host dependency) lib_file = prefix / "lib" / "python" / "myproject_lib.py" print(f"Reading library from: {lib_file}") print(lib_file.read_text()) requirements: build: - python host: - ${{ name }}-lib """ multi_recipe = Stage0Recipe.from_yaml(multi_output_yaml) print("Multi-Output Recipe Loaded") print("=" * 60) print(f"Recipe type: {type(multi_recipe).__name__}") print(f"Is multi-output: {isinstance(multi_recipe, MultiOutputRecipe)}") print(f"Number of outputs: {len(multi_recipe.outputs)}") print("\nOutputs:") for idx, output in enumerate(multi_recipe.outputs, 1): print(f" {idx}. {output.to_dict()['package']['name']}") # Render the recipe mo_variants = VariantConfig() mo_render = RenderConfig() mo_results = multi_recipe.render(mo_variants, mo_render) print(f"\nRendered {len(mo_results)} package(s):") print("=" * 60) for rendered in mo_results: stage1 = rendered.recipe print(f"\nPackage: {stage1.package.name} {stage1.package.version}") print(f" Build script: {stage1.build.script}") print(f" Run requirements: {stage1.requirements.run}") ``` -------------------------------- ### Build and Publish with Attestation Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/sigstore.md Use this command to build a recipe and publish packages to a prefix.dev channel while automatically generating Sigstore attestations. ```bash # Build and publish in one go rattler-build publish ./my-recipe.yaml --to https://prefix.dev/my-channel --generate-attestation ``` -------------------------------- ### Initialize and Use Source Cache Source: https://github.com/prefix-dev/rattler-build/blob/main/crates/rattler_build_source_cache/README.md Demonstrates creating a SourceCache with custom configuration and fetching different types of sources (URL, Git, Path). Requires `rattler_build_source_cache` and `chrono` crates. ```rust use rattler_build_source_cache::{SourceCacheBuilder, Source, UrlSource, GitSource, GitReference, Checksum}; #[tokio::main] async fn main() -> Result<(), Box> { // Create a cache with custom configuration let cache = SourceCacheBuilder::new() .cache_dir("/path/to/cache") .max_age(chrono::Duration::days(30)) .enable_cleanup(true) .cleanup_interval(std::time::Duration::from_secs(3600)) .build() .await?; // Fetch a URL source let url_source = Source::Url(UrlSource { urls: vec!["https://example.com/archive.tar.gz".parse()?], checksum: Some(Checksum::Sha256(vec![/* hash bytes */])), file_name: None, // Will auto-extract }); let path = cache.get_source(&url_source).await?; println!("Source cached at: {}", path.display()); // Fetch a Git repository use rattler_build_source_cache::GitReference; let git_source = Source::Git(GitSource::new( "https://github.com/example/repo".parse()?, GitReference::Branch("main".to_string()), Some(1), false, true, )); let repo_path = cache.get_source(&git_source).await?; println!("Repository cloned at: {}", repo_path.display()); // Path sources are passed through without caching let path_source = Source::Path("/local/path".into()); let local_path = cache.get_source(&path_source).await?; assert_eq!(local_path, std::path::Path::new("/local/path")); Ok(()) } ``` -------------------------------- ### Convert recipe files Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/converting_from_conda_build.md Run the conversion utility to transform meta.yaml to recipe.yaml. ```bash conda-recipe-manager convert my-recipe/meta.yaml ``` ```bash conda-recipe-manager convert my-recipe/meta.yaml > recipe.yaml ``` -------------------------------- ### Install Rattler-Build with Micromamba Source: https://github.com/prefix-dev/rattler-build/blob/main/README.md Installs rattler-build from the conda-forge channel using micromamba. Requires micromamba to be set up. ```bash micromamba install rattler-build -c conda-forge ``` -------------------------------- ### Build a package from a recipe Source: https://github.com/prefix-dev/rattler-build/blob/main/py-rattler-build/README.md Loads a recipe from a file and executes the build process. ```python from rattler_build import Stage0Recipe, VariantConfig recipe = Stage0Recipe.from_file("recipe.yaml") results = recipe.run_build() for result in results: print(f"Built {result.name} {result.version} in {result.build_time:.1f}s") for pkg in result.packages: print(f" {pkg}") ``` -------------------------------- ### Common Build Options Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/getting_started.md Configure build channels and variant configurations. ```bash # Add channels for dependencies (note: conda-forge is the default) rattler-build build -c conda-forge -c bioconda # Use variant configurations rattler-build build -m variants.yaml ``` -------------------------------- ### Install Rattler-Build on Arch Linux Source: https://github.com/prefix-dev/rattler-build/blob/main/README.md Installs rattler-build on Arch Linux using pacman. This command assumes you are using Arch Linux. ```bash pacman -S rattler-build ``` -------------------------------- ### Install Rattler-Build on Alpine Linux Source: https://github.com/prefix-dev/rattler-build/blob/main/README.md Installs rattler-build on Alpine Linux from the edge repository using apk. Ensure the testing repository is enabled. ```shell apk add rattler-build ``` -------------------------------- ### Configure Prefix Detection and Replacement Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/build_options.md Control how the installation prefix is handled in text and binary files. Options include forcing file types, ignoring specific files or all binary files, and managing padding for binary prefix replacement. ```yaml package: name: mypackage version: 1.0 build: # settings concerning the prefix detection in files prefix_detection: # force the file type of the given files to be TEXT or BINARY # for prefix replacement force_file_type: # force TEXT file type (list of globs) text: list of globs # force binary file type (list of globs) binary: list of globs # ignore all or specific files for prefix replacement` ignore: bool | [path] (defaults to false) # whether to ignore binary files for prefix replacement # defaults to false on Unix and (always) true on Windows ignore_binary_files: bool ``` -------------------------------- ### Basic Run Requirements Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md Specifies the essential packages needed to run the package. These are installed automatically when the package is installed. Package names must follow conda package match specifications. ```yaml requirements: run: - python - six >=1.8.0 ``` -------------------------------- ### Create a minimal package Source: https://github.com/prefix-dev/rattler-build/blob/main/py-rattler-build/notebooks/package_assembly.ipynb Assemble a basic package by specifying only the name, version, and source directory. ```python # Create temporary directories for our example work_dir = Path(tempfile.mkdtemp()) files_dir = work_dir / "files" output_dir = work_dir / "output" files_dir.mkdir() output_dir.mkdir() # Create some example files to package (files_dir / "bin").mkdir() (files_dir / "bin" / "hello").write_text("#!/bin/bash\necho 'Hello, World!'") # Create the package output = assemble_package( name="hello", version="1.0.0", target_platform="linux-64", build_string="0", output_dir=output_dir, files_dir=files_dir, ) print(f"Package created: {output.path.name}") print(f"Identifier: {output.identifier}") ``` -------------------------------- ### Install Cross-Platform Activation Scripts Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/special_files.md Installs activation scripts for different shells on Unix-like systems and Windows. This ensures the package behaves correctly across various operating systems and shell environments. ```sh # Unix shells (Bash, Zsh) mkdir -p $PREFIX/etc/conda/activate.d cp activate-mypkg.sh $PREFIX/etc/conda/activate.d/10-activate-mypkg.sh # Windows Cmd.exe cp activate-mypkg.bat $PREFIX/etc/conda/activate.d/10-activate-mypkg.bat # Windows PowerShell cp activate-mypkg.ps1 $PREFIX/etc/conda/activate.d/10-activate-mypkg.ps1 ``` -------------------------------- ### Upload to S3 Bucket (Cloudflare R2 Example) Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/authentication_and_upload.md Upload packages to an S3-compatible bucket by setting S3_* environment variables for authentication. This example demonstrates uploading to a Cloudflare R2 bucket with specific endpoint and addressing style. ```bash export S3_ACCESS_KEY_ID= export S3_SECRET_ACCESS_KEY= rattler-build upload s3 \ --channel s3://my-bucket/my-channel \ --region auto \ --endpoint-url https://xyz.r2.cloudflarestorage.com \ --addressing-style path ``` -------------------------------- ### Get Rattler-Build Version Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/py-rattler-build/reference/index.md Retrieves the current version of the rattler_build library. ```python from rattler_build import rattler_build_version print(rattler_build_version()) ``` -------------------------------- ### Create a package with metadata Source: https://github.com/prefix-dev/rattler-build/blob/main/py-rattler-build/notebooks/package_assembly.ipynb Include package metadata such as license, homepage, dependencies, and constraints during assembly. ```python # Create new directories files_dir2 = work_dir / "files2" output_dir2 = work_dir / "output2" files_dir2.mkdir() output_dir2.mkdir() # Create a Python package structure (files_dir2 / "lib" / "python3.12" / "site-packages" / "mylib").mkdir(parents=True) (files_dir2 / "lib" / "python3.12" / "site-packages" / "mylib" / "__init__.py").write_text( '"""My library."""\n__version__ = "2.0.0"\n' ) # Create package with full metadata output = assemble_package( name="mylib", version="2.0.0", target_platform="linux-64", build_string="py312_0", output_dir=output_dir2, files_dir=files_dir2, # Metadata homepage="https://github.com/example/mylib", license="MIT", license_family="MIT", summary="A demonstration library", description="This is a longer description of the library.", # Dependencies depends=["python >=3.12,<3.13", "numpy >=1.20"], constrains=["scipy >=1.0"], build_number=0, ) print(f"Package: {output.path.name}") print(f"Identifier: {output.identifier}") ``` -------------------------------- ### Importing Rendering Classes Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/py-rattler-build/reference/rendering.md Import the necessary classes from the rattler_build package to begin recipe rendering. ```python from rattler_build import VariantConfig, RenderConfig, RenderedVariant ``` -------------------------------- ### Initialize Filesystem Channel Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/publish.md Publish a package to a local filesystem channel. If the channel directory does not exist, Rattler-Build will create it, initialize it with an empty repodata.json, upload the package, and run indexing. ```bash rattler-build publish ./my-package.conda --to file:///path/to/my-channel ``` -------------------------------- ### Get Working Directory Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/debugging_builds.md Retrieves the path to the current working directory for the build. ```bash rattler-build debug workdir ``` -------------------------------- ### Create a DebugSession Source: https://github.com/prefix-dev/rattler-build/blob/main/py-rattler-build/notebooks/debug_session.ipynb Initialize a session to resolve dependencies and prepare the build environment. ```python session = DebugSession.create( variants[0], channels=["conda-forge"], ) print(f"Work directory: {session.work_dir}") ``` -------------------------------- ### Build Script for Copying Post-Link Script Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/special_files.md Example of a build script configuration to copy a post-link script into the correct location within the package's bin directory. Ensure the script is executable. ```yaml build: ... script: - ... - mkdir -p $PREFIX/bin - cp $RECIPE_DIR/post-link.sh $PREFIX/bin/.mypkg-post-link.sh - chmod +x $PREFIX/bin/.mypkg-post-link.sh ``` -------------------------------- ### Show detailed file listing with hashes and sizes Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/cli/rattler-build/package/inspect.md Append the `--paths` option to display detailed file listings, including hashes and sizes for each file within the package. ```bash rattler-build package inspect --paths ``` -------------------------------- ### rattler-build debug build-add Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/cli/rattler-build/debug/build-add.md Installs additional packages into the build prefix of an existing debug build. ```APIDOC ## rattler-build debug build-add ### Description Install additional packages into the build prefix. This command resolves and installs the specified packages into the build environment of an existing debug build. Useful for adding build tools without re-running the full debug setup. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Arguments #### Path Parameters - **SPECS** (string) - Required - Package specs to install (e.g. "python>=3.11", "cmake", "numpy 1.26.*"). May be provided more than once. ### Options #### Query Parameters - **--channel (-c)** (string) - Optional - Channels to search for packages in. May be provided more than once. - **--work-dir** (string) - Optional - Work directory to use (reads from last build in rattler-build-log.txt if not specified). - **--output-dir (-o)** (string) - Optional - Output directory containing rattler-build-log.txt. Default: `./output`. ### Request Example ```bash rattler-build debug build-add --channel conda-forge --output-dir ./build python=3.10 "scipy>=1.10" ``` ### Response #### Success Response (200) Not applicable (CLI command output) #### Response Example ``` Installing python=3.10... Installing scipy>=1.10... ``` ``` -------------------------------- ### Ruby Test Internal Script Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md An example of the Ruby script generated internally to require specified modules. ```ruby require 'json' require 'rspec' ``` -------------------------------- ### R Test Internal Script Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md An example of the R script generated internally to load specified libraries. ```r library(knitr) ``` -------------------------------- ### Create a render configuration Source: https://github.com/prefix-dev/rattler-build/blob/main/py-rattler-build/notebooks/recipe_rendering_basics.ipynb Defines platform targets and custom context variables for the rendering process. ```python platform_config = PlatformConfig( target_platform="linux-64", build_platform="linux-64", host_platform="linux-64", experimental=False, ) render_config = RenderConfig( platform=platform_config, extra_context={ "custom_var": "custom_value", "build_timestamp": "2024-01-01", "my_number": 42, }, ) print("Render Configuration") print("=" * 60) print(f"Target platform: {render_config.target_platform}") print(f"Build platform: {render_config.build_platform}") print(f"Host platform: {render_config.host_platform}") print(f"Experimental: {render_config.experimental}") print("\nCustom context variables:") print(json.dumps(render_config.get_all_context(), indent=2)) ``` -------------------------------- ### Perl Test Internal Script Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md An example of the Perl script generated internally to use specified modules. ```perl use Call::Context; ``` -------------------------------- ### Python Test Internal Script Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md An example of the Python script generated internally to import specified modules. ```python import bsdiff4 import bspatch4 ``` -------------------------------- ### Select files for package output Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/multi_output.md Use the build files key to define which files from the prefix are included in the package. ```yaml build: files: - lib/*.so - lib/*.so.* ``` -------------------------------- ### Execute the patch creation workflow Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/create_patch.md The standard workflow involves setting up a debug environment, modifying files, and generating a patch file. ```bash # Set up debug environment and enter the debug shell rattler-build debug setup --recipe recipe.yaml rattler-build debug shell # You're now in the work directory with the build environment sourced. # Edit files directly: vim some_file.c # Generate patch (from inside the debug shell, the directories are auto-detected) rattler-build debug create-patch --name fix-typo # Add to recipe ``` -------------------------------- ### Source from Pre-built Binary with `file_name` Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/reference/recipe_file.md Specify a URL for a pre-built binary and use `file_name` to give it a clean, platform-independent name in the work directory. This is useful for binaries with complex URL paths. ```yaml source: url: https://github.com/owner/project/releases/download/v1.0.0/project-v1.0.0-linux-amd64 sha256: file_name: project # rename to a clean, platform-independent name ``` -------------------------------- ### Define NSIS Registry Operations Source: https://github.com/prefix-dev/rattler-build/blob/main/test-data/patch_application/workdir/CMakeLists.txt Configures registry keys for file associations and system notifications during installation and uninstallation. ```cmake set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS " WriteRegStr HKCR \".love\" \"\" \"LOVE\" WriteRegStr HKCR \"LOVE\" \"\" \"LOVE Game File\" WriteRegStr HKCR \"LOVE\\DefaultIcon\" \"\" \"$INSTDIR\\game.ico\" WriteRegStr HKCR \"LOVE\\shell\" \"\" \"open\" WriteRegStr HKCR \"LOVE\\shell\\open\" \"\" \"Open in LOVE\" WriteRegStr HKCR \"LOVE\\shell\\open\\command\" \"\" \"$INSTDIR\\love.exe $\\\"%1$\\\"\" System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)' ") set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS " DeleteRegKey HKCR \"LOVE\" DeleteRegKey HKCR \".love\" System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)' ") include(CPack) ``` -------------------------------- ### Install Rattler-Build with Pixi (Project) Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/index.md Adds rattler-build as a dependency to a pixi project. This is useful for project-specific build environments. ```bash pixi add rattler-build ``` -------------------------------- ### Build Against Multiple Python Versions Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/variants.md Demonstrates how to specify multiple Python versions for variants using a comma-separated string on the CLI. ```console rattler-build build --recipe ./my-recipe --variant python=3.12,3.13 ``` -------------------------------- ### Import Package Assembler Classes Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/py-rattler-build/reference/package_assembler.md Import necessary classes and functions from the rattler_build library to start assembling packages. ```python from rattler_build import assemble_package, collect_files, ArchiveType, FileEntry, PackageOutput ``` -------------------------------- ### Ship shell completions in recipe.yaml Source: https://github.com/prefix-dev/rattler-build/blob/main/docs/system_integration.md Generate and install shell completion scripts into the appropriate $PREFIX/share directories to enable tab-completion. ```yaml package: name: ripgrep version: "1.24.3" # ... other fields omitted for brevity build: number: 1 noarch: generic script: # Build and install ripgrep ... # Then generate the completions # ZSH completions - mkdir -p $PREFIX/share/zsh/site-functions - rg --generate complete-zsh > $PREFIX/share/zsh/site-functions/_rg # Bash completions - mkdir -p $PREFIX/share/bash-completion/completions - rg --generate complete-bash > $PREFIX/share/bash-completion/completions/rg # Fish completions - mkdir -p $PREFIX/share/fish/vendor_completions.d - rg --generate complete-fish > $PREFIX/share/fish/vendor_completions.d/rg.fish # ... continue recipe ```