Last active
May 15, 2024 07:21
-
-
Save mbernson/e830f34d1bcd88b8e7a97d21ca9dce24 to your computer and use it in GitHub Desktop.
Compile libssh2 from source for macOS, creating a universal xcframework that works for Intel (x86_64) and Apple Silicon (arm64)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
set -e | |
# This script compiles libssh2 from source for macOS, creating a universal xcframework that works for Intel (x86_64) and Apple Silicon (arm64). | |
# How to use it: download or clone libssh2. Put this script in the root of the repository and run it. | |
SDK=macosx | |
SDK_VERSION="14.0" | |
# Set up a build directory | |
SOURCE_ROOT="$(pwd)"; | |
BUILD_ROOT="/private/tmp/libssh-macos"; | |
rm -rf $BUILD_ROOT; | |
mkdir -p $BUILD_ROOT; | |
cd $BUILD_ROOT | |
# Generate an Xcode project using cmake | |
cmake -S "$SOURCE_ROOT" -B "$BUILD_ROOT" \ | |
-G Xcode \ | |
-DBUILD_STATIC_LIBS=ON \ | |
-DCMAKE_OSX_SYSROOT=$(xcrun --sdk $SDK --show-sdk-path) \ | |
-DCMAKE_OSX_DEPLOYMENT_TARGET=$SDK_VERSION \ | |
-DBUILD_SHARED_LIBS=OFF \ | |
-DCRYPTO_BACKEND=OpenSSL | |
# Build the static library | |
xcodebuild archive \ | |
-project libssh2.xcodeproj \ | |
-scheme libssh2_static \ | |
-destination "generic/platform=macOS" \ | |
-archivePath "$BUILD_ROOT/libssh2-macOS.xcarchive" \ | |
INSTALL_PATH="/" \ | |
SKIP_INSTALL=NO \ | |
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ | |
ARCHS='$(ARCHS_STANDARD)' | |
# Create the xcframework | |
OUTPUT_FRAMEWORK="libssh2.xcframework" | |
xcodebuild -create-xcframework \ | |
-library "$BUILD_ROOT/libssh2-macOS.xcarchive/Products/libssh2.a" \ | |
-headers "$SOURCE_ROOT/include" \ | |
-output "$OUTPUT_FRAMEWORK" | |
echo "Success! The libssh2 xcframework is located at $OUTPUT_FRAMEWORK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment