Skip to content

add musl target to kos-go#212

Merged
fsiggor merged 16 commits into
developfrom
fix/cgo-vendor
Sep 23, 2025
Merged

add musl target to kos-go#212
fsiggor merged 16 commits into
developfrom
fix/cgo-vendor

Conversation

@klever-patrick

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

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added Linux-musl build and test support for Go bindings.
    • Updated platform library resolution to use relative paths for reliability.
  • Build

    • Simplified build steps; removed aggregate build/test targets in favor of explicit musl targets.
    • Improved linker/runtime path handling for platform-specific libraries.
  • Tests

    • Automated per-platform tests for Linux (glibc and musl) and macOS.
  • Chores

    • Introduced CI workflow to build, test, and update platform libraries.
    • Updated ignore rules for vendor, bin, test outputs, coverage, and IDE files.
    • Adjusted PR workflow path filters.

@coderabbitai

coderabbitai Bot commented Sep 23, 2025

Copy link
Copy Markdown

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • packages/kos-go/kos_mobile/lib/linux-musl-amd64/libkos_mobile.so is excluded by !**/*.so

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

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 "add musl target to kos-go" is concise and accurately summarizes the main change — adding musl build/test support for the kos-go package — and aligns with the Makefile, cgo, and CI modifications in the diff.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

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.

@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: 7

🧹 Nitpick comments (3)
.github/workflows/kos-go.yaml (2)

44-49: Broaden commit pattern to include regenerated bindings

If uniffi regenerates Go sources or headers, they won’t be committed with a single-file pattern.

Apply this diff:

-          file_pattern: "packages/kos-go/kos_mobile/lib/linux-amd64/libkos_mobile.so"
+          file_pattern: |
+            packages/kos-go/kos_mobile/lib/linux-amd64/libkos_mobile.so
+            packages/kos-go/**/*.go
+            packages/kos-go/kos_mobile/*.h

Repeat similarly for macOS/musl jobs if desired.


1-1: Avoid push conflicts from parallel auto-commits

Add concurrency to serialize runs on a ref, or commit only in one job after aggregating artifacts.

Add this at the top-level of the workflow:

concurrency:
  group: kos-go-${{ github.ref }}
  cancel-in-progress: false
Makefile (1)

46-49: Make uniffi-bindgen-go install idempotent; crate-type for musl verified

  • Avoid reinstalling uniffi-bindgen-go on every build — move install to CI setup or make it idempotent (use cargo install -q --locked ... || true in build-go and build-go-musl).
  • Verified packages/kos-mobile/Cargo.toml:12 contains crate-type = ["cdylib", "staticlib", "rlib"] — both staticlib and cdylib present.
📜 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 8e95eff and 1462871.

⛔ Files ignored due to path filters (2)
  • packages/kos-go/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)
  • .github/workflows/kos-go.yaml (1 hunks)
  • .github/workflows/pull-develop.yaml (1 hunks)
  • Makefile (1 hunks)
  • packages/kos-go/.gitignore (1 hunks)
  • packages/kos-go/kos_mobile/.gitignore (1 hunks)
  • packages/kos-go/kos_mobile/cgo.go (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/kos-go.yaml

9-9: both "paths" and "paths-ignore" filters cannot be used for the same event "push". note: use '!' to negate patterns

(events)


22-22: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


27-27: the runner of "actions/setup-go@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


59-59: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


64-64: the runner of "actions/setup-go@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


98-98: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


103-103: the runner of "actions/setup-go@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: format
🔇 Additional comments (3)
packages/kos-go/kos_mobile/.gitignore (1)

1-16: LGTM – sensible ignores for tests/coverage/workspace/IDE

.github/workflows/pull-develop.yaml (1)

20-20: LGTM, but confirm intent to not trigger checks on lib updates

Ignoring packages/kos-go/kos_mobile/lib/** will prevent PR checks when only the prebuilt libs change (your new workflow will commit them). Confirm this is desired.

packages/kos-go/.gitignore (1)

1-1: Change packages/kos-go/.gitignore to use vendor/ and verify vendor-mode usage

Replace vendor with vendor/ in packages/kos-go/.gitignore and confirm no build/test/CI tooling relies on Go's vendor mode (-mod=vendor).

-vendor
+vendor/

Run to verify vendor usage:

rg -nP --type=go -C2 '(-mod=vendor|go\s+mod\s+vendor|GOMODCACHE=vendor|go\s+build\s+-mod=vendor|go\s+test\s+-mod=vendor)'

Comment thread .github/workflows/kos-go.yaml
Comment thread .github/workflows/kos-go.yaml Outdated
Comment thread .github/workflows/kos-go.yaml Outdated
Comment thread .github/workflows/kos-go.yaml
Comment thread .github/workflows/kos-go.yaml Outdated
Comment thread .github/workflows/kos-go.yaml Outdated
Comment thread packages/kos-go/kos_mobile/cgo.go

@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: 2

🧹 Nitpick comments (2)
.github/workflows/kos-go.yaml (2)

26-30: Enable Go module caching for faster CI

actions/setup-go supports caching.

Apply:

       - name: Setup Go
-        uses: actions/setup-go@v4
+        uses: actions/setup-go@v5
         with:
           go-version: '1.21'
+          cache: true

Repeat at the other Setup Go steps.

Also applies to: 63-67, 102-106


1-16: Overall: solid structure and platform coverage

Matrix could reduce duplication later; current explicit jobs are fine for now.

📜 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 1462871 and b56bde0.

📒 Files selected for processing (1)
  • .github/workflows/kos-go.yaml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/kos-go.yaml

9-9: both "paths" and "paths-ignore" filters cannot be used for the same event "push". note: use '!' to negate patterns

(events)


22-22: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


27-27: the runner of "actions/setup-go@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


59-59: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


64-64: the runner of "actions/setup-go@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


98-98: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


103-103: the runner of "actions/setup-go@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (7)
.github/workflows/kos-go.yaml (7)

120-124: Verify darwin folder naming

Consumer conventions often use darwin-arm64; you’re using darwin-aarch64. Confirm downstream expectations.

Would you like me to search the repo for imports/CGO flags expecting this exact path?


4-13: Fix event filters: cannot combine paths and paths-ignore on push

Use only paths; convert exclusions to negations.

Apply:

 on:
   push:
-    paths:
-      - 'packages/kos-go/kos_mobile/**'
     branches:
       - develop
-    paths-ignore:
-      - '**/*.md'
-      - '.gitignore'
-      - '.github/**'
+    paths:
+      - 'packages/kos-go/kos_mobile/**'
+      - '!**/*.md'
+      - '!.gitignore'
+      - '!.github/**'
   pull_request:
     branches:
       - develop

