Skip to content

Commit 6780f31

Browse files
Add bazel support to Yams (jpsim#302)
Also add a GitHub action to ensure builds are working. Validated on all Apple platforms and Linux.
1 parent 938a037 commit 6780f31

File tree

10 files changed

+227
-7
lines changed

10 files changed

+227
-7
lines changed

.bazelrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Force the tests to not run in sandboxed mode, since it can introduce
2+
# errors and flakes.
3+
test --spawn_strategy=local
4+
build --macos_minimum_os=10.9

.github/workflows/bazel.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Bazel
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'Sources/**/*.[ch]'
8+
- 'Sources/**/*.swift'
9+
- 'Tests/**/*.swift'
10+
- 'Tests/**/*.ya?ml'
11+
- '**/BUILD'
12+
- 'WORKSPACE'
13+
pull_request:
14+
paths:
15+
- 'Sources/**/*.[ch]'
16+
- 'Sources/**/*.swift'
17+
- 'Tests/**/*.swift'
18+
- 'Tests/**/*.ya?ml'
19+
- '**/BUILD'
20+
- 'WORKSPACE'
21+
22+
jobs:
23+
MacOS:
24+
runs-on: macos-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: MacOS build test
28+
if: always()
29+
run: bazelisk test //Tests:macOSBuildTest
30+
shell: bash
31+
- name: WatchOS build test
32+
if: always()
33+
run: bazelisk test //Tests:watchOSBuildTest
34+
shell: bash
35+
- name: iOS build test
36+
if: always()
37+
run: bazelisk test //Tests:iOSBuildTest
38+
shell: bash
39+
- name: tvOS build test
40+
if: always()
41+
run: bazelisk test //Tests:tvOSBuildTest
42+
shell: bash
43+
- name: Yams tests
44+
if: always()
45+
run: bazelisk test //Tests:YamsTests
46+
shell: bash
47+
Linux:
48+
strategy:
49+
matrix:
50+
tag: ['5.1', '5.2', '5.3']
51+
runs-on: ubuntu-latest
52+
container:
53+
image: swift:${{ matrix.tag }}
54+
steps:
55+
- uses: actions/checkout@v2
56+
- uses: actions/setup-go@v2
57+
with:
58+
go-version: '^1.13.1' # The Go version to download (if necessary) and use.
59+
- name: Setup Bazel
60+
if: always()
61+
run: go get github.com/bazelbuild/bazelisk
62+
shell: bash
63+
- name: Yams tests
64+
if: always()
65+
run: |
66+
build_workspace_directory=$(bazelisk info workspace)
67+
CC=clang bazelisk test //Tests:YamsTests --action_env=PATH --test_env=BUILD_WORKSPACE_DIRECTORY=$build_workspace_directory
68+
shell: bash
69+
- name: Yams tests logs
70+
if: always()
71+
run: cat bazel-out/k8-fastbuild/testlogs/Tests/YamsTests/test.log
72+
shell: bash

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Carthage/Build
5858

5959
# fastlane
6060
#
61-
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
61+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
6262
# screenshots whenever they are needed.
6363
# For more information about the recommended setup visit:
6464
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md
@@ -69,3 +69,6 @@ fastlane/screenshots
6969
# Docs
7070
docs
7171
.swiftpm
72+
73+
# Bazel
74+
bazel-*

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
##### Enhancements
88

9-
* None.
9+
* Adds the ability to build Yams for Linux and MacOS via Bazel.
10+
[Maxwell Elliott](https://github.com/maxwellE)
1011

1112
##### Bug Fixes
1213

13-
* None.
14+
* None.
1415

1516
## 4.0.4
1617

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ Add `pod 'Yams'` to your `Podfile`.
4949

5050
Add `github "jpsim/Yams"` to your `Cartfile`.
5151

52+
### Bazel
53+
54+
In your WORKSPACE file
55+
56+
```WORKSPACE
57+
YAMS_GIT_SHA = "SOME_SHA"
58+
http_archive(
59+
name = "com_github_jpsim_yams",
60+
urls = [
61+
"https://github.com/jpsim/Yams/archive/%s.zip" % YAMS_GIT_SHA,
62+
],
63+
strip_prefix = "yams-%s" % YAMS_GIT_SHA,
64+
)
65+
```
66+
5267
## Usage
5368

5469
Yams has three groups of conversion APIs:

Sources/CYaml/BUILD

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load(
2+
"@rules_cc//cc:defs.bzl",
3+
"cc_library"
4+
)
5+
6+
cc_library(
7+
name = "CYaml",
8+
srcs = glob(["src/*.c", "src/*.h"]),
9+
hdrs = ["include/yaml.h"],
10+
includes = ["include"],
11+
visibility = [
12+
"//Sources/Yams:__pkg__",
13+
"//Tests:__subpackages__",
14+
],
15+
)

Sources/Yams/BUILD

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
2+
3+
swift_library(
4+
name = "Yams",
5+
module_name = "Yams",
6+
srcs = glob(["*.swift"]),
7+
copts = [
8+
"-DSWIFT_PACKAGE",
9+
],
10+
visibility = ["//visibility:public"],
11+
deps = ["//Sources/CYaml:CYaml"],
12+
)

Tests/BUILD

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_build_test")
2+
load("@build_bazel_rules_apple//apple:watchos.bzl", "watchos_build_test")
3+
load("@build_bazel_rules_apple//apple:tvos.bzl", "tvos_build_test")
4+
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_build_test")
5+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_test")
6+
7+
config_setting(
8+
name = "linux",
9+
constraint_values = ["@platforms//os:linux"],
10+
)
11+
12+
genrule(
13+
name = "LinuxMain",
14+
srcs = ["LinuxMain.swift"],
15+
outs = ["main.swift"],
16+
cmd = "cp $< $@"
17+
)
18+
19+
swift_test(
20+
name = "YamsTests",
21+
module_name = "YamsTests",
22+
srcs = glob(["YamsTests/*.swift"]) + select({
23+
":linux": ["main.swift"],
24+
"//conditions:default": [],
25+
}),
26+
data = glob(["YamsTests/Fixtures/**/*.*"]),
27+
deps = [
28+
"//Sources/Yams:Yams",
29+
],
30+
)
31+
32+
macos_build_test(
33+
name = "macOSBuildTest",
34+
minimum_os_version = "10.9",
35+
targets = [
36+
"//Sources/Yams:Yams",
37+
"//Sources/CYaml:CYaml",
38+
],
39+
)
40+
41+
watchos_build_test(
42+
name = "watchOSBuildTest",
43+
minimum_os_version = "2.0",
44+
targets = [
45+
"//Sources/Yams:Yams",
46+
"//Sources/CYaml:CYaml",
47+
],
48+
)
49+
50+
tvos_build_test(
51+
name = "tvOSBuildTest",
52+
minimum_os_version = "9.0",
53+
targets = [
54+
"//Sources/Yams:Yams",
55+
"//Sources/CYaml:CYaml",
56+
],
57+
)
58+
59+
ios_build_test(
60+
name = "iOSBuildTest",
61+
minimum_os_version = "8.0",
62+
targets = [
63+
"//Sources/Yams:Yams",
64+
"//Sources/CYaml:CYaml",
65+
],
66+
)

Tests/YamsTests/PerformanceTests.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import Foundation
1010
import XCTest
1111
import Yams
1212

13-
private let fixturesDirectory = URL(fileURLWithPath: #file).deletingLastPathComponent().path + "/Fixtures/"
14-
1513
class PerformanceTests: XCTestCase {
16-
let filename = fixturesDirectory + "SourceKitten#289/debug.yaml"
14+
private let fixturesDirectory: String = {
15+
if let buildWorkspace = ProcessInfo.processInfo.environment["BUILD_WORKSPACE_DIRECTORY"] {
16+
return "\(buildWorkspace)/Tests/YamsTests/Fixtures/"
17+
}
18+
return URL(fileURLWithPath: #file).deletingLastPathComponent().path + "/Fixtures/"
19+
}()
1720
let expectedImports = ["/SourceKitten/.build/debug"]
1821
let expectedOtherArguments = [
1922
"-j8", "-D", "SWIFT_PACKAGE", "-Onone", "-g", "-enable-testing",
@@ -58,7 +61,7 @@ class PerformanceTests: XCTestCase {
5861
]
5962

6063
func loadYAML() throws -> String {
61-
let data = try Data(contentsOf: URL(fileURLWithPath: filename))
64+
let data = try Data(contentsOf: URL(fileURLWithPath: fixturesDirectory + "/SourceKitten#289/debug.yaml"))
6265
return String(data: data, encoding: .utf8)!
6366
}
6467

WORKSPACE

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3+
4+
http_archive(
5+
name = "build_bazel_rules_apple",
6+
sha256 = "09423d57ace0fca1b84e19326dc9aadd42f2be52f1b5a15bc652d18c2c1dee71",
7+
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.30.0/rules_apple.0.30.0.tar.gz",
8+
)
9+
10+
load(
11+
"@build_bazel_rules_apple//apple:repositories.bzl",
12+
"apple_rules_dependencies",
13+
)
14+
15+
apple_rules_dependencies()
16+
17+
load(
18+
"@build_bazel_rules_swift//swift:repositories.bzl",
19+
"swift_rules_dependencies",
20+
)
21+
22+
swift_rules_dependencies()
23+
24+
load(
25+
"@build_bazel_rules_swift//swift:extras.bzl",
26+
"swift_rules_extra_dependencies",
27+
)
28+
29+
swift_rules_extra_dependencies()

0 commit comments

Comments
 (0)