Skip to content

Instantly share code, notes, and snippets.

@startergo
Forked from rnapier/fix-xcode
Last active June 20, 2025 13:12
Show Gist options
  • Select an option

  • Save startergo/57c07949b1fdfea5d34590fabc30ffa2 to your computer and use it in GitHub Desktop.

Select an option

Save startergo/57c07949b1fdfea5d34590fabc30ffa2 to your computer and use it in GitHub Desktop.
Links Xcode SDK from the ~/SDKs directory (which you maintain yourself)
#!/usr/bin/env python3
# fix-xcode
# Rob Napier <[email protected]>
# Script to link in all your old SDKs every time you upgrade Xcode
# Create a directory called ~/SDKs (or modify source_path).
# Under it, put all the platform directories:
# MacOSX.platform iPhoneOS.platform iPhoneSimulator.platform
# Under those, store the SDKs:
# MacOSX10.4u.sdk MacOSX10.5.sdk MacOSX10.6.sdk MacOSX10.7.sdk MacOSX10.8.sdk
#
# After upgrading Xcode, just run fix-xcode.
import argparse
import subprocess
import os
import sys
# Change this to the actual location of your SDK directory
# Using a directory in the user's home folder to avoid permission issues
source_path = os.path.expanduser("~/SDKs")
parser = argparse.ArgumentParser()
parser.add_argument('xcodePath', help='path to Xcode', nargs='?')
args = parser.parse_args()
if args.xcodePath:
dest_path = args.xcodePath
else:
dest_path = subprocess.check_output(["xcode-select", "--print-path"]).decode().rstrip()
if not dest_path.endswith("/Contents/Developer"):
dest_path += "/Contents/Developer"
# Check if source path exists
if not os.path.exists(source_path):
print(f"Error: Source directory '{source_path}' does not exist.")
print(f"Please create this directory with: mkdir -p {source_path}")
print("Then add your SDK platforms as described in the comments.")
sys.exit(1)
# Process each platform
for platform_dir in os.listdir(source_path):
platform_path = os.path.join(source_path, platform_dir)
if os.path.isdir(platform_path) and platform_dir.endswith(".platform"):
platform_name = platform_dir
sdk_source_dir = os.path.join(platform_path, "Developer", "SDKs")
if os.path.exists(sdk_source_dir):
# Create target directory if it doesn't exist
target_dir = f"{dest_path}/Platforms/{platform_name}/Developer/SDKs"
os.makedirs(target_dir, exist_ok=True)
print(f"Linking SDKs for platform {platform_name}...")
for sdk in os.listdir(sdk_source_dir):
source_sdk = os.path.join(sdk_source_dir, sdk)
target_sdk = os.path.join(target_dir, sdk)
if os.path.isdir(source_sdk):
# Using sudo is still needed because we're writing to Xcode's directory
cmd = f"sudo ln -sf \"{source_sdk}\" \"{target_sdk}\""
print(f"Running: {cmd}")
subprocess.call(cmd, shell=True)
else:
print(f"Warning: No SDKs found for platform {platform_name}")
@startergo
Copy link
Author

startergo commented Jun 20, 2025

  • Create the directory in your home folder:
mkdir -p ~/SDKs
  • Place your SDK files in this directory following the structure:
~/SDKs/
  |-- MacOSX.platform/
  |    |-- Developer/
  |         |-- SDKs/
  |              |-- MacOSX10.4u.sdk/
  |              |-- MacOSX10.5.sdk/
  |              |-- etc...
  |-- iPhoneOS.platform/
  |    |-- Developer/
  |         |-- SDKs/
  |              |-- iPhoneOS8.0.sdk/
  |              |-- etc...
  |-- iPhoneSimulator.platform/
       |-- Developer/
            |-- SDKs/
                 |-- iPhoneSimulator8.0.sdk/
                 |-- etc...
  • Run the script:
    python3 ~/Downloads/fix-SDK-code/fix-xcode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment