Skip to content
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
8 changes: 8 additions & 0 deletions .github/workflows/skipstone-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ jobs:
#- 'r29'

steps:
- name: Checkout compiler regression tests
uses: actions/checkout@v7

- uses: Homebrew/actions/setup-homebrew@main

# The transpiled (Lite) and Fuse framework `swift test` runs execute the Kotlin suite under
Expand Down Expand Up @@ -221,6 +224,11 @@ jobs:

- run: skip android build --version

- name: Verify Android SwiftUI import isolation on warm builds
env:
SKIP_TEST_ANDROID_SWIFTUI_IMPORTS: "1"
run: swift test --package-path skipstone --filter AndroidSwiftUIImportTests --jobs 4

#- run: skip doctor

#- name: "Create and export new Skip Fuse app project"
Expand Down
20 changes: 20 additions & 0 deletions skipstone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ Skip 1.7.0*: skipstone plugin to: /Users/marc/Library/Developer/Xcode/DerivedDat
>
> When in doubt, always just quit Xcode manually and re-launch your workspace from the `skipstone` folder from the Terminal again, and then verify that the local build of `skipstone` is being used with the logging indicators above.

## Android SwiftUI imports

Generated native package manifests alias the Android `SwiftUI` compatibility target to
`SkipCompatibilitySwiftUI` on dependencies on the `SkipFuseUI` product. SwiftPM forwards the alias
to those consumers, so their `import SwiftUI` and qualified `SwiftUI` references keep working.
Unrelated packages no longer discover that module through `canImport(SwiftUI)`, which otherwise
activates Apple-only extensions in packages such as swift-clocks and swift-dependencies during
incremental builds. Apple-platform manifests are unchanged.

Android builds of these generated packages use a `swiftui-imports` subdirectory of the selected
scratch directory. This keeps old, unaliased `SwiftUI.swiftmodule` artifacts out of their search
paths without deleting existing build outputs.

Run the compiler regression, including an upgrade from old build outputs and a forced warm
rebuild, on a host with a matching Swift Android SDK installed:

```console
SKIP_TEST_ANDROID_SWIFTUI_IMPORTS=1 swift test --filter AndroidSwiftUIImportTests
```

## Releasing Skip

A release of Skip publishes a new version of both the `skip` command-line tool and the `skip`
Expand Down
43 changes: 43 additions & 0 deletions skipstone/Sources/SkipBuild/AndroidSwiftUIImports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Foundation

/// Keep the Android SwiftUI compatibility module out of unrelated targets' `canImport` checks.
/// SwiftPM puts every built module in a shared search directory, so an unaliased `SwiftUI`
/// activates Apple-only extensions in packages such as swift-clocks on subsequent builds.
enum AndroidSwiftUIImports {
static let marker = "// Scope Skip's Android SwiftUI compatibility module to targets that depend on SkipFuseUI."

/// Old builds leave an unaliased SwiftUI.swiftmodule in the shared products directory.
/// Use a separate scratch directory so upgrading does not reactivate those stale imports.
static func scratchPath(packagePath: String, configuredPath: String?) -> String? {
let manifest = URL(fileURLWithPath: packagePath).appendingPathComponent("Package.swift")
guard let contents = try? String(contentsOf: manifest, encoding: .utf8), contents.contains(marker) else {
return configuredPath
}
return URL(fileURLWithPath: configuredPath ?? (packagePath + "/.build"))
.appendingPathComponent("swiftui-imports").path
}

static let packageAddendum = """

// Scope Skip's Android SwiftUI compatibility module to targets that depend on SkipFuseUI.
if Context.environment["TARGET_OS_ANDROID"] ?? "0" != "0" {
for target in package.targets {
target.dependencies = target.dependencies.map { dependency in
switch dependency {
case .productItem(let name, let dependencyPackage, let moduleAliases, let condition)
where name == "SkipFuseUI" && dependencyPackage == "skip-fuse-ui":
var aliases = moduleAliases ?? [:]
aliases["SwiftUI"] = aliases["SwiftUI"] ?? "SkipCompatibilitySwiftUI"
return .product(name: name, package: "skip-fuse-ui", moduleAliases: aliases, condition: condition)
case .byNameItem(let name, let condition)
where name == "SkipFuseUI" && !package.targets.contains(where: { $0.name == name }):
return .product(name: name, package: "skip-fuse-ui", moduleAliases: ["SwiftUI": "SkipCompatibilitySwiftUI"], condition: condition)
default:
return dependency
}
}
}
}

"""
}
13 changes: 9 additions & 4 deletions skipstone/Sources/SkipBuild/Commands/AndroidCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ protocol AndroidOperationCommand : MessageCommand, ToolchainOptionsCommand {
}

extension AndroidOperationCommand {
var swiftScratchPath: String? {
AndroidSwiftUIImports.scratchPath(packagePath: toolchainOptions.packagePath ?? ".", configuredPath: toolchainOptions.scratchPath)
}

/// Default runtime options for commands that don't expose the flag (e.g. build, toolchain version)
var androidRuntimeOptions: AndroidRuntimeOptions { AndroidRuntimeOptions() }

Expand Down Expand Up @@ -882,8 +886,9 @@ extension AndroidOperationCommand {
}
// resolve every generated manifest's local dependencies against the root Packages/ links, so each package has one path and re-plans stay incremental
env["SKIP_LOCAL_PACKAGES_PATH"] = URL(fileURLWithPath: toolchainOptions.packagePath ?? ".").appendingPathComponent("Packages", isDirectory: true).standardizedFileURL.path
// pass-through the "--scratch-path" flag to the underlying build command
if let scratchPath = toolchainOptions.scratchPath {
// Generated SwiftUI aliases need a products directory without the old unaliased shim.
let scratchPath = swiftScratchPath
if let scratchPath {
cmd += ["--scratch-path", scratchPath]
}
// pass-through the "--configuration" flag to the underlying build command
Expand Down Expand Up @@ -995,7 +1000,7 @@ extension AndroidOperationCommand {
if let packagePath = toolchainOptions.packagePath {
binPathCmd += ["--package-path", packagePath]
}
if let scratchPath = toolchainOptions.scratchPath {
if let scratchPath {
binPathCmd += ["--scratch-path", scratchPath]
}
if let configuration = toolchainOptions.configuration {
Expand Down Expand Up @@ -1067,7 +1072,7 @@ extension AndroidOperationCommand {
} else {
// Fallback to the legacy path construction
buildOutputFolder = [
toolchainOptions.scratchPath ?? (packageDir + "/.build"),
swiftScratchPath ?? (packageDir + "/.build"),
arch.tripleKey(api: toolchainOptions.androidAPILevel, sdkVersion: tc.swiftSDKVersion),
buildConfig.rawValue,
].joined(separator: "/")
Expand Down
4 changes: 2 additions & 2 deletions skipstone/Sources/SkipBuild/Commands/AndroidTestCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ fileprivate extension AndroidOperationCommand {
buildOutputFolder = binPath
} else {
buildOutputFolder = [
toolchainOptions.scratchPath ?? (packageDir + "/.build"),
swiftScratchPath ?? (packageDir + "/.build"),
arch.tripleKey(api: apiLevel, sdkVersion: tc.swiftSDKVersion),
buildConfig.rawValue,
].joined(separator: "/")
Expand Down Expand Up @@ -743,7 +743,7 @@ fileprivate extension AndroidOperationCommand {
let apiLevel = toolchainOptions.androidAPILevel
let tc = try buildToolchainConfiguration(for: arch)
let swiftCmd = tc.toolchainPath.appendingPathComponent("usr/bin/swift", isDirectory: false).path
let scratch = toolchainOptions.scratchPath ?? (packageDir + "/.build")
let scratch = swiftScratchPath ?? (packageDir + "/.build")
let buildSystemArgs = args

return TestLibsTarget(
Expand Down
4 changes: 4 additions & 0 deletions skipstone/Sources/SkipBuild/Commands/SkipstoneCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,10 @@ struct SkipstoneCommand: BuildPluginOptionsCommand, StreamingCommand {
"""
}

if createdIds.contains("skip-fuse-ui") {
packageAddendum += AndroidSwiftUIImports.packageAddendum
}

// Targets can use a custom path, including a test package nested inside the
// component package. Mirror the target's owning package, not a fixed ancestor.
let mirrorSource = try Self.packageRoot(containing: projectFolderPath, fs: fs)
Expand Down
Loading
Loading