Metadata-Version: 2.1
Name: pants_backend_platforms
Version: 0.1.0rc0
Summary: Multi-platform builds for Pants backends: platform targets and a contract for building dependencies per platform.
Keywords: pantsbuild,pants,backend,cross-compilation,platforms
Author-Email: Tom Solberg <me@sbg.dev>
License: MIT License
         
         Copyright (c) 2022 Tom Solberg
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
         
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Build Tools
Project-URL: Repository, https://github.com/tgolsson/pants-backends
Project-URL: Code, https://github.com/tgolsson/pants-backends/tree/main/pants-plugins/platforms
Project-URL: Changelog, https://github.com/tgolsson/pants-backends/tree/main/pants-plugins/platforms/CHANGELOG.md
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# pants-backend-platforms

A [Pants](https://www.pantsbuild.org) backend for building targets for more than one platform.
It has no build rules of its own: language backends (such as pants-backend-cmake) use it to
know which platforms to build and how to ask another backend for a dependency built for the
same platform. The C and C++ toolchain for each platform is in [pants-backend-cc](../cc).

This release targets Pants **2.32.x**. Install it with `pants-backend-platforms==0.1.0rc0` in
`[GLOBAL].plugins` in `pants.toml`, and enable `pants_backend_platforms` in
`[GLOBAL].backend_packages`.

**Status: alpha.**

## Targets

```python
platform(name="linux-x86_64", os="linux", arch="x86_64")
platform(name="windows-x86_64", os="windows", arch="x86_64")
```

- `platform`: `os` (`linux`, `windows`, `macos`) and `arch` (`x86_64`, `aarch64`). Everything
  refers to a platform by its target name, so names are unique.
- The host is the `platform` matching the machine Pants runs on. When several match, choose
  with `[platforms].host`; when none does, there is an implicit `<os>-<arch>` platform.

## Choosing what to build

A target of a backend that supports platforms has a `platforms` field: the platforms it can be
built for, the host alone when unset.

```python
cmake_target(name="app", project=":project", platforms=["linux-x86_64", "windows-x86_64"])
```

`pants package` builds the platforms in that list that are the host or in
`[platforms].enabled`. The host's output keeps its usual path in `dist/`, and every other
platform's goes under `dist/<platform>/`:

```
pants --platforms-enabled="['windows-x86_64']" package ::
```

A target built for a platform has its dependencies built for the same platform, enabled or not.
A dependency whose `platforms` does not list it is an error naming both targets.

Enable extra platforms where the packages are published rather than in `pants.toml`: whatever
packages a target, such as a test's `runtime_package_dependencies` or an `archive`, gets every
enabled platform too.

## For backend authors

- Make the field set a `PlatformBuildFieldSet` member, which brings the `platforms` field, and
  register `UnionRule(PlatformBuildFieldSet, MyFieldSet)`. Its rule takes the field set and a
  `TargetPlatform` and returns a `PlatformBuild`: the files at the paths `pants package` writes
  them to for the host.
- `build_platform_dependencies(PlatformDependenciesRequest(address, targets, platform))` builds
  the members among `targets` for the platform and checks their `platforms`. A tool that runs
  during the build is built with `build_for_platform` for `KnownPlatforms.host`.
- The `package` rule returns `package_for_platforms(PackageForPlatformsRequest(field_set))`.
  Goals that run what they build, such as `run` and `test`, build for the host.
