aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Dmitry Shevchenko <dmishe@google.com>2016-04-22 20:46:07 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-04-22 21:21:02 +0000
commit2036dbd666a3e6430480bcbe333c77376d35bc63 (patch)
tree4f36f6cabb108be6b67cd16a40899c39462bdfee /examples
parente7be839c1ce7df2048b86bc956207f86db4e5b65 (diff)
Add a Skylark rule to build Swift modules.
* Adds a swift_library rule that produces a (.a, .swiftmodule) pair. It can handle dependencies between modules and can be used as a dependency of objc_binary. * Does not work with Objective-C yet. -- MOS_MIGRATED_REVID=120578875
Diffstat (limited to 'examples')
-rw-r--r--examples/BUILD1
-rw-r--r--examples/swift/BUILD19
-rw-r--r--examples/swift/BarLib/BUILD15
-rw-r--r--examples/swift/BarLib/mul.swift8
-rw-r--r--examples/swift/constants.swift4
-rw-r--r--examples/swift/foo.swift9
6 files changed, 56 insertions, 0 deletions
diff --git a/examples/BUILD b/examples/BUILD
index 8bfbc19524..781c81a46c 100644
--- a/examples/BUILD
+++ b/examples/BUILD
@@ -11,5 +11,6 @@ filegroup(
"//examples/py:srcs",
"//examples/py_native:srcs",
"//examples/shell:srcs",
+ "//examples/swift:srcs",
],
)
diff --git a/examples/swift/BUILD b/examples/swift/BUILD
new file mode 100644
index 0000000000..e2cbb195e2
--- /dev/null
+++ b/examples/swift/BUILD
@@ -0,0 +1,19 @@
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"]) # Apache 2.0
+
+load("//tools/build_defs/apple:swift.bzl", "swift_library")
+
+swift_library(
+ name = "swift_lib",
+ srcs = glob(["*.swift"]),
+ deps = ["//examples/swift/BarLib"],
+)
+
+filegroup(
+ name = "srcs",
+ srcs = glob(["**"]) + [
+ "//examples/swift/BarLib:srcs",
+ ],
+ visibility = ["//examples:__pkg__"],
+)
diff --git a/examples/swift/BarLib/BUILD b/examples/swift/BarLib/BUILD
new file mode 100644
index 0000000000..d575a879f1
--- /dev/null
+++ b/examples/swift/BarLib/BUILD
@@ -0,0 +1,15 @@
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"]) # Apache 2.0
+
+load("//tools/build_defs/apple:swift.bzl", "swift_library")
+
+swift_library(
+ name = "BarLib",
+ srcs = ["mul.swift"],
+)
+
+filegroup(
+ name = "srcs",
+ srcs = glob(["**"]),
+)
diff --git a/examples/swift/BarLib/mul.swift b/examples/swift/BarLib/mul.swift
new file mode 100644
index 0000000000..1f1df40512
--- /dev/null
+++ b/examples/swift/BarLib/mul.swift
@@ -0,0 +1,8 @@
+/// Class used to multiply stuff.
+public class Multiplier {
+ public init() {}
+
+ public func multiply(a: Int, _ b: Int) -> Int {
+ return a * b
+ }
+}
diff --git a/examples/swift/constants.swift b/examples/swift/constants.swift
new file mode 100644
index 0000000000..6c16d34a82
--- /dev/null
+++ b/examples/swift/constants.swift
@@ -0,0 +1,4 @@
+class Constants {
+ static var x = 2
+ static var y = 3
+} \ No newline at end of file
diff --git a/examples/swift/foo.swift b/examples/swift/foo.swift
new file mode 100644
index 0000000000..067c6730cd
--- /dev/null
+++ b/examples/swift/foo.swift
@@ -0,0 +1,9 @@
+import class BarLib.Multiplier
+
+public class Foo {
+ public init() {}
+
+ public func multiply() -> Int {
+ return Multiplier().multiply(Constants.x, Constants.y)
+ }
+}