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

Karim/fix xcode previews #3124

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions tools/generators/legacy/src/Generator/CreateProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ $(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)
"LD": "$(BAZEL_INTEGRATION_DIR)/ld",
"LDPLUSPLUS": "$(BAZEL_INTEGRATION_DIR)/ld",
"LIBTOOL": "$(BAZEL_INTEGRATION_DIR)/libtool",
"SWIFT_EXEC": "$(BAZEL_INTEGRATION_DIR)/swiftc",
"SWIFT_USE_INTEGRATED_DRIVER": false,
"TAPI_EXEC": "/usr/bin/true",
], uniquingKeysWith: { _, r in r })
} else {
Expand Down
2 changes: 0 additions & 2 deletions tools/generators/legacy/test/CreateProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ $(BUILD_DIR)/$(BAZEL_PACKAGE_BIN_DIR)
"RULES_XCODEPROJ_BUILD_MODE": "bazel",
"SRCROOT": directories.workspace.string,
"SUPPORTS_MACCATALYST": false,
"SWIFT_EXEC": "$(BAZEL_INTEGRATION_DIR)/swiftc",
"TAPI_EXEC": "/usr/bin/true",
"SWIFT_OBJC_INTERFACE_HEADER_NAME": "",
"SWIFT_OPTIMIZATION_LEVEL": "-Onone",
"SWIFT_USE_INTEGRATED_DRIVER": false,
"SWIFT_VERSION": "5.0",
"TARGET_TEMP_DIR": """
$(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)
Expand Down
4 changes: 0 additions & 4 deletions tools/generators/pbxproj_prefix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,8 @@ Here is an example output:
RULES_XCODEPROJ_BUILD_MODE = bazel;
SRCROOT = /tmp/workspace;
SUPPORTS_MACCATALYST = NO;
SWIFT_EXEC = "$(BAZEL_INTEGRATION_DIR)/swiftc";
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_USE_INTEGRATED_DRIVER = NO;
SWIFT_VERSION = 5.0;
TAPI_EXEC = /usr/bin/true;
TARGET_TEMP_DIR = "$(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)";
Expand Down Expand Up @@ -292,10 +290,8 @@ Here is an example output:
RULES_XCODEPROJ_BUILD_MODE = bazel;
SRCROOT = /tmp/workspace;
SUPPORTS_MACCATALYST = NO;
SWIFT_EXEC = "$(BAZEL_INTEGRATION_DIR)/swiftc";
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_USE_INTEGRATED_DRIVER = NO;
SWIFT_VERSION = 5.0;
TAPI_EXEC = /usr/bin/true;
TARGET_TEMP_DIR = "$(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,8 @@ extension Generator {
.init(key: "RULES_XCODEPROJ_BUILD_MODE", value: "bazel"),
.init(key: "SRCROOT", value: workspace.pbxProjEscaped),
.init(key: "SUPPORTS_MACCATALYST", value: "NO"),
.init(
key: "SWIFT_EXEC",
value: #""$(BAZEL_INTEGRATION_DIR)/swiftc""#
),
.init(key: "SWIFT_OBJC_INTERFACE_HEADER_NAME", value: #""""#),
.init(key: "SWIFT_OPTIMIZATION_LEVEL", value: #""-Onone""#),
.init(key: "SWIFT_USE_INTEGRATED_DRIVER", value: "NO"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-12-26 at 15 45 00

.init(key: "SWIFT_VERSION", value: "5.0"),
.init(key: "TAPI_EXEC", value: "/usr/bin/true"),
.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ class PBXProjectBuildSettingsTests: XCTestCase {
RULES_XCODEPROJ_BUILD_MODE = bazel;
SRCROOT = "/Users/TimApple/Star Board";
SUPPORTS_MACCATALYST = NO;
SWIFT_EXEC = "$(BAZEL_INTEGRATION_DIR)/swiftc";
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_USE_INTEGRATED_DRIVER = NO;
SWIFT_VERSION = 5.0;
TAPI_EXEC = /usr/bin/true;
TARGET_TEMP_DIR = "$(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)";
Expand Down
22 changes: 20 additions & 2 deletions tools/swiftc_stub/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum PathKey: String {
case emitModulePath = "-emit-module-path"
case emitObjCHeaderPath = "-emit-objc-header-path"
case outputFileMap = "-output-file-map"
case supplementaryOutputFileMap = "-supplementary-output-file-map"
case sdk = "-sdk"
}

Expand All @@ -32,7 +33,7 @@ func processArgs(

if arg == "-wmo" || arg == "-whole-module-optimization" {
isWMO = true
} else if arg.hasSuffix(".preview-thunk.swift") {
} else if arg.hasSuffix("usr/lib/swift/host/plugins") || arg.hasSuffix(".preview-thunk.swift") {
isPreviewThunk = true
} else {
previousArg = arg
Expand All @@ -56,7 +57,7 @@ func processArgs(
}

return (
!paths.keys.contains(.outputFileMap) && isPreviewThunk,
isPreviewThunk,
isWMO,
paths
)
Expand Down Expand Up @@ -116,11 +117,14 @@ func touchSwiftmoduleArtifacts(paths: [PathKey: URL]) throws {
.appendingPathExtension("swiftsourceinfo")
var swiftinterfacePath = swiftmodulePath.deletingPathExtension()
.appendingPathExtension("swiftinterface")
var swiftconstvaluesPath = swiftmodulePath.deletingPathExtension()
.appendingPathExtension("swiftconstvalues")

try swiftmodulePath.touch()
try swiftdocPath.touch()
try swiftsourceinfoPath.touch()
try swiftinterfacePath.touch()
try swiftconstvaluesPath.touch()
}

if var generatedHeaderPath = paths[PathKey.emitObjCHeaderPath] {
Expand All @@ -146,6 +150,20 @@ func handleXcodePreviewThunk(args: [String], paths: [PathKey: URL]) throws -> Ne
exit(1)
}

if let outputFileMapURL = paths[.supplementaryOutputFileMap] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

without that i got an error

Showing All Messages
Error opening '/Users/karim.alweheshy/Library/Developer/Xcode/DerivedData/TestModule_Feature-dtbqdukuomtoamfwbeaihszmgzda/Build/Intermediates.noindex/TestModule_Feature.build/bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min15.0-applebin_ios-ST-4f30668f84b0/bin/Modules/TestModule/TestModule/Objects-normal/arm64/TestModule.swiftconstvalues' for output: /Users/karim.alweheshy/Library/Developer/Xcode/DerivedData/TestModule_Feature-dtbqdukuomtoamfwbeaihszmgzda/Build/Intermediates.noindex/TestModule_Feature.build/bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min15.0-applebin_ios-ST-4f30668f84b0/bin/Modules/TestModule/TestModule/Objects-normal/arm64/TestModule.swiftconstvalues: Operation not permitted

let data = try! Data(contentsOf: outputFileMapURL)
let constValuesURL = String(data: data, encoding: .utf8)!
.components(separatedBy: .newlines)
.dropFirst()
.first { $0.contains("const-values") }!
.components(separatedBy: "\"")[1]

var attributes = try FileManager.default.attributesOfItem(atPath: constValuesURL)
let permissions: Int = 0o755 // rwxr-xr-x
attributes[.posixPermissions] = permissions
try FileManager.default.setAttributes(attributes, ofItemAtPath: constValuesURL)
}

// TODO: Make this work with custom toolchains
// We could produce this file at the start of the build?
let fullRange = NSRange(sdkPath.startIndex..., in: sdkPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if [[ "$ACTION" != indexbuild ]]; then
if [[ -f "$BAZEL_OUTPUTS_PRODUCT_BASENAME" ]]; then
# Product is a binary, so symlink instead of rsync, to allow for Bazel-set
# rpaths to work
ln -sfh "$PWD/$BAZEL_OUTPUTS_PRODUCT_BASENAME" "$TARGET_BUILD_DIR/$PRODUCT_NAME"
ln -sfh "$PWD/$BAZEL_OUTPUTS_PRODUCT_BASENAME" "$TARGET_BUILD_DIR/lib$PRODUCT_NAME.a"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SwiftUIP Previews run

libtool called with arguments: -static -arch_only arm64 -D -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.1.sdk -L/Users/karim.alweheshy/Library/Developer/Xcode/DerivedData/TestProject-cnscizqkxdbvwacrakshbzzkcnub/Build/Products/Debug-iphonesimulator -filelist /Users/karim.alweheshy/Library/Developer/Xcode/DerivedData/TestProject-cnscizqkxdbvwacrakshbzzkcnub/Build/Intermediates.noindex/Impl.build/Debug-iphonesimulator/Impl.build/Objects-normal/arm64/Impl.LinkFileList -dependency_info /Users/karim.alweheshy/Library/Developer/Xcode/DerivedData/TestProject-cnscizqkxdbvwacrakshbzzkcnub/Build/Intermediates.noindex/Impl.build/Debug-iphonesimulator/Impl.build/Objects-normal/arm64/Impl_libtool_dependency_info.dat -o /Users/karim.alweheshy/Library/Developer/Xcode/DerivedData/TestProject-cnscizqkxdbvwacrakshbzzkcnub/Build/Products/Debug-iphonesimulator/libImpl.a

else
# Product is a bundle
rsync \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ build_pre_config_flags=(
# This is brittle. If different file extensions are used for compilation
# inputs, they will need to be added to this list. Ideally we can stop doing
# this once Bazel adds support for a Remote Output Service.
"--experimental_remote_download_regex=.*\.indexstore/.*|.*\.(a|cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|yaml)$"
"--remote_download_regex=.*\.indexstore/.*|.*\.(a|cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|swiftconstvalues|yaml)$"
)

apply_sanitizers=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ readonly build_pre_config_flags=(
# This is brittle. If different file extensions are used for compilation
# inputs, they will need to be added to this list. Ideally we can stop doing
# this once Bazel adds support for a Remote Output Service.
"--experimental_remote_download_regex=${indexstores_regex}.*|.*\.(cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|yaml)$"
"--remote_download_regex=${indexstores_regex}.*|.*\.(cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|swiftconstvalues|yaml)$"
)

source "$BAZEL_INTEGRATION_DIR/bazel_build.sh"
Expand Down
6 changes: 6 additions & 0 deletions xcodeproj/internal/bazel_integration_files/ld
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ do
developer_dir="${1/\/Platforms\/*/}"
;;

*.debug.dylib)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to verify this on an App previews

# 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[@]}"
;;

*.preview-thunk.dylib)
# Pass through for SwiftUI Preview thunk compilation
# TODO: Make this work with custom toolchains
Expand Down
2 changes: 1 addition & 1 deletion xcodeproj/internal/templates/bazel_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ echo "Starting Bazel build"
${build_pre_config_flags:+"${build_pre_config_flags[@]}"} \
--config="$config" \
--color=yes \
${toolchain:+--define=SWIFT_CUSTOM_TOOLCHAIN="$toolchain"} \
${toolchain:+--action_env=TOOLCHAINS="$toolchain"} \
"$output_groups_flag" \
"%generator_label%" \
${labels:+"--build_metadata=PATTERN=${labels[*]}"} \
Expand Down
2 changes: 1 addition & 1 deletion xcodeproj/internal/templates/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ else
if [[ $cmd == "build" && -n "${generator_output_groups:-}" ]]; then
if [[ $download_intermediates -eq 1 ]]; then
pre_config_flags=(
"--experimental_remote_download_regex=.*\.indexstore/.*|.*\.(a|cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|yaml)$"
"--remote_download_regex=.*\.indexstore/.*|.*\.(a|cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|swiftconstvalues|yaml)$"
)
else
pre_config_flags=()
Expand Down
Loading