22-29: Upgrade core actions: checkout→v4, setup-go→v5

Older versions are deprecated on GH Actions runners.

Apply:

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
@@
-        uses: actions/setup-go@v4
+        uses: actions/setup-go@v5

Repeat the same replacements at Lines 59 and 64, and Lines 98 and 103.

Also applies to: 59-66, 98-105


74-76: Invalid multi-line run syntax

Use a block scalar for multi-line commands.

Apply:

-      - name: Build Linux Go bindings
-        run: 
-          rustup target add x86_64-unknown-linux-musl && make build-go-musl
+      - name: Build Linux Go bindings
+        run: |
+          rustup target add x86_64-unknown-linux-musl
+          make build-go-musl

79-81: Fix musl artifact dir name

Create linux-musl-amd64 (not linux-amd64) to match cp target.

Apply:

-          mkdir -p packages/kos-go/kos_mobile/lib/linux-amd64
+          mkdir -p packages/kos-go/kos_mobile/lib/linux-musl-amd64
           cp target/x86_64-unknown-linux-musl/release/libkos_mobile.so packages/kos-go/kos_mobile/lib/linux-musl-amd64/

85-86: Correct file_pattern path for musl commit

Use dashed folder, not slash.

Apply:

-          file_pattern: "packages/kos-go/kos_mobile/lib/linux-musl/amd64/libkos_mobile.so"
+          file_pattern: "packages/kos-go/kos_mobile/lib/linux-musl-amd64/libkos_mobile.so"

88-92: Run tests with musl build tag

Ensure musl-specific cgo flags are used.

Apply:

       - name: Run Go tests
         run: |
           cd packages/kos-go
-          make test
+          GOFLAGS="-tags=musl" make test

Comment thread .github/workflows/kos-go.yaml
Comment thread .github/workflows/kos-go.yaml

