Skip to content

Add musl static lib#214

Merged
klever-patrick merged 4 commits into
developfrom
add-static-lib
Sep 24, 2025
Merged

Add musl static lib#214
klever-patrick merged 4 commits into
developfrom
add-static-lib

Conversation

@klever-patrick

@klever-patrick klever-patrick commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added support for x86_64 Linux MUSL builds, enabling broader deployment environments.
  • Improvements

    • Introduced a size-optimized build profile to produce smaller binaries.
    • Reduced default feature usage in dependencies to further minimize binary size.
  • Chores

    • Simplified CI by removing automated Go binding build-and-commit steps; tests still run.
    • Updated the Go demo to Go 1.24.x and refreshed the kos-go dependency version.

@coderabbitai

coderabbitai Bot commented Sep 24, 2025

Copy link
Copy Markdown

Walkthrough

Adds a size-optimized Cargo profile, introduces a musl target with static CRT feature, updates Makefile to build kos-mobile with the new profile for musl, simplifies CI by removing Go binding build/commit steps, adjusts Go demo toolchain and dependency, and disables default features and pins versions in kos-mobile dependencies.

Changes

Cohort / File(s) Summary
Build profiles and targets
Cargo.toml, .cargo/config.toml
Adds a min-size Cargo profile (opt-level "s", strip, panic=abort, codegen-units=1, etc.). Consolidates Apple target rustflags formatting. Adds x86_64-unknown-linux-musl target with musl linker and +crt-static via rustflags.
Makefile musl build update
Makefile
Changes build-go-musl to use --profile min-size for kos-mobile targeting musl; updates uniffi-bindgen-go to point to target/x86_64-unknown-linux-musl/min-size/libkos_mobile.a.
CI workflow simplification
.github/workflows/kos-go.yaml
Removes Go bindings build/copy/commit steps for Linux, Linux musl, and macOS jobs; retains only Go test steps.
Go demo module adjustments
packages/kos-go/demo/go.mod
Downgrades Go toolchain to 1.24.7; updates github.com/klever-io/kos-rs/packages/kos-go to v0.2.35.
kos-mobile dependency flags and versions
packages/kos-mobile/Cargo.toml
Sets default-features = false for several deps (kos, kos-codec, num-bigint, num-traits, anyhow, bigdecimal) and pins explicit versions.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant Make as Makefile
  participant Cargo as Cargo (Rust)
  participant UFG as uniffi-bindgen-go
  participant Out as packages/kos-go

  Dev->>Make: make build-go-musl
  Make->>Cargo: cargo build --profile min-size --target x86_64-unknown-linux-musl -p kos-mobile
  Note right of Cargo: Produces libkos_mobile.a<br/>in .../min-size/
  Cargo-->>Make: artifact path
  Make->>UFG: generate using lib.../min-size/libkos_mobile.a
  UFG-->>Out: Go bindings in ./packages/kos-go
Loading
sequenceDiagram
  autonumber
  participant GH as GitHub Actions
  participant Job as kos-go workflow
  participant Go as Go toolchain

  GH->>Job: Start Linux/macOS jobs
  Job->>Go: Run Go tests
  Note over Job,Go: Binding build/copy/commit steps removed
  Go-->>Job: Test results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I nibbled flags till they were neat and small,
Musl munchies served in a min-size shawl.
CI’s burrow is lighter—hops, not hauls,
Go tests thump on, no binding stalls.
With trimmed crates and tidy trails,
This rabbit ships lean, and swiftly sails. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the core change of adding a MUSL static library target, matching the primary updates to the Cargo configuration, build scripts, and linker settings in this pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-static-lib

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Comment @coderabbitai help to get the list of available commands and usage tips.

@klever-patrick klever-patrick marked this pull request as ready for review September 24, 2025 18:57
@klever-patrick klever-patrick merged commit 9b267bb into develop Sep 24, 2025
7 of 8 checks passed
@klever-patrick klever-patrick deleted the add-static-lib branch September 24, 2025 18:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.cargo/config.toml (1)

16-19: Ensure MUSL linker is available in CI and dev images

.cargo/config.toml (lines 16–19) specifies x86_64-linux-musl-gcc as the linker, but that binary isn’t present; update your CI/dev images to install a musl cross-compiler package (e.g. musl-cross or musl-dev) or add a symlink from musl-gcc to x86_64-linux-musl-gcc.

🧹 Nitpick comments (3)
packages/kos-mobile/Cargo.toml (2)

30-31: Pin + default-features=false may break std usage; explicitly enable std features.

anyhow and bigdecimal default to std; disabling default features without enabling std/alloc can cause build/link issues. Suggest enabling std explicitly to keep behavior predictable.

Apply this diff:

- num-bigint = { version = "0.4", default-features = false }
- num-traits = { version = "0.2", default-features = false }
+ num-bigint = { version = "0.4", default-features = false, features = ["std"] }
+ num-traits = { version = "0.2", default-features = false, features = ["std"] }

- anyhow = { version = "1.0.96", default-features = false }
+ anyhow = { version = "1.0.96", default-features = false, features = ["std"] }

- bigdecimal = { version = "0.4.7", default-features = false }
+ bigdecimal = { version = "0.4.7", default-features = false, features = ["std"] }

If you intentionally target no_std, enable alloc appropriately and confirm downstream usage.

Also applies to: 35-35, 37-37


22-23: Centralize version pins in [workspace.dependencies] for consistency.

Move these version specs to the root workspace to avoid duplicate versions and make upgrades easier.

Also applies to: 30-31, 35-35, 37-37

Cargo.toml (1)

32-42: Min-size profile: consider thin LTO and validate size trade-offs.

  • lto=false can increase size for staticlibs; thin LTO often reduces size with modest compile-time cost.
  • opt-level="z" can be smaller than "s" for many crates; measure both.
  • overflow-checks=false and panic=abort are fine for FFI, but confirm this matches safety expectations.

If size is critical, build two variants and compare artifacts to confirm the best combo: LTO thin vs off, opt-level z vs s.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7753465 and 45bf575.

⛔ Files ignored due to path filters (2)
  • packages/kos-go/demo/go.sum is excluded by !**/*.sum
  • packages/kos-go/kos_mobile/lib/linux-musl-amd64/libkos_mobile.so is excluded by !**/*.so
📒 Files selected for processing (6)
  • .cargo/config.toml (1 hunks)
  • .github/workflows/kos-go.yaml (0 hunks)
  • Cargo.toml (1 hunks)
  • Makefile (1 hunks)
  • packages/kos-go/demo/go.mod (1 hunks)
  • packages/kos-mobile/Cargo.toml (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/kos-go.yaml
🔇 Additional comments (4)
packages/kos-mobile/Cargo.toml (1)

22-23: Disabling default features on core crates: verify no required features are lost.

Turning off default-features for kos and kos-codec can drop std/feature-gated code unexpectedly. Ensure all required features are explicitly enabled here or via workspace features.

.cargo/config.toml (1)

2-15: Apple rustflags consolidation looks good.

packages/kos-go/demo/go.mod (2)

5-5: Verified submodule tag packages/kos-go/v0.2.35 exists; version will resolve correctly.


3-3: Go 1.24.7 is a valid release—ensure CI and local setups use it
Go 1.24.7 is officially available. Confirm your CI pipelines and developer machines are configured to use Go 1.24.7 to avoid build failures.

Comment thread Makefile
Comment on lines +52 to +54
# cargo build --release --target x86_64-unknown-linux-musl --package kos-mobile && \
cargo build --profile min-size --target x86_64-unknown-linux-musl --package kos-mobile && \
uniffi-bindgen-go --library target/x86_64-unknown-linux-musl/min-size/libkos_mobile.a --out-dir ./packages/kos-go

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

Go/musl build: verify toolchain + uniffi version compatibility.

  • Ensure musl GCC is present; otherwise this target fails.
  • uniffi-bindgen-go tag v0.4.0+v0.28.3 should match workspace uniffi (0.28.1). Minor mismatches can break codegen; confirm compatibility.

If mismatched, align uniffi crate and bindgen versions to the same 0.28.x patch.


🏁 Script executed:

#!/bin/bash
# Check musl toolchain
command -v x86_64-linux-musl-gcc || echo "Missing: x86_64-linux-musl-gcc"

# Confirm uniffi version alignment
rg -nP '^\s*uniffi\s*=\s*\{[^}]*version\s*=\s*"([^"]+)"' Cargo.toml -n -C0
echo "Using uniffi-bindgen-go tag: v0.4.0+v0.28.3"

Length of output: 109


Install musl GCC and align uniffi versions

  • Install x86_64-linux-musl-gcc (musl-GCC) so the x86_64-unknown-linux-musl build target in the Makefile succeeds.
  • Sync the uniffi crate version (0.28.1) with the uniffi-bindgen-go tag (v0.4.0+v0.28.3): either bump the crate to 0.28.3 or pin bindgen to 0.28.1 to avoid codegen breaks.
🤖 Prompt for AI Agents
In Makefile around lines 52 to 54, the musl cross-compiler and uniffi version
mismatch cause the x86_64-unknown-linux-musl build and uniffi codegen to fail;
install the musl GCC toolchain (package providing x86_64-linux-musl-gcc) on
CI/dev machines and document it in the Makefile/README so the cargo target
builds succeed, and resolve the uniffi version skew by either bumping the uniffi
crate to 0.28.3 to match bindgen (v0.4.0+v0.28.3) or pin the uniffi-bindgen-go
tool to the older 0.28.1-compatible tag; update Cargo.toml or the tool
installation step in the repo accordingly and ensure the Makefile/build scripts
reference the chosen, consistent versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants