Skip to content

Commit

Permalink
feat: Add Swift example
Browse files Browse the repository at this point in the history
  • Loading branch information
satreix committed May 1, 2023
1 parent bf84959 commit 4895b45
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build --cxxopt='-std=c++17'

# Ensure rules_haskell picks up the correct toolchain on Mac.
build --action_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
#build --action_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1

build --java_language_version=17
build --java_runtime_version=remotejdk_17
Expand Down
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ http_archive(
url = "https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-5.8.2.tar.gz",
)

http_archive(
name = "build_bazel_rules_swift",
sha256 = "bf2861de6bf75115288468f340b0c4609cc99cc1ccc7668f0f71adfd853eedb3",
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.7.1/rules_swift.1.7.1.tar.gz",
)

http_archive(
name = "bazelruby_rules_ruby",
patch_args = ["-p1"],
Expand Down Expand Up @@ -480,3 +486,11 @@ k8s_defaults(
cluster = "satreix",
kind = "deployment",
)

load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies")

swift_rules_dependencies()

load("@build_bazel_rules_swift//swift:extras.bzl", "swift_rules_extra_dependencies")

swift_rules_extra_dependencies()
12 changes: 12 additions & 0 deletions src/swift/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary")
load("//tools/test/binary:binary.bzl", "binary_test")

swift_binary(
name = "hello_world",
srcs = ["main.swift"],
)

binary_test(
name = "hello_world_test",
binary = ":hello_world",
)
7 changes: 7 additions & 0 deletions src/swift/hello_world/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var name = "World"

if let nameIndex = CommandLine.arguments.firstIndex(of: "--name"), nameIndex + 1 < CommandLine.arguments.count {
name = CommandLine.arguments[nameIndex + 1]
}

print("Hello, \(name)!")
Empty file added third_party/swift/BUILD.bazel
Empty file.

0 comments on commit 4895b45

Please sign in to comment.