Skip to content

Commit a90aa9a

Browse files
authored
Fix syntax highlighting in SE-0339 (#2310)
1 parent 8c06e6f commit a90aa9a

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

proposals/0339-module-aliasing-for-disambiguation.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,29 @@ App
3737

3838
The modules from each package have the following code:
3939

40-
```
40+
```swift
4141
[Module Game] // swift-game
4242

4343
import Utils // swift-game
4444
public func start(level: Utils.Level) { ... }
4545
```
4646

47-
```
47+
```swift
4848
[Module Utils] // swift-game
4949

5050
public struct Level { ... }
5151
public var currentLevel: Utils.Level { ... }
5252
```
5353

54-
```
54+
```swift
5555
[Module Utils] // swift-draw
5656

5757
public protocol Drawable { ... }
5858
public class Canvas: Utils.Drawable { ... }
5959
```
6060

6161
Since `App` depends on these two `Utils` modules, we have a conflict, thus we need to rename one. We will introduce a new setting in SwiftPM called `moduleAliases` that will allow setting unique names for dependencies, like so:
62-
```
62+
```swift
6363
targets: [
6464
.executableTarget(
6565
name: "App",
@@ -71,7 +71,7 @@ Since `App` depends on these two `Utils` modules, we have a conflict, thus we ne
7171
```
7272

7373
The setting `moduleAliases` will rename `Utils` from the `swift-game` package as `GameUtils` and alias all its references in the source code to be compiled as `GameUtils`. Since renaming one of the `Utils` modules will resolve the conflict, it is not necessary to rename the other `Utils` module. The references to `Utils` in the `Game` module will be built as `GameUtils` without requiring any source changes. If `App` needs to reference both `Utils` modules in its source code, it can do so by directly including the aliased name:
74-
```
74+
```swift
7575
[App]
7676

7777
import GameUtils
@@ -130,8 +130,8 @@ App
130130

131131
Here are the manifest examples for `swift-game` and `swift-draw`.
132132

133-
```
134-
{
133+
```swift
134+
let package = Package(
135135
name: "swift-game",
136136
dependencies: [],
137137
products: [
@@ -142,11 +142,11 @@ Here are the manifest examples for `swift-game` and `swift-draw`.
142142
.target(name: "Game", dependencies: ["Utils"]),
143143
.target(name: "Utils", dependencies: [])
144144
]
145-
}
145+
)
146146
```
147147

148-
```
149-
{
148+
```swift
149+
let package = Package(
150150
name: "swift-draw",
151151
dependencies: [],
152152
products: [
@@ -155,12 +155,12 @@ Here are the manifest examples for `swift-game` and `swift-draw`.
155155
targets: [
156156
.target(name: "Utils", dependencies: [])
157157
]
158-
}
158+
)
159159
```
160160

161161
The `App` manifest needs to explicitly define unique names for the conflicting modules via a new parameter called `moduleAliases`.
162-
```
163-
{
162+
```swift
163+
let package = Package(
164164
name: "App",
165165
dependencies: [
166166
.package(url: https://.../swift-game.git),
@@ -177,15 +177,15 @@ The `App` manifest needs to explicitly define unique names for the conflicting m
177177
.product(name: "Utils", package: "swift-draw"),
178178
])
179179
]
180-
}
180+
)
181181
```
182182

183183
SwiftPM will perform validations when it parses `moduleAliases`; for each entry, it will check whether the given alias is a unique name, whether there is a conflict among aliases, whether the specified module is built from source (pre-compiled modules cannot be rebuilt to respect the rename), and whether the module is a pure Swift module (see **Requirements/Limitations** section for more details).
184184

185185
It will also check if any aliases are defined in upstream packages and override them if necessary. For example, if the `swift-game` package were modified per below and defined its own alias `SwiftUtils` for module `Utils` from a dependency package, the alias defined in `App` will override it, thus the `Utils` module from `swift-utils` will be built as `GameUtils`.
186186

187-
```
188-
{
187+
```swift
188+
let package = Package(
189189
name: "swift-game",
190190
dependencies: [
191191
.package(url: https://.../swift-utils.git),
@@ -201,7 +201,7 @@ It will also check if any aliases are defined in upstream packages and override
201201
moduleAliases: ["Utils": "SwiftUtils"]),
202202
])
203203
]
204-
}
204+
)
205205
```
206206

207207
Once the validation and alias overriding steps pass, dependency resolution will take place using the new module names, and the `-module-alias [name]=[new_name]` flag will be passed to the build execution.

0 commit comments

Comments
 (0)