@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

🧹 Nitpick comments (1)
packages/kos-go/Makefile (1)

151-151: Help text consistency (mention arch or align with directory naming).

Minor nit: other entries include arch. Consider aligning wording to match directory naming.

-	@echo "  build-linux-musl    - Build for Linux with musl"
+	@echo "  build-linux-musl    - Build for Linux musl AMD64"
@@
-	@echo "  test-linux-musl     - Test Linux with musl"
+	@echo "  test-linux-musl     - Test Linux musl AMD64"

Also applies to: 155-155

📜 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 b56bde0 and 07c11ea.

📒 Files selected for processing (3)
  • packages/kos-go/.gitignore (1 hunks)
  • packages/kos-go/Makefile (2 hunks)
  • packages/kos-go/kos_mobile/cgo.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/kos-go/kos_mobile/cgo.go
  • packages/kos-go/.gitignore
🔇 Additional comments (1)
packages/kos-go/Makefile (1)

107-116: Use a musl-targeting CC, point LD_LIBRARY_PATH at the musl lib, and pass -tags=musl on go build (don’t use GOFLAGS)

Linking a musl-built staticlib with glibc’s cc is error-prone — set CC to a musl-targeting compiler (e.g., x86_64-linux-musl-gcc or zig cc -target x86_64-linux-musl), update LD_LIBRARY_PATH to the musl lib dir, and pass tags directly to go build.

File: packages/kos-go/Makefile (lines ~107-116)

 .PHONY: build-linux-musl
 build-linux-musl:
-	LD_LIBRARY_PATH=$(PWD)/kos_mobile/lib/linux-amd64 \
-	CGO_ENABLED=1 \
-	CGO_LDFLAGS="-lm" \
-	GOOS=linux \
-	GOARCH=amd64 \
-	GOFLAGS="-tags=musl" \
-	go build $(BUILD_FLAGS) -o bin/kos-linux-musl ./...
+	LD_LIBRARY_PATH=$(PWD)/kos_mobile/lib/linux-musl-amd64 \
+	CGO_ENABLED=1 \
+	CC=x86_64-linux-musl-gcc \
+	CGO_LDFLAGS="-lm" \
+	GOOS=linux \
+	GOARCH=amd64 \
+	go build -tags=musl $(BUILD_FLAGS) -o bin/kos-linux-musl ./...

Confirm kos_mobile/lib/linux-musl-amd64 exists and CI/tooling provides a musl cc (or use zig cc) before merging.

Comment thread packages/kos-go/Makefile
fsiggor
fsiggor previously approved these changes Sep 23, 2025

@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

🧹 Nitpick comments (6)
.github/actions/rustup/action.yaml (1)

