Skip to content

Commit

Permalink
Add bazel support to Yams (#302)
Browse files Browse the repository at this point in the history
Also add a GitHub action to ensure builds are working.

Validated on all Apple platforms and Linux.
  • Loading branch information
tinder-maxwellelliott committed Mar 22, 2021
1 parent 938a037 commit 6780f31
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
@@ -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
72 changes: 72 additions & 0 deletions .github/workflows/bazel.yml
@@ -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
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -58,7 +58,7 @@ Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md
Expand All @@ -69,3 +69,6 @@ fastlane/screenshots
# Docs
docs
.swiftpm

# Bazel
bazel-*
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -6,11 +6,12 @@

##### Enhancements

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

##### Bug Fixes

* None.
* None.

## 4.0.4

Expand Down
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -49,6 +49,21 @@ Add `pod 'Yams'` to your `Podfile`.

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

Yams has three groups of conversion APIs:
Expand Down
15 changes: 15 additions & 0 deletions Sources/CYaml/BUILD
@@ -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__",
],
)
12 changes: 12 additions & 0 deletions Sources/Yams/BUILD
@@ -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"],
)
66 changes: 66 additions & 0 deletions Tests/BUILD
@@ -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",
],
)
11 changes: 7 additions & 4 deletions Tests/YamsTests/PerformanceTests.swift
Expand Up @@ -10,10 +10,13 @@ import Foundation
import XCTest
import Yams

private let fixturesDirectory = URL(fileURLWithPath: #file).deletingLastPathComponent().path + "/Fixtures/"

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 expectedOtherArguments = [
"-j8", "-D", "SWIFT_PACKAGE", "-Onone", "-g", "-enable-testing",
Expand Down Expand Up @@ -58,7 +61,7 @@ class PerformanceTests: XCTestCase {
]

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)!
}

Expand Down
29 changes: 29 additions & 0 deletions WORKSPACE
@@ -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()

0 comments on commit 6780f31

Please sign in to comment.