Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
name: Generate Documentation
steps:
- uses: actions/checkout@v4
- name: Download prebuilt ladybug
run: bash scripts/download-liblbug.sh
- name: Generate documentation
run: |
swift package --allow-writing-to-directory ./docs \
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ jobs:
- name: Build (${{ matrix.config }} mode)
run: swift build -c ${{ matrix.config }}
env:
LBUG_USE_PREBUILT: "1"
LBUG_TARGET_DIR: ${{ github.workspace }}/lib
- name: Run tests (${{ matrix.config }} mode)
run: swift test -c ${{ matrix.config }}
env:
LBUG_USE_PREBUILT: "1"
LBUG_TARGET_DIR: ${{ github.workspace }}/lib

ios-simulator-test:
name: Build and Test on iOS Simulator
runs-on: macos-15
# iOS has no prebuilt liblbug yet: build the vendored C++ sources.
env:
LBUG_USE_PREBUILT: "0"
strategy:
matrix:
include:
Expand Down Expand Up @@ -123,9 +124,8 @@ jobs:
swift build -c release
# Copy the built binary to the current directory
cp ./.build/arm64-apple-macosx/release/swift-ladybug-example .
env:
LBUG_USE_PREBUILT: "1"
LBUG_TARGET_DIR: ${{ github.workspace }}/lib
# No LBUG_* env: exercises the zero-config prebuilt default
# (manifest resolves <package>/lib via #filePath).

- name: Run example
working-directory: Example
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ Sources/cxx-ladybug/ladybug/

# Downloaded by scripts/download-liblbug.sh
/lib/
Sources/cxx-ladybug-prebuilt/include/lbug.h
11 changes: 9 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
import PackageDescription
import Foundation

let usePrebuiltLadybug = ProcessInfo.processInfo.environment["LBUG_USE_PREBUILT"] == "1"
let prebuiltLadybugDirectory = ProcessInfo.processInfo.environment["LBUG_TARGET_DIR"] ?? "lib"
// Prebuilt liblbug is the default so that fresh clones and downstream
// packages build without generating the cxx-ladybug source tree.
// Set LBUG_USE_PREBUILT=0 to build from the vendored C++ submodule instead.
let usePrebuiltLadybug = ProcessInfo.processInfo.environment["LBUG_USE_PREBUILT"] != "0"
// Default to <this package>/lib so downstream packages link without extra
// configuration once scripts/download-liblbug.sh has run in this checkout.
// LBUG_TARGET_DIR overrides the lookup (e.g. a shared CI directory).
let packageDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent().path
let prebuiltLadybugDirectory = ProcessInfo.processInfo.environment["LBUG_TARGET_DIR"] ?? "\(packageDirectory)/lib"

let package = Package(
name: "swift-ladybug",
Expand Down
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,51 @@ The CI pipeline tests the package on macOS v15, Ubuntu 24.04, and iOS 18.6 Simul

## Build

### Source build
### Prebuilt library build (default)

When building from a source checkout, initialize only the top-level Ladybug C++
submodule and generate the `cxx-ladybug` SwiftPM target before running
`swift build`:
By default swift-ladybug links against a prebuilt `liblbug` shared library, so
neither fresh clones nor downstream packages need to compile the Ladybug C++
sources. Download the library for your platform, then build normally:

```bash
git clone https://github.com/LadybugDB/swift-ladybug.git
cd swift-ladybug
git submodule update --init Sources/LadybugCpp dataset
git -C Sources/LadybugCpp submodule update --init dataset
python3 scripts/collect-ladybug-src/collect-ladybug-src.py
bash scripts/download-liblbug.sh
swift build
```

If you already cloned the repository without submodules, run this first:
By default the script downloads the shared library release matching
`LBUG_VERSION` (default `0.21.2`) from `LadybugDB/ladybug` into `lib/`, which
the package links automatically. You can set `LBUG_VERSION`, `LBUG_LIB_KIND`,
`LBUG_LINUX_VARIANT`, `LBUG_PRECOMPILED_RUN_ID`, `LBUG_GITHUB_REPOSITORY`, or
`LBUG_TARGET_DIR` to select a specific release, static/shared archive, Linux
variant, workflow artifact, repository, or install directory (`LBUG_TARGET_DIR`
overrides the default `<package>/lib` lookup).

```bash
git submodule update --init Sources/LadybugCpp dataset
git -C Sources/LadybugCpp submodule update --init dataset
```
If you consume swift-ladybug as a package dependency, run the download script
from inside the resolved checkout (e.g.
`.build/checkouts/swift-ladybug/scripts/download-liblbug.sh`, or under Xcode
the `SourcePackages/checkouts` directory in DerivedData) so the library lands
in that checkout's `lib/` directory, then build your project with no extra
configuration.

After the generated target exists, subsequent builds can be run with:
### Source build (opt-in)

```bash
swift build
```

### Prebuilt library build

To skip compiling the Ladybug C++ sources, download a prebuilt `liblbug` archive
and enable prebuilt mode:
To compile the Ladybug C++ sources from scratch instead of using the prebuilt
library, initialize the submodules, generate the `cxx-ladybug` SwiftPM target,
and opt out of prebuilt mode:

```bash
bash scripts/download-liblbug.sh
LBUG_USE_PREBUILT=1 swift build
git clone https://github.com/LadybugDB/swift-ladybug.git
cd swift-ladybug
git submodule update --init Sources/LadybugCpp dataset
git -C Sources/LadybugCpp submodule update --init dataset
python3 scripts/collect-ladybug-src/collect-ladybug-src.py
LBUG_USE_PREBUILT=0 swift build
```

By default the script downloads the latest shared library release from
`LadybugDB/ladybug` into `lib/`. You can set `LBUG_VERSION`, `LBUG_LIB_KIND`,
`LBUG_PRECOMPILED_RUN_ID`, `LBUG_GITHUB_REPOSITORY`, or `LBUG_TARGET_DIR` to
select a specific release, static/shared archive, workflow artifact, repository,
or install directory.
Set `LBUG_USE_PREBUILT=0` whenever building or testing from source (including
`swift test`). Source builds require the submodules and only work from a full
clone, not from a package checkout. iOS device/simulator builds currently use
this path; a prebuilt XCFramework for iOS is planned (see issue #12).

## Tests

Expand Down
Loading
Loading