Skip to content

Commit a021977

Browse files
Improve bundling libssh2 for mac (#10)
Co-authored-by: Liam Mackie <liam@mackie.sh>
1 parent 338b04c commit a021977

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,27 @@ jobs:
8484
uses: actions/setup-dotnet@v5.2.0
8585
with:
8686
dotnet-version: 9.0.x
87-
- name: Compute version suffix for branch builds
87+
- name: Compute version override for branch builds
8888
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
8989
id: version
9090
run: |
91+
# Latest release tag matching the convention <upstream-version>-octopus.<n> (see README "Releasing")
92+
LATEST=$(git tag --list --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-octopus\.[0-9]+$' | head -n 1)
93+
if [ -z "$LATEST" ]; then
94+
echo "::error::No release tag matching <upstream-version>-octopus.<n> found"
95+
exit 1
96+
fi
9197
# Sanitize branch name: lowercase, replace non-alphanumeric with hyphen, trim to 20 chars
9298
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
9399
SAFE_BRANCH=$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//' | cut -c1-20)
94-
echo "override=${SAFE_BRANCH}.${{ github.run_number }}" >> "$GITHUB_OUTPUT"
100+
# Join with '.' (not '-') so branch/run land as separate prerelease IDs, keeping ordering correct vs the next octopus.<n+1>
101+
echo "override=${LATEST}.${SAFE_BRANCH}.${{ github.run_number }}" >> "$GITHUB_OUTPUT"
95102
- name: Download artifacts
96103
uses: actions/download-artifact@v8.0.1
97104
with:
98105
path: nuget.package/runtimes/
99106
- name: Create package
100-
run: dotnet pack nuget.package ${{ steps.version.outputs.override && format('/p:MinVerDefaultPreReleaseIdentifiers="{0}"', steps.version.outputs.override) || '' }}
107+
run: dotnet pack nuget.package ${{ steps.version.outputs.override && format('/p:MinVerVersionOverride={0}', steps.version.outputs.override) || '' }}
101108
- name: Upload NuGet package
102109
uses: actions/upload-artifact@v7.0.0
103110
with:

build.libgit2.sh

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,51 @@ cp libgit2/build/libgit2-$SHORTSHA.$LIBEXT $PACKAGEPATH/$RID/native
6262
LIBGIT2_PATH="$PACKAGEPATH/$RID/native/libgit2-$SHORTSHA.$LIBEXT"
6363

6464
if [[ $OS == "Darwin" ]]; then
65-
echo "macOS: libssh2 sourced from global installation"
65+
# We don't run Octopus Server on Mac, so we can avoid the restriction of relying on the system crypto libraries
66+
# (Required for FIPS compliance). Instead we just bundle the packages so devs don't need to install them.
67+
NATIVE_DIR="$PACKAGEPATH/$RID/native"
68+
69+
is_homebrew_path() {
70+
case "$1" in
71+
/opt/homebrew/*|/usr/local/Cellar/*) return 0 ;;
72+
*) return 1 ;;
73+
esac
74+
}
75+
76+
# Walk the load commands of $1 and, for each Homebrew-rooted dep, copy it next to libgit2,
77+
# rewrite the load command to @rpath, and recurse so transitive deps (libssl -> libcrypto, etc.) are covered.
78+
bundle_homebrew_deps() {
79+
local DYLIB="$1"
80+
local DEPS
81+
DEPS=$(otool -L "$DYLIB" | tail -n +2 | awk '{print $1}')
82+
local DEP
83+
for DEP in $DEPS; do
84+
if is_homebrew_path "$DEP"; then
85+
local DEP_BASENAME
86+
DEP_BASENAME=$(basename "$DEP")
87+
local DEP_DEST="$NATIVE_DIR/$DEP_BASENAME"
88+
if [[ ! -f "$DEP_DEST" ]]; then
89+
echo "Bundling $DEP_BASENAME from $DEP"
90+
cp "$DEP" "$DEP_DEST"
91+
chmod u+w "$DEP_DEST"
92+
install_name_tool -id "@rpath/$DEP_BASENAME" "$DEP_DEST"
93+
bundle_homebrew_deps "$DEP_DEST"
94+
fi
95+
install_name_tool -change "$DEP" "@rpath/$DEP_BASENAME" "$DYLIB"
96+
fi
97+
done
98+
}
99+
100+
bundle_homebrew_deps "$LIBGIT2_PATH"
101+
102+
for DYLIB in "$NATIVE_DIR"/*.dylib; do
103+
install_name_tool -add_rpath @loader_path "$DYLIB"
104+
done
105+
106+
# Ad-hoc re-sign — install_name_tool invalidates the existing signature, which is fatal on Apple Silicon.
107+
for DYLIB in "$NATIVE_DIR"/*.dylib; do
108+
codesign --force --sign - "$DYLIB"
109+
done
66110
else
67111
# Linux: find libssh2 via ldd
68112
LIBSSH2_PATH=$(ldd "$LIBGIT2_PATH" | grep libssh2 | awk '{print $3}')

0 commit comments

Comments
 (0)