Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Dec 4, 2024
2 parents f936d00 + 15f70b2 commit d40027b
Show file tree
Hide file tree
Showing 32 changed files with 765 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/typos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
uses: actions/[email protected]

- name: Check spelling
uses: crate-ci/[email protected].1
uses: crate-ci/[email protected].2
41 changes: 14 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
exclude: '(\.patch|\.diff|\.snap|\.ambr|test-data/recipes/test-parsing/.+)$'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
exclude: tests/data
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: ['--max-line-length=120']
language_version: python3
additional_dependencies:
- flake8-typing-imports==1.15.0
- flake8-builtins==2.1.0
- flake8-bugbear==23.9.16
- flake8-isort==6.1.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: local
hooks:
- id: rustfmt
Expand Down
83 changes: 79 additions & 4 deletions docs/multiple_output_cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ recipe:
version: '0.1.0'

cache:
source:
- url: https://example.com/library.tar.gz
sha256: 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef

requirements:
build:
- ${{ compiler('c') }}

build:
script:
- mkdir -p $PREFIX/lib
Expand Down Expand Up @@ -56,15 +61,85 @@ You can use a list of globs to select only the files that you want.

For something more complicated you can also use `include` and `exclude` fields in the `files` selector. Please refer to the [the build options documentation](build_options.md#include-only-certain-files-in-the-package).

## Run exports from the cache
### Run exports from the cache

Since the cache output also has build- and host requirements we need to additionally take care of eventual "run-exports" from the cache output.
Run exports from the cache-dependencies are handled very similar to the run exports from a given output. We append any run exports to the outputs.

If the cache has an "ignore run exports" section, than we apply those filters at the cache level. If the output ignores any run exports, then we also ignore the run-exports if they would come from the cache.

## Caching in the $SRC_DIR
### Source code in the cache

The cache output has its own `source` section. For every output, the (dirty) source is restored from the cache directory. Outputs can layer additional files on top of the cache source.
However, if you already ran `cmake` in the cache output, you can continue from where the build left off. This is useful when you want to e.g. build additional components (such as Python bindings) on top of the already-built library.


If you used `conda-build` a lot, you might have noticed that a top-level build is also caching the changes in the `$SRC_DIR`. This is not the case for `rattler-build` yet.
## C++ Example that builds Python bindings on top of a library

You can find an example (with source code) here: [Link](https://github.com/wolfv/rattler-build-cache-test/).

```yaml title="variants.yaml"
python:
- "3.12.*"
- "3.11.*"
```

And the corresponding recipe:

```yaml title="recipe.yaml"
recipe:
name: calculator
version: 1.0.0
cache:
source:
path: ../
You could try to work around by e.g. copying files into the `$PREFIX` and restoring them in each output.
requirements:
build:
- ${{ compiler('cxx') }}
- cmake
- ninja
build:
script:
# make sure that `alternative_name.md` is not present
- test ! -f ./alternative_name.md
- mkdir build
- cd build
- cmake $SRC_DIR -GNinja ${CMAKE_ARGS}
- ninja install

outputs:
# this first output will include all files installed during the cache build
- package:
name: libcalculator

requirements:
run_exports:
- ${{ pin_subpackage('libcalculator') }}
# This output will build the Python bindings using CMake and then create new
# packages with the Python bindings
- package:
name: py-calculator
source:
- path: ../README.md
file_name: alternative_name.md

requirements:
build:
- ${{ compiler('cxx') }}
- cmake
- ninja
host:
- pybind11
- python
- libcalculator

build:
script:
# assert that the README.md file is present
- test -f ./alternative_name.md
- cd build
- cmake $SRC_DIR -GNinja ${CMAKE_ARGS} -DBUILD_PYTHON_BINDINGS=ON
- ninja install
```
28 changes: 26 additions & 2 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ Build a package from a recipe
Path to an auth-file to read authentication information from


- `--channel-priority <CHANNEL_PRIORITY>`

Channel priority to use when solving

- Default value: `strict`

- `--tui`

Launch the terminal user interface
Expand Down Expand Up @@ -334,6 +340,12 @@ These test files are written at "package creation time" and are part of the pack
Path to an auth-file to read authentication information from


- `--channel-priority <CHANNEL_PRIORITY>`

Channel priority to use when solving

- Default value: `strict`

###### **Modifying result**

- `--output-dir <OUTPUT_DIR>`
Expand Down Expand Up @@ -399,6 +411,12 @@ Rebuild a package from a package file instead of a recipe
Path to an auth-file to read authentication information from


- `--channel-priority <CHANNEL_PRIORITY>`

Channel priority to use when solving

- Default value: `strict`

###### **Modifying result**

- `--test <TEST>`
Expand Down Expand Up @@ -431,7 +449,7 @@ Upload a package

##### **Subcommands:**

* `quetz` — Upload to aQuetz server. Authentication is used from the keychain / auth-file
* `quetz` — Upload to a Quetz server. Authentication is used from the keychain / auth-file
* `artifactory` — Options for uploading to a Artifactory channel. Authentication is used from the keychain / auth-file
* `prefix` — Options for uploading to a prefix.dev server. Authentication is used from the keychain / auth-file
* `anaconda` — Options for uploading to a Anaconda.org server
Expand Down Expand Up @@ -474,6 +492,12 @@ Upload a package
Path to an auth-file to read authentication information from


- `--channel-priority <CHANNEL_PRIORITY>`

Channel priority to use when solving

- Default value: `strict`

###### **Modifying result**

- `--output-dir <OUTPUT_DIR>`
Expand All @@ -487,7 +511,7 @@ Upload a package

#### `quetz`

Upload to aQuetz server. Authentication is used from the keychain / auth-file
Upload to a Quetz server. Authentication is used from the keychain / auth-file

**Usage:** `rattler-build upload quetz [OPTIONS] --url <URL> --channel <CHANNEL>`

Expand Down
93 changes: 93 additions & 0 deletions docs/tutorials/perl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Packaging a Perl (CPAM) package

Packaging a Perl package is similar to packaging a Python package!

## Building a Perl Package

### A perl `noarch: generic` package

The following recipe is for the Perl package `Call::Context`. We use `perl` in the `host` requirements, and install the package using `make`.
The `noarch: generic` is used to indicate that the package is architecture-independent - since this is a pure Perl package, it can be installed and run on any platform (`noarch`).

```yaml title="recipe.yaml"
context:
version: 0.03

package:
name: perl-call-context
version: ${{ version }}

source:
url: https://cpan.metacpan.org/authors/id/F/FE/FELIPE/Call-Context-${{ version }}.tar.gz
sha256: 0ee6bf46bc72755adb7a6b08e79d12e207de5f7809707b3c353b58cb2f0b5a26

build:
number: 0
noarch: generic
script:
- perl Makefile.PL INSTALLDIRS=vendor NO_PERLLOCAL=1 NO_PACKLIST=1
- make
- make test
- make install

requirements:
build:
- make
host:
- perl

tests:
- perl:
uses:
- Call::Context

about:
license: GPL-1.0-or-later OR Artistic-1.0-Perl
summary: Sanity-check calling context
homepage: http://metacpan.org/pod/Call-Context
```
### A perl package with a C extension
Some `perl` packages have native code extensions. In this example, we will build a package for the Perl package `Data::Dumper` using the `C` compiler.
The `c` compiler and `make` are required at build time in the `build` requirements to compile the native code extension.
We use `perl` in the `host` requirements, and install the package using `make`.

```yaml title="recipe.yaml"
context:
version: "2.183"
package:
name: "perl-data-dumper"
version: ${{ version }}
source:
url: https://cpan.metacpan.org/authors/id/N/NW/NWCLARK/Data-Dumper-${{ version }}.tar.gz
sha256: e42736890b7dae1b37818d9c5efa1f1fdc52dec04f446a33a4819bf1d4ab5ad3
build:
number: 0
script:
- perl Makefile.PL INSTALLDIRS=vendor NO_PERLLOCAL=1 NO_PACKLIST=1
- make
- make test
- make install VERBINST=1
requirements:
build:
- ${{ compiler('c') }}
- make
host:
- perl
- perl-extutils-makemaker
tests:
- perl:
uses:
- Data::Dumper
about:
homepage: https://metacpan.org/pod/Data::Dumper
license: GPL-1.0-or-later OR Artistic-1.0-Perl
summary: 'seeds germane, yet not germinated'
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ nav:
- "Javascript": tutorials/javascript.md
- "Rust": tutorials/rust.md
- "Go": tutorials/go.md
- "Perl": tutorials/perl.md
- "Converting from conda-build": converting_from_conda_build.md

- Build options:
Expand Down
2 changes: 1 addition & 1 deletion py-rattler-build/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Python bindings to rattler-build
# Python bindings to rattler-build
3 changes: 2 additions & 1 deletion py-rattler-build/tests/unit/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import rattler_build
from pathlib import Path

import rattler_build


def test_basic() -> None:
parent_cargo_toml = Path(__file__).parent.parent.parent.parent / "Cargo.toml"
Expand Down
14 changes: 8 additions & 6 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ pub async fn run_build(

let directories = output.build_configuration.directories.clone();

let output = output
.fetch_sources(tool_configuration)
.await
.into_diagnostic()?;

let output = output.build_or_fetch_cache(tool_configuration).await?;
let output = if output.recipe.cache.is_some() {
output.build_or_fetch_cache(tool_configuration).await?
} else {
output
.fetch_sources(tool_configuration)
.await
.into_diagnostic()?
};

let output = output
.resolve_dependencies(tool_configuration)
Expand Down
Loading

0 comments on commit d40027b

Please sign in to comment.