An open API service indexing awesome lists of open source software.

https://github.com/coldgrub1384/multibuild

Swift utilities for cross compiling and packaging libraries
https://github.com/coldgrub1384/multibuild

cmake cross-compilation make python swift

Last synced: about 2 months ago
JSON representation

Swift utilities for cross compiling and packaging libraries

Awesome Lists containing this project

README

          

# multibuild

A Swift build system for projects compiling to multiple architectures and sdks.
This library provides types that define projects, configurations and also a command line interface to trigger builds.

After compiling `multibuild` generates Python Wheels, Xcode frameworks and Swift Packages to be used on Apple platforms (non Apple platforms don't support `binaryTarget` and `xcframework`s, so we'll have to use an alternate package manager).

(only supports Apple platforms for the moment and not all because that's what I'm testing against currently but I plan to add support for at least Linux / Android)

See the [documentation](https://git.gatit.es/emma/cosas/documentaciones/multibuild) for API usage information.

## Why did I do that?

I didn't know there was already a [`multibuild`](https://github.com/multi-build/multibuild) when I started this and it is also related to Python. So I may end up renaming it some time.

This is part of my effort to automatize dependency management for my app [Pyto](https://pyto.app) (a Python IDE) while making it multi platform. Precompiled binaries can be found in [this package registry](https://git.gatit.es/pyto/pyto-runtime/packages). I have been spending more than half a year in this task while not working almost anything in the app itself but I added `Mac Catalyst` support and will be supporting other platforms. The idea is to have the same coding environment accross platforms so I'm starting with all Apple platforms. `visionOS` and `macOS` (native) are not yet supported because I'll start by having the app on `Mac Catalyst`, `watchOS` and `tvOS`.

## Installation

To use this library, create an executable Swift Package target and add `multibuild` as a dependency.

```swift
let package = Package(
name: "build-libraries",
dependencies: [
.package(url: "pi@git.gatit.es:emma/multibuild.git", from: "2.0.0")
],
targets: [
.executableTarget(
name: "build-libraries",
dependencies: [
.product(name: "Multibuild", package: "multibuild")
]),
]
)
```

## Usage

`multibuild` provides types for for constructing projects that work with Autoconf, CMake and other build systems.
The protocol `BuildPlan` provides an entry point for a command line program.

```swift
import Multibuild

@main
struct Plan: BuildPlan {
var platform: Platform = .apple // .iOS + .macCatalyst + ...
var bundleIdentifierPrefix = "com.myapp"

var project: Project {
Project(
directoryURL: rootURL.appendingPathComponent("openssl"),
version: .git("openssl-3.0.16"),
builder: Autoconf(products: [
.dynamicLibrary(staticArchives: [
"libssl.a", "libcrypto.a"
], includePath: "include")
], configureArguments: { _ in
["-static", ] // ...
}, additionalCompilerFlags: { _ in
["-DHAVE_FORK=0"]
}))
// ...
}
}
```

On Apple platforms, this will create a framework called `openssl` (project name) from static archives `libssl.a` and `libcrypto.a`, an universal Xcode framework and a Swift Package archive (contains all the frameworks from a project).

## Directory structure

Build products will be located under a `build` directory inside the compiled project.
Inside the build directory, each folder is named `sdkname.arch1`. For example, `iphoneos.arm64`. These name correspond to targets you can pass to the cli program.
Xcode frameworks are also created under an `apple.universal` directory.

## CLI usage

```
OVERVIEW: Command line interface for building your projects.

USAGE: build-command [--root ] [--list-targets] [--list-projects] [--no-compile] [--no-upload] [--no-package] [--force-configure] [--target ...] [--project ...]

OPTIONS:
--root Common root directory of projects. (defaults to working directory)
--list-targets List supported compilation targets and exit.
--list-projects List declared projects and exit.
--no-compile Skip recompilation and only perform packaging operations.
--no-upload Skip uploading generated packages.
--no-package Skip generation of Xcode Frameworks and Swift Packages.
-f, --force-configure Force regenerating Makefiles and other configurations.
-t, --target Specify a target to build
-p, --project Specify a project to build
-h, --help Show help information.
```