Custom Toolchain and Library Linking Implementation
The Problem
The generated projects had critical issues preventing Xcode Preview App (XOJIT) functionality because it depends on:
- Missing Library Dependencies: Preview App couldn't find required static libraries (
.a, .dylib.. ect) during linking, causing build failures. It parses it from the build phase.
- Missing Search Paths: Library search paths weren't properly configured, leading to linker errors. After adding the above, we need to add the search paths for the PreviewApp to find the .a files.
- Toolchain Misalignment: SwiftUI Preview prevents us from injecting swiftc stub. We need to geenrate an entire new xctoolchain.
The Solution
Implement a comprehensive custom toolchain system and enhanced library linking through several interconnected components:
1. Custom Toolchain Generation System
Create a fully functional Xcode toolchain that mirrors the system toolchain but allows for specific tool overrides.
2. Enhanced Library Detection and Linking
Improve library discovery to properly detect and collect library dependencies from compilation providers.
3. Build Phase Enhancement
Ensure discovered libraries are properly included in Xcode targets' build phases.
4. Project-Level Configuration
Update project settings to use custom toolchains and proper search paths to find the libs.
Implementation Progress
Custom Toolchain System
Library Detection Enhancement
Build Phase Integration
Runtime Library Support
Project Configuration
Testing and Validation
Project Size Optimization (High Priority)
Complexity: Medium (equivalent to 2-3 days focused development)
Dependency Detection Improvements (High Priority)
Complexity: High (equivalent to 3-4 days focused development)
Performance and Polish (Medium Priority)
Implementation Strategy
Phase 1: Project Size Optimization (Priority: High)
Focus on architectural changes to reference generation system to improve developer experience with large project files.
Approach:
- Implement shared product reference system across targets
- Update build file reference generation to reuse existing references
- Reorganize search paths to project-level configuration
- Test with existing large projects to validate improvements
Phase 2: Dependency Detection Enhancement (Priority: High)
Systematic analysis and enhancement of dependency discovery to address core functionality gaps.
Approach:
- Conduct deep investigation into dependency detection failures
- Create comprehensive test cases for problematic edge cases
- Implement enhanced dependency detection algorithms
- Add debugging infrastructure for troubleshooting complex scenarios
Phase 3: Performance and Polish (Priority: Medium)
Performance and developer experience improvements.
Approach:
- Profile toolchain generation performance and optimize bottlenecks
- Optimize file operations and implement intelligent caching
- Create comprehensive documentation and troubleshooting guides
- Establish monitoring and validation for edge cases
Technical Details
Branch: karim/add-custom-toolchain-to-generated-project
Key Files:
xcodeproj/internal/custom_toolchain.bzl - Custom toolchain rule implementation
xcodeproj/internal/files/linker_input_files.bzl - Enhanced library detection
tools/generators/pbxnativetargets/src/Generator/CreateLinkBinaryWithLibrariesBuildPhaseObject.swift - Build phase generation
tools/generators/pbxnativetargets/src/Generator/CreateFrameworkObject.swift - Framework object creation
tools/generators/pbxproj_prefix/src/Generator/PBXProjectBuildSettings.swift - Project build settings
Current Status
This implementation provides foundational infrastructure that enables reliable Xcode Preview usage while maintaining Bazel build benefits. The system significantly improves Preview App functionality, with remaining work focused on optimization and edge case handling rather than fundamental architectural changes.
The completed work establishes a solid foundation for iOS development workflows, and the outstanding tasks will complete the feature set for production readiness.
Custom Toolchain and Library Linking Implementation
The Problem
The generated projects had critical issues preventing Xcode Preview App (XOJIT) functionality because it depends on:
.a,.dylib.. ect) during linking, causing build failures. It parses it from the build phase.The Solution
Implement a comprehensive custom toolchain system and enhanced library linking through several interconnected components:
1. Custom Toolchain Generation System
Create a fully functional Xcode toolchain that mirrors the system toolchain but allows for specific tool overrides.
2. Enhanced Library Detection and Linking
Improve library discovery to properly detect and collect library dependencies from compilation providers.
3. Build Phase Enhancement
Ensure discovered libraries are properly included in Xcode targets' build phases.
4. Project-Level Configuration
Update project settings to use custom toolchains and proper search paths to find the libs.
Implementation Progress
Custom Toolchain System
custom_toolchain.bzl)custom_toolchain_symlink.sh,custom_toolchain_override.sh)Library Detection Enhancement
.a), dynamic libraries (.dylib), and frameworks from both Objective-C and C++ compilation providers (linker_input_files.bzl)Build Phase Integration
CreateLinkBinaryWithLibrariesBuildPhaseObject.swiftto generate properPBXFrameworksBuildPhaseCreateFrameworkObject.swiftfor framework references in Xcode projectCreateFrameworkBuildFileObject.swiftfor managing build file referencesRuntime Library Support
Project Configuration
PBXProjectBuildSettings.swiftfor custom toolchain usageTesting and Validation
test/internal/custom_toolchain/for toolchain generationProject Size Optimization (High Priority)
Complexity: Medium (equivalent to 2-3 days focused development)
Dependency Detection Improvements (High Priority)
Complexity: High (equivalent to 3-4 days focused development)
Performance and Polish (Medium Priority)
Implementation Strategy
Phase 1: Project Size Optimization (Priority: High)
Focus on architectural changes to reference generation system to improve developer experience with large project files.
Approach:
Phase 2: Dependency Detection Enhancement (Priority: High)
Systematic analysis and enhancement of dependency discovery to address core functionality gaps.
Approach:
Phase 3: Performance and Polish (Priority: Medium)
Performance and developer experience improvements.
Approach:
Technical Details
Branch:
karim/add-custom-toolchain-to-generated-projectKey Files:
xcodeproj/internal/custom_toolchain.bzl- Custom toolchain rule implementationxcodeproj/internal/files/linker_input_files.bzl- Enhanced library detectiontools/generators/pbxnativetargets/src/Generator/CreateLinkBinaryWithLibrariesBuildPhaseObject.swift- Build phase generationtools/generators/pbxnativetargets/src/Generator/CreateFrameworkObject.swift- Framework object creationtools/generators/pbxproj_prefix/src/Generator/PBXProjectBuildSettings.swift- Project build settingsCurrent Status
This implementation provides foundational infrastructure that enables reliable Xcode Preview usage while maintaining Bazel build benefits. The system significantly improves Preview App functionality, with remaining work focused on optimization and edge case handling rather than fundamental architectural changes.
The completed work establishes a solid foundation for iOS development workflows, and the outstanding tasks will complete the feature set for production readiness.