Skip to content

Commit 1bb96ce

Browse files
committed
Instead of importing platform SDK modules, just use C shims
1 parent 1e07a56 commit 1bb96ce

File tree

6 files changed

+46
-48
lines changed

6 files changed

+46
-48
lines changed

Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#if swift(>=6.0)
14-
#if canImport(Darwin)
15-
private import Darwin
16-
#elseif canImport(Glibc)
17-
private import Glibc
18-
#elseif canImport(ucrt)
19-
private import ucrt
20-
#endif
14+
private import _SwiftSyntaxCShims
2115
#else
22-
#if canImport(Darwin)
23-
import Darwin
24-
#elseif canImport(Glibc)
25-
import Glibc
26-
#elseif canImport(ucrt)
27-
import ucrt
28-
#endif
16+
@_implementationOnly import _SwiftSyntaxCShims
2917
#endif
3018

3119
func decodeFromJSON<T: Decodable>(json: UnsafeBufferPointer<UInt8>) throws -> T {

Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,8 @@
1212

1313
#if swift(>=6.0)
1414
private import _SwiftSyntaxCShims
15-
#if canImport(Darwin)
16-
private import Darwin
17-
#elseif canImport(Glibc)
18-
private import Glibc
19-
#elseif canImport(ucrt)
20-
private import ucrt
21-
#endif
2215
#else
23-
import _SwiftSyntaxCShims
24-
#if canImport(Darwin)
25-
import Darwin
26-
#elseif canImport(Glibc)
27-
import Glibc
28-
#elseif canImport(ucrt)
29-
import ucrt
30-
#endif
16+
@_implementationOnly import _SwiftSyntaxCShims
3117
#endif
3218

3319
#if canImport(ucrt)

Sources/SwiftSyntax/SyntaxArena.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import _SwiftSyntaxCShims
13+
#if swift(>=6.0)
14+
private import _SwiftSyntaxCShims
15+
#else
16+
@_implementationOnly import _SwiftSyntaxCShims
17+
#endif
1418

1519
/// A syntax arena owns the memory for all syntax nodes within it.
1620
///

Sources/SwiftSyntax/SyntaxText.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#if swift(>=6.0)
14-
#if canImport(Darwin)
15-
private import Darwin
16-
#elseif canImport(Glibc)
17-
private import Glibc
18-
#elseif canImport(Musl)
19-
private import Musl
20-
#elseif canImport(ucrt)
21-
private import ucrt
22-
#endif
14+
private import _SwiftSyntaxCShims
2315
#else
24-
#if canImport(Darwin)
25-
import Darwin
26-
#elseif canImport(Glibc)
27-
import Glibc
28-
#elseif canImport(Musl)
29-
import Musl
30-
#elseif canImport(ucrt)
31-
import ucrt
32-
#endif
16+
@_implementationOnly import _SwiftSyntaxCShims
3317
#endif
3418

3519
/// Represent a string.

Sources/_SwiftSyntaxCShims/include/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module _SwiftSyntaxCShims {
2+
header "swiftsyntax/_includes.h"
23
header "swiftsyntax/AtomicBool.h"
34
header "swiftsyntax/errno.h"
45
header "swiftsyntax/stdio.h"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file is for, instead of importing platform modules in Swift file, like:
14+
//
15+
// #if canImport(Darwin)
16+
// import Darwin
17+
// #elseif canImport(Glibc)
18+
// import Glibc
19+
// ...
20+
//
21+
// Just include them here using C facilities, so that Swift module can just:
22+
//
23+
// import _SwiftSyntaxCShims
24+
//
25+
//===----------------------------------------------------------------------===//
26+
27+
#if defined(_WIN32)
28+
#include <io.h>
29+
#elif defined(__unix__) || defined(__APPLE__)
30+
#include <unistd.h>
31+
#endif
32+
33+
#include <stdio.h>
34+
#include <stdlib.h>
35+
#include <string.h>

0 commit comments

Comments
 (0)