92-92: Trim install footprint; consider making musl-tools opt-in

  • Add --no-install-recommends to reduce packages/time (already in the diff above).
  • Optional: add a follow-up cleanup to free apt lists if you hit disk limits:
    sudo rm -rf /var/lib/apt/lists/*
  • Consider an input (e.g., inputs.install_musl: boolean) to install musl-tools only when needed; or move musl setup to the kos-go workflow to keep this “WasmPack toolchain” action focused.

If you want, I can draft the input/plumbing changes to gate musl-tools installation.

.github/workflows/kos-go.yaml (5)

24-28: Drive Go version from go.mod and enable caching

Reduces drift and speeds builds.

       - name: Setup Go
         uses: actions/setup-go@v5
         with:
-          go-version: '1.21'
+          go-version-file: packages/kos-go/go.mod
+          cache: true

64-68: Apply same go.mod-driven version and cache here

       - name: Setup Go
         uses: actions/setup-go@v5
         with:
-          go-version: '1.21'
+          go-version-file: packages/kos-go/go.mod
+          cache: true

106-110: Apply same go.mod-driven version and cache here

       - name: Setup Go
         uses: actions/setup-go@v5
         with:
-          go-version: '1.21'
+          go-version-file: packages/kos-go/go.mod
+          cache: true

3-11: Optional: Add PR path filters to reduce unnecessary runs

Mirror the push paths under pull_request to only run when kos-go assets change.

   pull_request:
     branches:
       - develop
+    paths:
+      - 'packages/kos-go/kos_mobile/**'

13-18: Optional: Avoid concurrent auto-commits across jobs

Multiple jobs committing to the same ref can race. Use workflow concurrency to cancel in-flight runs on the same branch.

Add at top-level:

concurrency:
  group: kos-go-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
📜 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 6c13db2 and 01891de.

⛔ Files ignored due to path filters (2)
  • packages/kos-go/kos_mobile/lib/darwin-aarch64/libkos_mobile.dylib is excluded by !**/*.dylib
  • packages/kos-go/kos_mobile/lib/linux-amd64/libkos_mobile.so is excluded by !**/*.so
📒 Files selected for processing (2)
  • .github/actions/rustup/action.yaml (1 hunks)
  • .github/workflows/kos-go.yaml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build-go-linux
  • GitHub Check: build-go-linux-musl
  • GitHub Check: build-go-mac
  • GitHub Check: format
🔇 Additional comments (6)
.github/actions/rustup/action.yaml (1)

90-92: Guard apt-get to Linux runners

Gate the protobuf setup step to Linux to avoid breaking macOS/Windows runners; use --no-install-recommends.

-    - name: Setup protobuf
-      shell: bash
-      run: sudo apt-get update && sudo apt-get -y install protobuf-compiler musl-tools
+    - name: Setup protobuf
+      if: runner.os == 'Linux'
+      shell: bash
+      run: sudo apt-get update && sudo apt-get install -y --no-install-recommends protobuf-compiler musl-tools

Verify no workflows call .github/actions/rustup on non-Linux runners.

.github/workflows/kos-go.yaml (5)

42-48: Auto-commit guard runs on PRs and can loop CI; restrict to push and add [skip ci]

Current condition executes on pull_request and on push without “[skip ci]”, causing PR failures and retrigger loops. Limit to push and include “[skip ci]” in the commit message.

-      - name: Commit and push changes
-        if: github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]')
+      - name: Commit and push changes
+        if: github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip ci]')
         uses: stefanzweifel/git-auto-commit-action@v4
         with:
-          commit_message: "Update Linux Go bindings library"
+          commit_message: "[skip ci] Update Linux Go bindings library"
           file_pattern: "packages/kos-go/kos_mobile/lib/linux-amd64/libkos_mobile.so"

79-83: mkdir targets wrong directory for musl; cp may fail

You create linux-amd64 but copy into linux-musl-amd64. Create the correct directory.

       - name: Copy .so to Go package
         run: |
-          mkdir -p packages/kos-go/kos_mobile/lib/linux-amd64
+          mkdir -p packages/kos-go/kos_mobile/lib/linux-musl-amd64
           cp target/x86_64-unknown-linux-musl/release/libkos_mobile.so packages/kos-go/kos_mobile/lib/linux-musl-amd64/

84-90: Same auto-commit guard issue on musl job; fix and add “[skip ci]”

       - name: Commit and push changes
-        if: github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]')
+        if: github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip ci]')
         uses: stefanzweifel/git-auto-commit-action@v4
         with:
-          commit_message: "Update Linux musl Go bindings library"
+          commit_message: "[skip ci] Update Linux musl Go bindings library"
           file_pattern: "packages/kos-go/kos_mobile/lib/linux-musl-amd64/libkos_mobile.so"

129-135: Same auto-commit guard issue on mac job; fix and add “[skip ci]”

       - name: Commit and push changes
-        if: github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]')
+        if: github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip ci]')
         uses: stefanzweifel/git-auto-commit-action@v4
         with:
-          commit_message: "Update macOS Go bindings library"
+          commit_message: "[skip ci] Update macOS Go bindings library"
           file_pattern: "packages/kos-go/kos_mobile/lib/darwin-aarch64/libkos_mobile.dylib"

111-117: Install rustup on macOS runner before calling rustup component add

The workflow (.github/workflows/kos-go.yaml lines 111–117) assumes rustup is present; add an install fallback (run the rustup-init installer or use a GitHub Action to set up Rust) before rustup component add --toolchain stable rustfmt clippy.

Comment thread .github/workflows/kos-go.yaml
@fsiggor fsiggor merged commit 7753465 into develop Sep 23, 2025
7 checks passed
@fsiggor fsiggor deleted the fix/cgo-vendor branch September 23, 2025 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants