@@ -62,7 +62,51 @@ cp libgit2/build/libgit2-$SHORTSHA.$LIBEXT $PACKAGEPATH/$RID/native
6262LIBGIT2_PATH=" $PACKAGEPATH /$RID /native/libgit2-$SHORTSHA .$LIBEXT "
6363
6464if [[ $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
66110else
67111 # Linux: find libssh2 via ldd
68112 LIBSSH2_PATH=$( ldd " $LIBGIT2_PATH " | grep libssh2 | awk ' {print $3}' )
0 commit comments