-
Notifications
You must be signed in to change notification settings - Fork 138
Add universal build for macos (needed for obs-studio) #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,29 +43,70 @@ while [[ $# -gt 0 ]]; do | |
| esac | ||
| done | ||
|
|
||
| # Detect target if not specified | ||
| if [[ -z "$TARGET" ]]; then | ||
| TARGET=$(rustc -vV | grep host | cut -d' ' -f2) | ||
| echo "Detected target: $TARGET" | ||
| fi | ||
|
|
||
| # Get version from Cargo.toml if not specified | ||
| if [[ -z "$VERSION" ]]; then | ||
| VERSION=$(grep '^version' "$SCRIPT_DIR/Cargo.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/') | ||
| echo "Detected version: $VERSION" | ||
| fi | ||
|
|
||
| echo "Building libmoq for $TARGET..." | ||
| if [[ "$TARGET" == "universal-apple-darwin" ]]; then | ||
| if [[ "$(uname)" != "Darwin" ]]; then | ||
| echo "Error: Universal builds are only supported on macOS" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Building libmoq for $TARGET..." | ||
|
|
||
| # Build x86_64 | ||
| echo "Building for x86_64-apple-darwin..." | ||
| cargo build --release --package libmoq --target x86_64-apple-darwin --manifest-path "$WORKSPACE_DIR/Cargo.toml" | ||
|
|
||
| # Build arm64 | ||
| echo "Building for aarch64-apple-darwin..." | ||
| cargo build --release --package libmoq --target aarch64-apple-darwin --manifest-path "$WORKSPACE_DIR/Cargo.toml" | ||
|
|
||
| # Define sources for packaging | ||
| # Use arm64 as the reference for headers/pkgconfig (they should be identical) | ||
| REF_TARGET="aarch64-apple-darwin" | ||
| INCLUDE_SOURCE="$WORKSPACE_DIR/target/$REF_TARGET/include/moq.h" | ||
| PKGCONFIG_SOURCE="$WORKSPACE_DIR/target/$REF_TARGET/pkgconfig/moq.pc" | ||
|
|
||
| # Libraries to combine | ||
| LIB_X86="$WORKSPACE_DIR/target/x86_64-apple-darwin/release/libmoq.a" | ||
| LIB_ARM64="$WORKSPACE_DIR/target/aarch64-apple-darwin/release/libmoq.a" | ||
| LIB_FILE="libmoq.a" | ||
|
|
||
| # Set up cross-compilation for Linux ARM64 | ||
| if [[ "$TARGET" == "aarch64-unknown-linux-gnu" ]]; then | ||
| export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc | ||
| fi | ||
| else | ||
| # Detect target if not specified | ||
| if [[ -z "$TARGET" ]]; then | ||
| TARGET=$(rustc -vV | grep host | cut -d' ' -f2) | ||
| echo "Detected target: $TARGET" | ||
| fi | ||
|
|
||
| echo "Building libmoq for $TARGET..." | ||
|
|
||
| # Set up cross-compilation for Linux ARM64 | ||
| if [[ "$TARGET" == "aarch64-unknown-linux-gnu" ]]; then | ||
| export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc | ||
| fi | ||
|
|
||
| cargo build --release --package libmoq --target "$TARGET" --manifest-path "$WORKSPACE_DIR/Cargo.toml" | ||
| cargo build --release --package libmoq --target "$TARGET" --manifest-path "$WORKSPACE_DIR/Cargo.toml" | ||
|
|
||
| # Define sources for packaging | ||
| INCLUDE_SOURCE="$WORKSPACE_DIR/target/$TARGET/include/moq.h" | ||
| PKGCONFIG_SOURCE="$WORKSPACE_DIR/target/$TARGET/pkgconfig/moq.pc" | ||
|
|
||
| TARGET_DIR="$WORKSPACE_DIR/target/$TARGET/release" | ||
| if [[ "$TARGET" == *"-windows-"* ]]; then | ||
| LIB_SOURCE="$TARGET_DIR/moq.lib" | ||
| LIB_FILE="moq.lib" | ||
| else | ||
| LIB_SOURCE="$TARGET_DIR/libmoq.a" | ||
| LIB_FILE="libmoq.a" | ||
| fi | ||
| fi | ||
|
|
||
| # Determine paths | ||
| TARGET_DIR="$WORKSPACE_DIR/target/$TARGET/release" | ||
| NAME="moq-${VERSION}-${TARGET}" | ||
| PACKAGE_DIR="$OUTPUT_DIR/$NAME" | ||
|
|
||
|
|
@@ -75,36 +116,26 @@ echo "Packaging $NAME..." | |
| rm -rf "$PACKAGE_DIR" | ||
| mkdir -p "$PACKAGE_DIR/include" "$PACKAGE_DIR/lib" | ||
|
|
||
| # Copy header (generated in target/$TARGET/include/ by build.rs) | ||
| cp "$WORKSPACE_DIR/target/$TARGET/include/moq.h" "$PACKAGE_DIR/include/" | ||
| # Copy header | ||
| cp "$INCLUDE_SOURCE" "$PACKAGE_DIR/include/" | ||
|
|
||
| # Copy static library | ||
| case "$TARGET" in | ||
| *-windows-*) | ||
| cp "$TARGET_DIR/moq.lib" "$PACKAGE_DIR/lib/" | ||
| ;; | ||
| *) | ||
| # Unix-like (macOS, Linux, etc.) | ||
| cp "$TARGET_DIR/libmoq.a" "$PACKAGE_DIR/lib/" | ||
| ;; | ||
| esac | ||
| if [[ "$TARGET" == "universal-apple-darwin" ]]; then | ||
| echo "Creating universal binary..." | ||
| lipo -create "$LIB_X86" "$LIB_ARM64" -output "$PACKAGE_DIR/lib/$LIB_FILE" | ||
| else | ||
| cp "$LIB_SOURCE" "$PACKAGE_DIR/lib/" | ||
| fi | ||
|
Comment on lines
+119
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's find and examine the build.sh file
find . -name "build.sh" -path "*/libmoq/*" | head -5Repository: moq-dev/moq Length of output: 75 🏁 Script executed: # Search for the build.sh file
fd "build.sh" rs/libmoqRepository: moq-dev/moq Length of output: 73 🏁 Script executed: # Look for workflow files that might reference libmoq
fd -e "yml" -e "yaml" | grep -i "workflow\|action" | head -20Repository: moq-dev/moq Length of output: 37 🏁 Script executed: # Examine the build.sh file around lines 119-128
cat -n rs/libmoq/build.sh | sed -n '100,135p'Repository: moq-dev/moq Length of output: 1272 🏁 Script executed: # Check entire build.sh to understand variable definitions
wc -l rs/libmoq/build.shRepository: moq-dev/moq Length of output: 77 🏁 Script executed: # Search for workflow/CI files
fd -e "yml" -e "yaml" .githubRepository: moq-dev/moq Length of output: 37 🏁 Script executed: # Read the beginning of build.sh to understand setup and variable definitions
cat -n rs/libmoq/build.sh | head -100Repository: moq-dev/moq Length of output: 3948 🏁 Script executed: # Search for where LIB_X86 and LIB_ARM64 are defined
rg "LIB_X86|LIB_ARM64" rs/libmoq/Repository: moq-dev/moq Length of output: 338 🏁 Script executed: # Look for GitHub workflow files
find .github -type f \( -name "*.yml" -o -name "*.yaml" \) 2>/dev/nullRepository: moq-dev/moq Length of output: 257 🏁 Script executed: # Examine the libmoq.yml workflow file
cat .github/workflows/libmoq.ymlRepository: moq-dev/moq Length of output: 2621 Workflow target configuration needs fixing for universal binary builds. The packaging logic using lipo is correct. However, the 🤖 Prompt for AI Agents |
||
|
|
||
| # Copy pkg-config file (generated in target/$TARGET/pkgconfig/ by build.rs, not for Windows) | ||
| if [[ "$TARGET" != *"-windows-"* ]]; then | ||
| mkdir -p "$PACKAGE_DIR/lib/pkgconfig" | ||
| cp "$WORKSPACE_DIR/target/$TARGET/pkgconfig/moq.pc" "$PACKAGE_DIR/lib/pkgconfig/" | ||
| cp "$PKGCONFIG_SOURCE" "$PACKAGE_DIR/lib/pkgconfig/" | ||
| fi | ||
|
|
||
| # Generate CMake config files from templates | ||
| mkdir -p "$PACKAGE_DIR/lib/cmake/moq" | ||
|
|
||
| # Determine library filename | ||
| if [[ "$TARGET" == *"-windows-"* ]]; then | ||
| LIB_FILE="moq.lib" | ||
| else | ||
| LIB_FILE="libmoq.a" | ||
| fi | ||
|
|
||
| # Extract major version | ||
| MAJOR_VERSION="${VERSION%%.*}" | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust target installation will fail for universal-apple-darwin.
universal-apple-darwinis not a valid Rust target triple. Thedtolnay/rust-toolchainaction at line 39 will either fail or have no effect. The build script actually needs bothx86_64-apple-darwinandaarch64-apple-darwintargets installed to compile the universal binary.🐛 Proposed fix: Install both actual targets for universal builds
- name: Install Rust uses: dtolnay/rust-toolchain@stable with: - targets: ${{ matrix.target }} + targets: ${{ matrix.target == 'universal-apple-darwin' && 'x86_64-apple-darwin,aarch64-apple-darwin' || matrix.target }}Also applies to: 36-39
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, the proposed fix looks good.
@claude I don't know if you have permission, but can you commit this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.