Skip to content
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

WIP SwiftUI Preview investigation Xcode 16 #3113

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
691 changes: 691 additions & 0 deletions docs/SwiftUIPreviewInvestigation/Output/Bazel/Bazel_Build_Log.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-target
x86_64-apple-macos12.0
-sdk
__BAZEL_XCODE_SDKROOT__
-debug-prefix-map
__BAZEL_XCODE_DEVELOPER_DIR__=/PLACEHOLDER_DEVELOPER_DIR
-file-prefix-map
__BAZEL_XCODE_DEVELOPER_DIR__=/PLACEHOLDER_DEVELOPER_DIR
-emit-object
-output-file-map
bazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin/tools/swiftc_stub/swiftc_stub.library.output_file_map.json
-Xfrontend
-no-clang-module-breadcrumbs
-emit-module-path
bazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin/tools/swiftc_stub/swiftc_stub.swiftmodule
-enable-bare-slash-regex
-DDEBUG
-Onone
-Xfrontend
-no-serialize-debugging-options
-enable-testing
-gline-tables-only
-Xwrapped-swift=-debug-prefix-pwd-is-dot
-Xwrapped-swift=-file-prefix-pwd-is-dot
-module-cache-path
bazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin/_swift_module_cache
-Xwrapped-swift=-macro-expansion-dir=bazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin/tools/swiftc_stub/swiftc_stub.library.macro-expansions
-Xcc
-iquote.
-Xcc
-iquotebazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin
-Xfrontend
-color-diagnostics
-enable-batch-mode
-module-name
swiftc_stub
-static
-Xcc
-O0
-Xcc
-DDEBUG=1
tools/swiftc_stub/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-lc++
-Wl,-oso_prefix,__BAZEL_EXECUTION_ROOT__/
-Wl,-S
-o
bazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin/tools/swiftc_stub/swiftc_stub_binary
bazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin/tools/swiftc_stub/libswiftc_stub.library.a
-headerpad_max_install_names
-Wl,-add_ast_path,bazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin/tools/swiftc_stub/swiftc_stub.swiftmodule
-ObjC
-L__BAZEL_XCODE_DEVELOPER_DIR__/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
-L/usr/lib/swift
-Wl,-objc_abi_version,2
-Wl,-rpath,/usr/lib/swift
-no-canonical-prefixes
-target
x86_64-apple-macosx12.0
-fobjc-link-runtime
-Xlinker
-no_deduplicate
-framework
Foundation
-Wl,-no_warn_duplicate_libraries
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"-D_FORTIFY_SOURCE=1"
"-fstack-protector"
"-fcolor-diagnostics"
"-Wall"
"-Wthread-safety"
"-Wself-assign"
"-fno-omit-frame-pointer"
"-g0"
"-O2"
"-DNDEBUG"
"-DNS_BLOCK_ASSERTIONS=1"
"-std=c++14"
"-fdebug-prefix-map=/Users/oscarberggren/Desktop/rules_xcodeproj-2.9.1/examples/sanitizers/bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/__main__=."
"-fdebug-prefix-map=/Applications/Xcode16.0/Xcode.app/Contents/Developer=/PLACEHOLDER_DEVELOPER_DIR"
"-iquote"
"external/build_bazel_rules_swift"
"-iquote"
"bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/build_bazel_rules_swift"
"-iquote"
"external/com_github_nlohmann_json"
"-iquote"
"bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/com_github_nlohmann_json"
"-isystem"
"external/com_github_nlohmann_json/include"
"-isystem"
"bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/com_github_nlohmann_json/include"
"-MD"
"-MF"
"bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/build_bazel_rules_swift/tools/worker/_objs/worker_protocol/worker_protocol.d"
"-frandom-seed=bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/build_bazel_rules_swift/tools/worker/_objs/worker_protocol/worker_protocol.o"
"-isysroot"
"/Applications/Xcode16.0/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk"
"-F/Applications/Xcode16.0/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks"
"-F/Applications/Xcode16.0/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks"
"-no-canonical-prefixes"
"-pthread"
"-g0"
"-g0"
"-std=c++17"
"-no-canonical-prefixes"
"-Wno-builtin-macro-redefined"
"-D__DATE__=\"redacted\""
"-D__TIMESTAMP__=\"redacted\""
"-D__TIME__=\"redacted\""
"-target"
"arm64-apple-macosx13.0"
"-c"
"external/build_bazel_rules_swift/tools/worker/worker_protocol.cc"
"-o"
"bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/build_bazel_rules_swift/tools/worker/_objs/worker_protocol/worker_protocol.o"

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions docs/SwiftUIPreviewInvestigation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a branch for investigating why SwiftUI Previews have stopped working in Xcode 16, I would love for people to come with inputs and contribute so we can solve this together

# Generating example project

This folder contains a project.yml file that will generate the project when running 'xcodegen generate'

If xcodegen isn't installed, please visit https://github.com/yonaskolb/XcodeGen#installing and follow the instructions

# How to get Bazel flags
cd to rules_xcodeproj root and run:
bazelisk build tools/swiftc_stub:universal_swiftc_stub

This will create a bunch of files in
/Users/User/Downloads/rules_xcodeproj/bazel-output-base/execroot/_main/bazel-out/darwin_x86_64-fastbuild-macos-x86_64-min12.0-applebin_macos-ST-50cbb438abaf/bin/tools

Find the files called “swiftc_stub_binary-2.params” and "swiftc-stub.swiftmodue-0"

Open with TextEdit.

# How to get extended Build log

Open Xcode and go to Target -> Build Phases -> New Run Script Phase

Paste “echo $CFLAGS”

Run the app

Navigate to "Report navigator"

Go to the Build section and press “Export” in the top right corner.

This file will contains C-flags settings in Xcode

# wrapped_clang_params: WIP
31 changes: 31 additions & 0 deletions docs/SwiftUIPreviewInvestigation/Stubs/clang_shim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -euo pipefail

echo "$@" > $(pwd)/Output/clang_shim_args.txt

while test $# -gt 0
do
case $1 in
-MF)
shift
touch "$1"
;;
--serialize-diagnostics)
shift
cp "${BASH_SOURCE%/*}/cc.dia" "$1"
;;
*.o)
break
;;
-v)
# TODO: Make this work with custom toolchains
DEV_DIR_PREFIX=$(awk '{ sub(/.*-isysroot /, ""); sub(/.Contents\/Developer.*/, ""); print}' <<< "${@:1}")
clang="$DEV_DIR_PREFIX/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
"$clang" "${@:1}"
break
;;
esac

shift
done
32 changes: 32 additions & 0 deletions docs/SwiftUIPreviewInvestigation/Stubs/ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -euo pipefail

echo "$@" > $(pwd)/Output/clang_shim_args.txt

passthrough_args=("${@:1}")

while test $# -gt 0
do
case $1 in
*_dependency_info.dat)
ld_version=$(ld -v 2>&1 | grep ^@)
printf "\0%s\0" "$ld_version" > "$1"
break
;;

-isysroot)
shift
# PATH/DEVELOPER_DIR isn't set when this is called, so we need to calculate
# the developer dir from the sysroot to invoke clang (used below)
developer_dir="${1/\/Platforms\/*/}"
;;

*.preview-thunk.dylib)
# Pass through for SwiftUI Preview thunk compilation
# TODO: Make this work with custom toolchains
exec "$developer_dir/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "${passthrough_args[@]}"
;;
esac
shift
done
Binary file added docs/SwiftUIPreviewInvestigation/Stubs/swiftc
Binary file not shown.
8 changes: 8 additions & 0 deletions docs/SwiftUIPreviewInvestigation/app/Debug.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<string>group.com.example.core</string>
</dict>
</plist>
24 changes: 24 additions & 0 deletions docs/SwiftUIPreviewInvestigation/app/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>MyApp</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
18 changes: 18 additions & 0 deletions docs/SwiftUIPreviewInvestigation/app/sources/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ContentView.swift
// Core
//
// Created by Oscar Berggren on 12/9/24.
//

import SwiftUI

struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}

#Preview {
ContentView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ExampleProjectApp.swift
// Core
//
// Created by Oscar Berggren on 12/9/24.
//

import SwiftUI

@main
struct ExampleProjectApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
86 changes: 86 additions & 0 deletions docs/SwiftUIPreviewInvestigation/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
############
## Project
############
name: ExampleProject

############
## Options
############
## In this part we will override some project properties

options:
# Select the minimum xcodegen version that could generate this project
minimumXcodeGenVersion: 2.10

# Create empty directories in the final project too
generateEmptyDirectories: true

# Select deployment target. In this particular case will be use iOS, but
# we include the example to define it to watchOS, tvOS or macOS
deploymentTarget:
iOS: "17.4"
# watchOS: "6.0"
# tvOS: "15.0"
# macOS: "11.0"

#############
## Settings
#############

settings:
# Following properties will be override properties that you could find
# into Build settings directory. We will rewrite some for all default variants
# created by default for xcodegen, Debug and Release.
IPHONEOS_DEPLOYMENT_TARGET: "17.4"
MARKETING_VERSION: "1.0.0"
CURRENT_PROJECT_VERSION: "1"

############
## Targets
############

# Finally we will create our targets. Rememeber we have three of them:
# - A core package (that will depends on Alamofire)
# - A test target for this core package
# - An app target

targets:

# Name for our app target
ExampleProject:
# choose application as a type. There a so many types to select here (framework, extensions ...)
type: application
# choose destination platform
platform: iOS
deploymentTarget: 17.4
sources:
# Where app files will be found. Remember you could use patterns and exclusions too!
- path: app/sources
group: app
settings:
# Select the bundle identifier
PRODUCT_BUNDLE_IDENTIFIER: "com.example.core"
CC:
- "$(PROJECT_DIR)/Stubs/clang_shim.sh"
CXX:
- "$(PROJECT_DIR)/Stubs/clang_shim.sh"
LD:
- "$(PROJECT_DIR)/Stubs/ld"
SWIFT_EXEC:
- "$(PROJECT_DIR)/Stubs/swiftc"

# Select where Info.plist will be found
INFOPLIST_FILE: app/Info.plist
MARKETING_VERSION: 1.0.0
postCompileScripts:
- script: |
echo $CFLAGS
name: CFlags
entitlements:
path: app/Debug.entitlements
properties:
com.apple.security.application-groups: group.com.example.core
info:
path: app/Info.plist
properties:
CFBundleDisplayName: "MyApp"