Skip to content

Commit 07c2eb5

Browse files
authored
Moves away from @_exported import to add the import in the generated code (#8637)
1 parent c7b9dc8 commit 07c2eb5

25 files changed

+110
-34
lines changed

grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// swiftlint:disable all
33
// swiftformat:disable all
44

5+
#if canImport(Common)
6+
import Common
7+
#endif
8+
59
import FlatBuffers
610

711
public struct models_HelloReply: FlatBufferObject, Verifiable {

samples/monster_generated.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// swiftlint:disable all
33
// swiftformat:disable all
44

5+
#if canImport(Common)
6+
import Common
7+
#endif
8+
59
import FlatBuffers
610

711
public enum MyGame_Sample_Color: Int8, Enum, Verifiable {

src/idl_gen_swift.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ class SwiftGenerator : public BaseGenerator {
174174
code_ += "// swiftlint:disable all";
175175
code_ += "// swiftformat:disable all\n";
176176
if (parser_.opts.include_dependence_headers || parser_.opts.generate_all) {
177-
if (parser_.opts.swift_implementation_only)
178-
code_ += "@_implementationOnly \\";
179-
180-
code_ += "import FlatBuffers\n";
177+
code_.SetValue("IMPLEMENTONLY", parser_.opts.swift_implementation_only ? "@_implementationOnly " : "");
178+
code_ += "#if canImport(Common)";
179+
code_ += "{{IMPLEMENTONLY}}import Common";
180+
code_ += "#endif";
181+
code_ += "";
182+
code_ += "{{IMPLEMENTONLY}}import FlatBuffers\n";
181183
}
182184

183185
// Generate code for all the enum declarations.

swift/Sources/FlatBuffers/Constants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
#if canImport(Common)
18-
@_exported import Common
18+
import Common
1919
#endif
2020
import Foundation
2121

swift/Sources/FlatBuffers/Enum.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
#if canImport(Common)
17+
import Common
18+
#endif
1619

1720
import Foundation
1821

swift/Sources/FlatBuffers/FlatBufferBuilder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
#if canImport(Common)
17+
import Common
18+
#endif
1619

1720
import Foundation
1821

swift/Sources/FlatBuffers/Mutable.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
#if canImport(Common)
17+
import Common
18+
#endif
1619

1720
import Foundation
1821

swift/Sources/FlatBuffers/Struct.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
#if canImport(Common)
17+
import Common
18+
#endif
1619

1720
import Foundation
1821

swift/Sources/FlatBuffers/Table.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
#if canImport(Common)
17+
import Common
18+
#endif
1619

1720
import Foundation
1821

swift/Sources/FlatBuffers/Verifiable.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
#if canImport(Common)
18+
import Common
19+
#endif
20+
1721
import Foundation
1822

1923
/// Verifiable is a protocol all swift flatbuffers object should conform to,

0 commit comments

Comments
 (0)