Skip to content

Commit

Permalink
[CI] add workspace (#34)
Browse files Browse the repository at this point in the history
* [WORKSPACE] add support again

* [WORKSPACE] add smoke test

* [WORKSPACE] right CI

* [WORKSPACE] simple test

* [BAZELMOD] add smoke test

* [BAZELMOD] rename e2e test

* [CI] add e2e.

* [CI] fix module.

* [CI] run E2E multiplatform.

* [CI] simple CI.

* [CI] simple matrix.

* [CI] include windows.

* [CI] add custom toolchain.

* [CI] clean bre

* [FORMAT] build files

* [CI] fix windows

* [CI] disable bazelmod in WORKSPACE

* [CI] try windows bazel mod

* [CI] try windows output path

* [CI] use bash on windows

* [CI] windows separate

* [CI] run windows with bazelisk

* [README] update badges

* [CI] fix linux targets

* [CI] single bazel version

* [CI] no matrix version

* [CI] windows concurrency
  • Loading branch information
hexdae authored Mar 28, 2024
1 parent 30def27 commit 8f60491
Show file tree
Hide file tree
Showing 47 changed files with 2,950 additions and 31 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e2e/
19 changes: 14 additions & 5 deletions .github/workflows/remote.yml → .github/workflows/bre.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
name: Remote
name: BRE

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
workflow_dispatch:

jobs:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
linux:
name: Bazel Remote Execution
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: remote execution

- name: run nativelink
run: |
cargo install --git https://github.com/TraceMachina/nativelink --tag v0.2.0
(nativelink .github/bre/basic_cas.json &)
- name: remote execution
run: |
bazelisk build --config=remote --config=linux //examples/...
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
e2e-test-multi-bazel:
name: ${{ matrix.env.TARGET }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
env:
TARGET: "x86_64-unknown-linux-gnu"
- os: ubuntu-latest
env:
TARGET: "aarch64-unknown-linux-gnu"
- os: macos-latest
env:
TARGET: "x86_64-apple-darwin"
- os: macos-latest
env:
TARGET: "aarch64-apple-darwin"

env:
USE_BAZEL_VERSION: "7.x"

steps:
- uses: actions/checkout@v2

- name: run e2e tests - workspace
working-directory: e2e/workspace
run: |
bazel test //...
- name: run e2e tests - bzlmod
working-directory: e2e/bzlmod
run: |
bazel test //...
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
name: Windows
name: PC

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:

windows:
name: Build
name: x86_64-pc-windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 6 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module(
name = "arm_gnu_toolchain",
version = "0.0.1",
compatibility_level = 1,
version = "0.0.1",
)

bazel_dep(name = "platforms", version = "0.0.8")
Expand All @@ -16,6 +16,7 @@ arm_toolchain = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_toolch
# module extension will select the version here if a consumer attempts to use
# the newer toolchain.
arm_toolchain.arm_none_eabi(version = "13.2.1")

use_repo(
arm_toolchain,
"arm_none_eabi",
Expand All @@ -25,7 +26,9 @@ use_repo(
"arm_none_eabi_linux_x86_64",
"arm_none_eabi_windows_x86_64",
)

arm_toolchain.arm_none_linux_gnueabihf(version = "13.2.1")

use_repo(
arm_toolchain,
"arm_none_linux_gnueabihf",
Expand All @@ -35,8 +38,8 @@ use_repo(
)

# DEV ONLY (not needed for release)
bazel_dep(name = "aspect_bazel_lib", version = "2.0.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", dev_dependency = True, version = "2.0.0")
bazel_dep(name = "bazel_skylib", dev_dependency = True, version = "1.5.0")

register_toolchains(
"@arm_none_eabi//toolchain:all",
Expand Down
6 changes: 3 additions & 3 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@
</a>

<a href="https://github.com/d-asnaghi/bazel-arm-none-eabi/actions">
<img alt="Linux" src="https://github.com/d-asnaghi/bazel-arm-none-eabi/workflows/Linux/badge.svg">
<img alt="CI" src="https://github.com/hexdae/bazel-arm-none-eabi/actions/workflows/ci.yml/badge.svg">
</a>

<a href="https://github.com/d-asnaghi/bazel-arm-none-eabi/actions">
<img alt="macOS" src="https://github.com/d-asnaghi/bazel-arm-none-eabi/workflows/macOS/badge.svg">
</a>

<a href="https://github.com/d-asnaghi/bazel-arm-none-eabi/actions">
<img alt="Widnows" src="https://github.com/d-asnaghi/bazel-arm-none-eabi/workflows/Windows/badge.svg">
<img alt="Windows" src="https://github.com/d-asnaghi/bazel-arm-none-eabi/workflows/Windows/badge.svg">
</a>

</p>
Expand All @@ -41,7 +37,8 @@ You can follow the post [Bazel for ARM embedded toolchains](https://asnaghi.me/p

## Features

- Simple integration with WORKSPACE / MODULE [experimental]
- [MODULE support](#bzlmod)
- [WORKSPACE support](#workspace)
- [Direct access to gcc tools](#direct-access-to-gcc-tools)
- [Custom toolchain support](#custom-toolchain)
- Remote execution support
Expand All @@ -65,12 +62,13 @@ build --platforms=@arm_gnu_toolchain//platforms:arm_none_generic

```python
# MODULE.bazel

bazel_dep(name = "arm_gnu_toolchain", version = "0.0.1")

git_override(
module_name = "arm_gnu_toolchain",
remote = "https://github.com/hexdae/bazel-arm-none-eabi",
commit = "<commit>", # <-- Change this to the commit you want
branch = "master",
)

# Toolchains: arm-none-eabi
Expand Down Expand Up @@ -101,7 +99,7 @@ use_repo(
register_toolchains("@arm_none_linux_gnueabihf//toolchain:all")
```

## WORKSPACE [soon to be deprecated]
## WORKSPACE

Add this git repository to your WORKSPACE to use the compiler

Expand All @@ -110,17 +108,27 @@ Add this git repository to your WORKSPACE to use the compiler

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "rules_cc",
remote = "https://github.com/bazelbuild/rules_cc",
branch = "main",
)

git_repository(
name = "arm_none_eabi",
commit = "<commit>",
remote = "https://github.com/hexdae/bazel-arm-none-eabi",
branch = "master",
)

# Toolchain: arm-none-eabi
load("@arm_gnu_toolchain//:deps.bzl", "arm_none_eabi_deps", "register_default_arm_none_eabi_toolchains")

arm_none_eabi_deps()

register_default_arm_none_eabi_toolchains()

# Toolchain arm-none-linux-gnueabihf
load("@arm_gnu_toolchain//:deps.bzl", "arm_none_linux_gnueabihf_deps", "register_default_arm_none_linux_gnueabihf_toolchains")
arm_none_linux_gnueabihf_deps()
register_default_arm_none_linux_gnueabihf_toolchains()
```

Now Bazel will automatically use `arm-none-eabi-gcc` as a compiler.
Expand Down
17 changes: 13 additions & 4 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,12 @@ def arm_gnu_toolchain_deps(toolchain, toolchain_prefix, version, archives):
**attrs
)

def register_default_arm_gnu_toolchains(toolchain_prefix):
def register_default_arm_gnu_toolchains(repo, toolchain_prefix):
for cpu in target_constraints[toolchain_prefix]:
register_arm_gnu_toolchain("//toolchain:{}".format(cpu))
register_arm_gnu_toolchain(
name = "@{}//toolchain:{}".format(repo, cpu),
prefix = toolchain_prefix,
)

# arm-none-eabi

Expand All @@ -200,7 +203,10 @@ def arm_none_eabi_deps(version = "13.2.1", archives = GCC_ARM_NONE_EABI):
)

def register_default_arm_none_eabi_toolchains():
register_default_arm_gnu_toolchains("arm-none-eabi")
register_default_arm_gnu_toolchains(
repo = "arm_none_eabi",
toolchain_prefix = "arm-none-eabi",
)

# arm-none-linux-gnueabihf

Expand All @@ -219,4 +225,7 @@ def arm_none_linux_gnueabihf_deps(version = "13.2.1", archives = GCC_ARM_NONE_LI
)

def register_default_arm_none_linux_gnueabihf_toolchains():
register_default_arm_gnu_toolchains("arm-none-linux-gnueabihf")
register_default_arm_gnu_toolchains(
repo = "arm_none_linux_gnueabihf",
toolchain_prefix = "arm-none-linux-gnueabihf",
)
2 changes: 2 additions & 0 deletions e2e/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build --incompatible_enable_cc_toolchain_resolution
build --enable_bzlmod=true
23 changes: 23 additions & 0 deletions e2e/bzlmod/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Provides a simple way to test your rules as an external workspace.
Add a basic smoke-test target below.
"""

load("@bazel_skylib//rules:build_test.bzl", "build_test")

build_test(
name = "arm_linux_test",
targets = ["//arm-linux:hex"],
)

build_test(
name = "arm_none_test",
targets = ["//arm-none:hex"],
)

build_test(
name = "custom_toolchain_test",
targets = [
"//custom:cortex_m4_elf",
"//custom:cortex_m3_elf",
],
)
45 changes: 45 additions & 0 deletions e2e/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""ARM cross compilation toolchains for bazel"""

module(
name = "smoke",
version = "0.0.1",
)

bazel_dep(name = "aspect_bazel_lib", version = "2.0.0")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "arm_gnu_toolchain")

local_path_override(
module_name = "arm_gnu_toolchain",
path = "../..",
)

arm_toolchain = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_toolchain")

arm_toolchain.arm_none_eabi(version = "13.2.1")

use_repo(
arm_toolchain,
"arm_none_eabi",
"arm_none_eabi_darwin_arm64",
"arm_none_eabi_darwin_x86_64",
"arm_none_eabi_linux_aarch64",
"arm_none_eabi_linux_x86_64",
"arm_none_eabi_windows_x86_64",
)

arm_toolchain.arm_none_linux_gnueabihf(version = "13.2.1")

use_repo(
arm_toolchain,
"arm_none_linux_gnueabihf",
"arm_none_linux_gnueabihf_linux_aarch64",
"arm_none_linux_gnueabihf_linux_x86_64",
"arm_none_linux_gnueabihf_windows_x86_64",
)

register_toolchains(
"@arm_none_eabi//toolchain:all",
"@arm_none_linux_gnueabihf//toolchain:all",
"//custom/toolchain:all",
)
Loading

0 comments on commit 8f60491

Please sign in to comment.