Add bazel support to Yams (#302)
Also add a GitHub action to ensure builds are working. Validated on all Apple platforms and Linux.
This commit is contained in:
parent
938a037ba3
commit
6780f317eb
|
@ -0,0 +1,4 @@
|
||||||
|
# Force the tests to not run in sandboxed mode, since it can introduce
|
||||||
|
# errors and flakes.
|
||||||
|
test --spawn_strategy=local
|
||||||
|
build --macos_minimum_os=10.9
|
|
@ -0,0 +1,72 @@
|
||||||
|
name: Bazel
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'Sources/**/*.[ch]'
|
||||||
|
- 'Sources/**/*.swift'
|
||||||
|
- 'Tests/**/*.swift'
|
||||||
|
- 'Tests/**/*.ya?ml'
|
||||||
|
- '**/BUILD'
|
||||||
|
- 'WORKSPACE'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- 'Sources/**/*.[ch]'
|
||||||
|
- 'Sources/**/*.swift'
|
||||||
|
- 'Tests/**/*.swift'
|
||||||
|
- 'Tests/**/*.ya?ml'
|
||||||
|
- '**/BUILD'
|
||||||
|
- 'WORKSPACE'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
MacOS:
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: MacOS build test
|
||||||
|
if: always()
|
||||||
|
run: bazelisk test //Tests:macOSBuildTest
|
||||||
|
shell: bash
|
||||||
|
- name: WatchOS build test
|
||||||
|
if: always()
|
||||||
|
run: bazelisk test //Tests:watchOSBuildTest
|
||||||
|
shell: bash
|
||||||
|
- name: iOS build test
|
||||||
|
if: always()
|
||||||
|
run: bazelisk test //Tests:iOSBuildTest
|
||||||
|
shell: bash
|
||||||
|
- name: tvOS build test
|
||||||
|
if: always()
|
||||||
|
run: bazelisk test //Tests:tvOSBuildTest
|
||||||
|
shell: bash
|
||||||
|
- name: Yams tests
|
||||||
|
if: always()
|
||||||
|
run: bazelisk test //Tests:YamsTests
|
||||||
|
shell: bash
|
||||||
|
Linux:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
tag: ['5.1', '5.2', '5.3']
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: swift:${{ matrix.tag }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: '^1.13.1' # The Go version to download (if necessary) and use.
|
||||||
|
- name: Setup Bazel
|
||||||
|
if: always()
|
||||||
|
run: go get github.com/bazelbuild/bazelisk
|
||||||
|
shell: bash
|
||||||
|
- name: Yams tests
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
build_workspace_directory=$(bazelisk info workspace)
|
||||||
|
CC=clang bazelisk test //Tests:YamsTests --action_env=PATH --test_env=BUILD_WORKSPACE_DIRECTORY=$build_workspace_directory
|
||||||
|
shell: bash
|
||||||
|
- name: Yams tests logs
|
||||||
|
if: always()
|
||||||
|
run: cat bazel-out/k8-fastbuild/testlogs/Tests/YamsTests/test.log
|
||||||
|
shell: bash
|
|
@ -69,3 +69,6 @@ fastlane/screenshots
|
||||||
# Docs
|
# Docs
|
||||||
docs
|
docs
|
||||||
.swiftpm
|
.swiftpm
|
||||||
|
|
||||||
|
# Bazel
|
||||||
|
bazel-*
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
##### Enhancements
|
##### Enhancements
|
||||||
|
|
||||||
* None.
|
* Adds the ability to build Yams for Linux and MacOS via Bazel.
|
||||||
|
[Maxwell Elliott](https://github.com/maxwellE)
|
||||||
|
|
||||||
##### Bug Fixes
|
##### Bug Fixes
|
||||||
|
|
||||||
|
|
15
README.md
15
README.md
|
@ -49,6 +49,21 @@ Add `pod 'Yams'` to your `Podfile`.
|
||||||
|
|
||||||
Add `github "jpsim/Yams"` to your `Cartfile`.
|
Add `github "jpsim/Yams"` to your `Cartfile`.
|
||||||
|
|
||||||
|
### Bazel
|
||||||
|
|
||||||
|
In your WORKSPACE file
|
||||||
|
|
||||||
|
```WORKSPACE
|
||||||
|
YAMS_GIT_SHA = "SOME_SHA"
|
||||||
|
http_archive(
|
||||||
|
name = "com_github_jpsim_yams",
|
||||||
|
urls = [
|
||||||
|
"https://github.com/jpsim/Yams/archive/%s.zip" % YAMS_GIT_SHA,
|
||||||
|
],
|
||||||
|
strip_prefix = "yams-%s" % YAMS_GIT_SHA,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Yams has three groups of conversion APIs:
|
Yams has three groups of conversion APIs:
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
load(
|
||||||
|
"@rules_cc//cc:defs.bzl",
|
||||||
|
"cc_library"
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "CYaml",
|
||||||
|
srcs = glob(["src/*.c", "src/*.h"]),
|
||||||
|
hdrs = ["include/yaml.h"],
|
||||||
|
includes = ["include"],
|
||||||
|
visibility = [
|
||||||
|
"//Sources/Yams:__pkg__",
|
||||||
|
"//Tests:__subpackages__",
|
||||||
|
],
|
||||||
|
)
|
|
@ -0,0 +1,12 @@
|
||||||
|
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||||
|
|
||||||
|
swift_library(
|
||||||
|
name = "Yams",
|
||||||
|
module_name = "Yams",
|
||||||
|
srcs = glob(["*.swift"]),
|
||||||
|
copts = [
|
||||||
|
"-DSWIFT_PACKAGE",
|
||||||
|
],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["//Sources/CYaml:CYaml"],
|
||||||
|
)
|
|
@ -0,0 +1,66 @@
|
||||||
|
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_build_test")
|
||||||
|
load("@build_bazel_rules_apple//apple:watchos.bzl", "watchos_build_test")
|
||||||
|
load("@build_bazel_rules_apple//apple:tvos.bzl", "tvos_build_test")
|
||||||
|
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_build_test")
|
||||||
|
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_test")
|
||||||
|
|
||||||
|
config_setting(
|
||||||
|
name = "linux",
|
||||||
|
constraint_values = ["@platforms//os:linux"],
|
||||||
|
)
|
||||||
|
|
||||||
|
genrule(
|
||||||
|
name = "LinuxMain",
|
||||||
|
srcs = ["LinuxMain.swift"],
|
||||||
|
outs = ["main.swift"],
|
||||||
|
cmd = "cp $< $@"
|
||||||
|
)
|
||||||
|
|
||||||
|
swift_test(
|
||||||
|
name = "YamsTests",
|
||||||
|
module_name = "YamsTests",
|
||||||
|
srcs = glob(["YamsTests/*.swift"]) + select({
|
||||||
|
":linux": ["main.swift"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
data = glob(["YamsTests/Fixtures/**/*.*"]),
|
||||||
|
deps = [
|
||||||
|
"//Sources/Yams:Yams",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
macos_build_test(
|
||||||
|
name = "macOSBuildTest",
|
||||||
|
minimum_os_version = "10.9",
|
||||||
|
targets = [
|
||||||
|
"//Sources/Yams:Yams",
|
||||||
|
"//Sources/CYaml:CYaml",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
watchos_build_test(
|
||||||
|
name = "watchOSBuildTest",
|
||||||
|
minimum_os_version = "2.0",
|
||||||
|
targets = [
|
||||||
|
"//Sources/Yams:Yams",
|
||||||
|
"//Sources/CYaml:CYaml",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tvos_build_test(
|
||||||
|
name = "tvOSBuildTest",
|
||||||
|
minimum_os_version = "9.0",
|
||||||
|
targets = [
|
||||||
|
"//Sources/Yams:Yams",
|
||||||
|
"//Sources/CYaml:CYaml",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ios_build_test(
|
||||||
|
name = "iOSBuildTest",
|
||||||
|
minimum_os_version = "8.0",
|
||||||
|
targets = [
|
||||||
|
"//Sources/Yams:Yams",
|
||||||
|
"//Sources/CYaml:CYaml",
|
||||||
|
],
|
||||||
|
)
|
|
@ -10,10 +10,13 @@ import Foundation
|
||||||
import XCTest
|
import XCTest
|
||||||
import Yams
|
import Yams
|
||||||
|
|
||||||
private let fixturesDirectory = URL(fileURLWithPath: #file).deletingLastPathComponent().path + "/Fixtures/"
|
|
||||||
|
|
||||||
class PerformanceTests: XCTestCase {
|
class PerformanceTests: XCTestCase {
|
||||||
let filename = fixturesDirectory + "SourceKitten#289/debug.yaml"
|
private let fixturesDirectory: String = {
|
||||||
|
if let buildWorkspace = ProcessInfo.processInfo.environment["BUILD_WORKSPACE_DIRECTORY"] {
|
||||||
|
return "\(buildWorkspace)/Tests/YamsTests/Fixtures/"
|
||||||
|
}
|
||||||
|
return URL(fileURLWithPath: #file).deletingLastPathComponent().path + "/Fixtures/"
|
||||||
|
}()
|
||||||
let expectedImports = ["/SourceKitten/.build/debug"]
|
let expectedImports = ["/SourceKitten/.build/debug"]
|
||||||
let expectedOtherArguments = [
|
let expectedOtherArguments = [
|
||||||
"-j8", "-D", "SWIFT_PACKAGE", "-Onone", "-g", "-enable-testing",
|
"-j8", "-D", "SWIFT_PACKAGE", "-Onone", "-g", "-enable-testing",
|
||||||
|
@ -58,7 +61,7 @@ class PerformanceTests: XCTestCase {
|
||||||
]
|
]
|
||||||
|
|
||||||
func loadYAML() throws -> String {
|
func loadYAML() throws -> String {
|
||||||
let data = try Data(contentsOf: URL(fileURLWithPath: filename))
|
let data = try Data(contentsOf: URL(fileURLWithPath: fixturesDirectory + "/SourceKitten#289/debug.yaml"))
|
||||||
return String(data: data, encoding: .utf8)!
|
return String(data: data, encoding: .utf8)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "build_bazel_rules_apple",
|
||||||
|
sha256 = "09423d57ace0fca1b84e19326dc9aadd42f2be52f1b5a15bc652d18c2c1dee71",
|
||||||
|
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.30.0/rules_apple.0.30.0.tar.gz",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@build_bazel_rules_apple//apple:repositories.bzl",
|
||||||
|
"apple_rules_dependencies",
|
||||||
|
)
|
||||||
|
|
||||||
|
apple_rules_dependencies()
|
||||||
|
|
||||||
|
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()
|
Loading…
Reference in New Issue