Skip to content
Open
20 changes: 12 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@ jobs:
uses: actions/checkout@v4
with:
path: ios-client
submodules: true

- name: Checkout netbird
uses: actions/checkout@v4
with:
repository: netbirdio/netbird
path: netbird
# - name: Checkout netbird
# uses: actions/checkout@v4
# with:
# repository: netbirdio/netbird
# path: ios-client/libs/netbird

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache-dependency-path: netbird/go.sum
cache-dependency-path: ios-client/libs/netbird/go.sum

- name: Install gomobile
run: go install golang.org/x/mobile/cmd/gomobile@v0.0.0-20251113184115-a159579294ab

- name: Install gomobile-netbird
run: GOPROXY=direct go install github.com/netbirdio/gomobile-tvos-fork/cmd/gomobile-netbird@latest

- name: Add gomobile-tvos-fork to netbird dependencies
working-directory: netbird
working-directory: ios-client/libs/netbird
run: go get github.com/netbirdio/gomobile-tvos-fork@latest

- name: Debug - List files before xcframework build
Expand All @@ -51,7 +55,7 @@ jobs:

- name: Build NetBirdSDK xcframework
working-directory: ios-client
run: ./build-go-lib.sh ../netbird
run: ./build-go-lib.sh both

- name: Debug - List files after xcframework build
working-directory: ios-client
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/netbird"]
path = libs/netbird
url = https://github.com/netbirdio/netbird
155 changes: 139 additions & 16 deletions build-go-lib.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,145 @@
#!/bin/bash
set -e
# Script to build NetBird iOS/tvOS bindings using gomobile
#
# Usage: ./build-go-lib.sh [platform] [version]
#
# Parameters:
# 1. platform (optional): Target platform(s) to build for
# - ios : Build for iOS and iOS Simulator only (uses standard gomobile)
# - tvos : Build for tvOS and tvOS Simulator only (uses gomobile-netbird)
# - both : Build for all platforms (uses gomobile-netbird) [default]
#
# 2. version (optional): Git tag to build
# - If provided, validates the tag exists in the submodule and checks it out
# - If omitted and current commit is exactly tagged, uses that tag
# - Otherwise, uses "dev-<short-hash>" (or "ci-<short-hash>" in GitHub Actions)
# - Leading 'v' is stripped from semver tags (v1.2.3 -> 1.2.3)
#
# Examples:
# ./build-go-lib.sh # Build both platforms using current commit
# ./build-go-lib.sh ios # Build iOS only using current commit
# ./build-go-lib.sh tvos v0.64.1 # Build tvOS only using tag v0.64.1
# ./build-go-lib.sh both v0.64.1 # Build both platforms using tag v0.64.1
#
# Output:
# Creates NetBirdSDK.xcframework in the current directory

rn_app_path=$(pwd)
netbirdPath=$1
if [ -z "${1+x}" ]
then
netbirdPath=${GOPATH}/src/github.com/netbirdio/netbird
fi
set -euo pipefail

version=$2
if [ -z "${2+x}" ]
then
version=development
fi
# Normalize semantic versions to drop a leading 'v' (e.g., v1.2.3 -> 1.2.3).
# Only strips if the string starts with 'v' followed by a digit, so it won't affect
# dev/ci strings or other non-semver values.
normalize_version() {
local ver="$1"
if [[ "$ver" =~ ^v[0-9] ]]; then
ver="${ver#v}"
fi
echo "$ver"
}

cd $netbirdPath
# Checkout a git tag in the specified repository path
# Tries the tag as provided, then with 'v' prefix if needed
checkout_tag() {
local tag="$1"
local repo_path="$2"

gomobile-netbird init
CGO_ENABLED=0 gomobile-netbird bind -target=ios,iossimulator,tvos,tvossimulator -bundleid=io.netbird.framework -ldflags="-X github.com/netbirdio/netbird/version.version=$version" -o $rn_app_path/NetBirdSDK.xcframework $netbirdPath/client/ios/NetBirdSDK
if git -C "$repo_path" rev-parse "refs/tags/$tag" >/dev/null 2>&1; then
git -C "$repo_path" checkout "$tag"
return 0
fi

cd -
# Try with 'v' prefix if not provided
if [[ ! "$tag" =~ ^v ]] && git -C "$repo_path" rev-parse "refs/tags/v$tag" >/dev/null 2>&1; then
git -C "$repo_path" checkout "v$tag"
return 0
fi

echo "Error: Tag '$tag' does not exist" >&2
exit 1
}

# Get version string, optionally checking out a tag if provided
get_version() {
local version_arg="${1:-}"
local repo_path="$2"

if [ -n "$version_arg" ]; then
# Version provided - validate and checkout the tag
checkout_tag "$version_arg" "$repo_path"
normalize_version "$version_arg"
return
fi

# No version provided - try to get an exact tag for current commit
local tag
tag=$(git -C "$repo_path" describe --tags --exact-match 2>/dev/null || true)

if [ -n "$tag" ]; then
normalize_version "$tag"
return
fi

# Fallback to dev/ci prefix with short hash
local short_hash
short_hash=$(git -C "$repo_path" rev-parse --short HEAD)

if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
echo "ci-$short_hash"
else
echo "dev-$short_hash"
fi
}

project_root=$(pwd)
netbirdPath=$project_root/libs/netbird

# Parse arguments
platform="${1:-both}"
version_arg="${2:-}"

# Validate platform argument
case "$platform" in
ios|tvos|both)
;;
*)
echo "Error: Invalid platform '$platform'. Must be 'ios', 'tvos', or 'both'." >&2
exit 1
;;
esac
Comment on lines +96 to +108
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Find all invocations of build-go-lib.sh
rg 'build-go-lib\.sh' -n --max-count=20

Repository: netbirdio/ios-client

Length of output: 546


🏁 Script executed:

# Check GitHub Actions workflows
fd -type f \( -name '*.yml' -o -name '*.yaml' \) .github/workflows/ 2>/dev/null | xargs cat 2>/dev/null || echo "No workflows found"

Repository: netbirdio/ios-client

Length of output: 46


🏁 Script executed:

# Get the full build-go-lib.sh file to see the complete interface
fd 'build-go-lib\.sh' -type f

Repository: netbirdio/ios-client

Length of output: 234


🏁 Script executed:

# View the README around line 91 to see the old usage
sed -n '85,95p' README.md

Repository: netbirdio/ios-client

Length of output: 296


🏁 Script executed:

# Search for GitHub Actions workflows more carefully
find .github -name "*.yml" -o -name "*.yaml" 2>/dev/null | head -20

Repository: netbirdio/ios-client

Length of output: 118


🏁 Script executed:

# Also search for any references to build-go-lib in yaml/yml files
rg 'build-go-lib' -A 5 -B 5

Repository: netbirdio/ios-client

Length of output: 1722


🏁 Script executed:

# Check the actual workflow files to see how they invoke the script
cat .github/workflows/build.yml
cat .github/workflows/test.yml

Repository: netbirdio/ios-client

Length of output: 9789


Update script invocations and documentation for new API signature.

The new script signature ./build-go-lib.sh [platform] [version] is a breaking change from the old ./build-go-lib.sh <path> interface. Both GitHub Actions workflows (.github/workflows/build.yml and .github/workflows/test.yml) and the README.md still use the old invocation pattern ./build-go-lib.sh ../netbird, which will fail validation in the platform check (lines 100-106) since ../netbird does not match the valid platforms (ios, tvos, both).

Update:

  1. Both workflows to call: ./build-go-lib.sh both (or specific platform)
  2. README.md line 91 to show the new usage pattern
🤖 Prompt for AI Agents
In `@build-go-lib.sh` around lines 96 - 108, The workflows and README still call
the old script signature and must be updated to the new one: change invocations
that pass a path (e.g. "./build-go-lib.sh ../netbird") to pass a platform
argument ("both" or "ios" or "tvos") per the new validation around the platform
variable and the case statement that only accepts ios|tvos|both; update
.github/workflows/build.yml and .github/workflows/test.yml to call
"./build-go-lib.sh both" (or a specific platform as appropriate) and update
README.md (around the previous usage example at line ~91) to show the new usage
"./build-go-lib.sh [platform] [version]".


# Get version (this also checks out the tag if provided)
version=$(get_version "$version_arg" "$netbirdPath")

cd "$netbirdPath"

echo "Using version: $version"
echo "Building for platform: $platform"

# Set targets and gomobile command based on platform
case "$platform" in
ios)
targets="ios,iossimulator"
gomobile_cmd="gomobile"
;;
tvos)
targets="tvos,tvossimulator"
gomobile_cmd="gomobile-netbird"
;;
both)
targets="ios,iossimulator,tvos,tvossimulator"
gomobile_cmd="gomobile-netbird"
;;
esac

# Initialize gomobile
$gomobile_cmd init

# Build
$gomobile_cmd bind \
-target="$targets" \
-bundleid=io.netbird.framework \
-ldflags="-X github.com/netbirdio/netbird/version.version=$version" \
-o "$project_root/NetBirdSDK.xcframework" \
"$netbirdPath/client/ios/NetBirdSDK"

cd - > /dev/null
1 change: 1 addition & 0 deletions libs/netbird
Submodule netbird added at 5333e5