Skip to content

Conversation

crazytonyli
Copy link
Contributor

When building libraries for Apple platforms, Rust sets minimal os versions to static libraries. The minimal os versions are set by special environment variables, and default ones are used if env var is not set. This PR sets deployment target environment variables when building for Apple platforms, to alight them with the ones defined in the Package.swift file.

Please note: for some reason, even though we have set the macos deployment target to 10.15, the built static library still has a 11.0 minimal os version (see the script output below). That's why this PR also bumps supported macOS version. Please let me know if you have any concerns.

Tests

You can use this script to print some static libraries's supported platform and the minimal os version.

for target in "aarch64-apple-darwin" "aarch64-apple-ios" "aarch64-apple-tvos" "aarch64-apple-watchos-sim"; do
    echo "=> $target"
    bin="target/$target/release/libwordpress.a"
    file=$(ar -t "$bin" | grep -E '\.o$' | head -n 1)
    ar -x "$bin" "$file"
    vtool -show "$file"
done

Please note: you'll need to run a clean build: make clean xcframework before running the script.

Here is a comparison of the script outputs on my Mac
// Before this PR's changes
=> aarch64-apple-darwin
wp_api.wp_api.6de1fa6468dd4249-cgu.00.rcgu.o:
Load command 1
      cmd LC_BUILD_VERSION
  cmdsize 24
 platform MACOS
    minos 11.0
      sdk n/a
   ntools 0
=> aarch64-apple-ios
wp_api.wp_api.66de11d73ce633d5-cgu.00.rcgu.o:
Load command 1
      cmd LC_VERSION_MIN_IPHONEOS
  cmdsize 16
  version 10.0
      sdk n/a
=> aarch64-apple-tvos
wp_api.wp_api.212db3aafd4f72b4-cgu.00.rcgu.o:
Load command 1
      cmd LC_VERSION_MIN_TVOS
  cmdsize 16
  version 10.0
      sdk n/a
=> aarch64-apple-watchos-sim
wp_api.wp_api.1d29733f9a3dee42-cgu.00.rcgu.o:
Load command 1
      cmd LC_BUILD_VERSION
  cmdsize 24
 platform WATCHOSSIMULATOR
    minos 7.0
      sdk n/a
   ntools 0

// After this PR's changes
=> aarch64-apple-darwin
wp_api.wp_api.6de1fa6468dd4249-cgu.00.rcgu.o:
Load command 1
      cmd LC_BUILD_VERSION
  cmdsize 24
 platform MACOS
    minos 11.0
      sdk n/a
   ntools 0
=> aarch64-apple-ios
wp_api.wp_api.66de11d73ce633d5-cgu.00.rcgu.o:
Load command 1
      cmd LC_BUILD_VERSION
  cmdsize 24
 platform IOS
    minos 13.0
      sdk n/a
   ntools 0
=> aarch64-apple-tvos
wp_api.wp_api.212db3aafd4f72b4-cgu.00.rcgu.o:
Load command 1
      cmd LC_BUILD_VERSION
  cmdsize 24
 platform TVOS
    minos 13.0
      sdk n/a
   ntools 0
=> aarch64-apple-watchos-sim
wp_api.wp_api.1d29733f9a3dee42-cgu.00.rcgu.o:
Load command 1
      cmd LC_BUILD_VERSION
  cmdsize 24
 platform WATCHOSSIMULATOR
    minos 8.0
      sdk n/a
   ntools 0

@crazytonyli crazytonyli requested a review from jkmassel April 4, 2024 21:31
Copy link
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

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

Please note: for some reason, even though we have set the macos deployment target to 10.15, the built static library still has a 11.0 minimal os version (see the script output below). That's why this PR also bumps supported macOS version.

I think this is because 11.0 is the first Apple Silicon-compatible version – I'd guess that if we were to compile against x86_64, we could go back further? Having 11.0 as a minimum seems reasonable given the fact that Intel is basically deprecated – if we have a compelling need to support older Intel-only macOS versions we could theoretically do so, but that's probably not worth us investing any time into right now.

@crazytonyli crazytonyli enabled auto-merge (squash) April 4, 2024 22:11
@crazytonyli crazytonyli merged commit a4591da into trunk Apr 4, 2024
@crazytonyli crazytonyli deleted the swift-package-set-deployment-targets branch April 4, 2024 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants