From c8250f6aa4c7613f97ab4e4cd925bb7967dbbb6a Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 18 Sep 2026 15:07:05 +0300 Subject: [PATCH] Tweak the BuildSDK command line tool now that ElementCall also links the SDK --- .gitignore | 3 +++ Tools/Sources/Commands/BuildSDK.swift | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bce983a6d..05265eb34 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ test_output # Only commit Pkl packages (there may be other caches in here). Components/Secrets/vendor/* !Components/Secrets/vendor/package-2 + +# Local SDK development override +matrix-rust-components-swift diff --git a/Tools/Sources/Commands/BuildSDK.swift b/Tools/Sources/Commands/BuildSDK.swift index 21da92cee..3bdcff55c 100644 --- a/Tools/Sources/Commands/BuildSDK.swift +++ b/Tools/Sources/Commands/BuildSDK.swift @@ -17,6 +17,9 @@ enum Target: String, ExpressibleByArgument, CaseIterable { struct BuildSDK: AsyncParsableCommand { static let configuration = CommandConfiguration(abstract: "A tool to checkout and build MatrixRustSDK locally for development.") + /// The name of the symlink to the SDK, which must match the identity of the released package. + static let symlinkName = "matrix-rust-components-swift" + @Argument(help: "An optional argument to specify a branch of the SDK.") var branch: String? @@ -111,17 +114,27 @@ struct BuildSDK: AsyncParsableCommand { /// Update the Xcode project to use the build of the SDK. func updateXcodeProject() throws { + try makeSymlinkIfNeeded() try updateProjectYAML() try Zsh.run(command: "xcodegen") } + /// Symlink the SDK as `matrix-rust-components-swift`. SwiftPM derives a local package's + /// identity from its directory name, so the link is what allows the build to override the + /// released components in both this project and its dependencies (such as ElementCall). + func makeSymlinkIfNeeded() throws { + let symlinkURL = URL.projectDirectory.appendingPathComponent(Self.symlinkName) + guard !FileManager.default.fileExists(atPath: symlinkURL.path) else { return } + try FileManager.default.createSymbolicLink(at: symlinkURL, withDestinationURL: .sdkDirectory) + } + /// Update project.yml with the local path of the SDK. func updateProjectYAML() throws { let yamlURL = URL.projectDirectory.appendingPathComponent("project.yml") let yamlString = try String(contentsOf: yamlURL, encoding: .utf8) guard var projectConfig = try Yams.compose(yaml: yamlString) else { throw Error.failureParsingProjectYAML } - projectConfig["packages"]?.mapping?["MatrixRustSDK"]? = ["path": "../matrix-rust-sdk"] + projectConfig["packages"]?.mapping?["MatrixRustSDK"]? = ["path": Node(Self.symlinkName)] let updatedYAMLString = try Yams.serialize(node: projectConfig) try updatedYAMLString.write(to: yamlURL, atomically: true, encoding: .utf8)