Skip to content

Commit

Permalink
Adds aarch64_none_linux_gnu support (#49)
Browse files Browse the repository at this point in the history
* Rebased from https://github.com/hexdae/bazel-arm-none-eabi/actions/runs/8789248662

* [AARCH64][LINUX] add test

* [AARCH64][LINUX] test on windows

* [AARCH64][LINUX] fix windows

---------

Co-authored-by: d-asnaghi <30296575+hexdae@users.noreply.github.com>
  • Loading branch information
makestuffwork and hexdae committed Apr 23, 2024
1 parent 80c1f68 commit 3061c51
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
USE_BAZEL_VERSION: "7.x"
steps:
- uses: actions/checkout@v2
- name: tests
run: bazel test //test:all
- name: workspace
working-directory: examples/workspace
run: bazel test //:all
Expand All @@ -51,7 +53,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: BUILD
run: bazel --output_user_root=C:/bzl build //...
run: bazel --output_user_root=C:/bzl test //test:all

remote-execution:
name: Bazel Remote Execution
Expand Down
15 changes: 6 additions & 9 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,35 @@

module(
name = "toolchains_arm_gnu",
compatibility_level = 1,
version = "1.0.0",
compatibility_level = 1,
)

bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "rules_cc", version = "0.0.9")

# DEV ONLY (not needed for release)
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")
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)

arm_toolchain = use_extension(
"@toolchains_arm_gnu//:extensions.bzl",
"arm_toolchain",
dev_dependency = True,
)

arm_toolchain.arm_none_eabi()

use_repo(arm_toolchain, "arm_none_eabi")

arm_toolchain.arm_none_linux_gnueabihf()

use_repo(arm_toolchain, "arm_none_linux_gnueabihf")

arm_toolchain.aarch64_none_elf()

use_repo(arm_toolchain, "aarch64_none_elf")
arm_toolchain.aarch64_none_linux_gnu()
use_repo(arm_toolchain, "aarch64_none_linux_gnu")

register_toolchains(
"//test/toolchains:all",
"@aarch64_none_elf//toolchain:all",
"@aarch64_none_linux_gnu//toolchain:all",
"@arm_none_eabi//toolchain:all",
"@arm_none_linux_gnueabihf//toolchain:all",
dev_dependency = True,
Expand Down
85 changes: 78 additions & 7 deletions MODULE.bazel.lock

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

21 changes: 18 additions & 3 deletions deps.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""deps.bzl"""

load("@toolchains_arm_gnu//toolchain:toolchain.bzl", "tools")
load("@toolchains_arm_gnu//toolchain/archives:aarch64_none_elf.bzl", "AARCH64_NONE_ELF")
load("@toolchains_arm_gnu//toolchain/archives:aarch64_none_linux_gnu.bzl", "AARCH64_NONE_LINUX_GNU")
load("@toolchains_arm_gnu//toolchain/archives:arm_none_eabi.bzl", "ARM_NONE_EABI")
load("@toolchains_arm_gnu//toolchain/archives:arm_none_linux_gnueabihf.bzl", "ARM_NONE_LINUX_GNUEABIHF")
load("@toolchains_arm_gnu//toolchain/archives:aarch64_none_elf.bzl", "AARCH64_NONE_ELF")
load("@toolchains_arm_gnu//toolchain:toolchain.bzl", "tools")

def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx):
"""Defines a host-specific repository for the ARM GNU toolchain."""
Expand Down Expand Up @@ -148,7 +149,7 @@ def arm_none_linux_gnueabihf_deps(version = "13.2.1", archives = ARM_NONE_LINUX_
)

def aarch64_none_elf_deps(version = "13.2.1-1.1", archives = AARCH64_NONE_ELF):
"""Workspace dependencies for the arm linux gcc toolchain
"""Workspace dependencies for the arm gcc toolchain
Args:
version: The version of the toolchain to use. If None, the latest version is used.
Expand All @@ -160,3 +161,17 @@ def aarch64_none_elf_deps(version = "13.2.1-1.1", archives = AARCH64_NONE_ELF):
version,
archives,
)

def aarch64_none_linux_gnu_deps(version = "13.2.1", archives = AARCH64_NONE_LINUX_GNU):
"""Workspace dependencies for the arm linux gcc toolchain
Args:
version: The version of the toolchain to use. If None, the latest version is used.
archives: A dictionary of the version to archive attributes.
"""
toolchains_arm_gnu_deps(
"aarch64_none_linux_gnu",
"aarch64-none-linux-gnu",
version,
archives,
)
24 changes: 21 additions & 3 deletions extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
"""Module extension for toolchains"""

load("@toolchains_arm_gnu//toolchain/archives:arm_none_eabi.bzl", "ARM_NONE_EABI")
load("@toolchains_arm_gnu//toolchain/archives:arm_none_linux_gnueabihf.bzl", "ARM_NONE_LINUX_GNUEABIHF")
load("@toolchains_arm_gnu//toolchain/archives:aarch64_none_elf.bzl", "AARCH64_NONE_ELF")
load(
"@toolchains_arm_gnu//:deps.bzl",
"aarch64_none_elf_deps",
"aarch64_none_linux_gnu_deps",
"arm_none_eabi_deps",
"arm_none_linux_gnueabihf_deps",
)
load("@toolchains_arm_gnu//toolchain/archives:aarch64_none_elf.bzl", "AARCH64_NONE_ELF")
load(
"@toolchains_arm_gnu//toolchain/archives:aarch64_none_linux_gnu.bzl",
"AARCH64_NONE_LINUX_GNU",
)
load(
"@toolchains_arm_gnu//toolchain/archives:arm_none_eabi.bzl",
"ARM_NONE_EABI",
)
load(
"@toolchains_arm_gnu//toolchain/archives:arm_none_linux_gnueabihf.bzl",
"ARM_NONE_LINUX_GNUEABIHF",
)

def _semver(version):
"""Parse a semantic version string into a list of integers."""
Expand Down Expand Up @@ -75,6 +86,10 @@ def _arm_toolchain_impl(ctx):
tag = lambda mod: mod.tags.aarch64_none_elf,
deps = aarch64_none_elf_deps,
),
_module_toolchain(
tag = lambda mod: mod.tags.aarch64_none_linux_gnu,
deps = aarch64_none_linux_gnu_deps,
),
]

for toolchain in available_toolchains:
Expand All @@ -95,5 +110,8 @@ arm_toolchain = module_extension(
"aarch64_none_elf": tag_class(attrs = {
"version": attr.string(default = _max_version(AARCH64_NONE_ELF.keys())),
}),
"aarch64_none_linux_gnu": tag_class(attrs = {
"version": attr.string(default = _max_version(AARCH64_NONE_LINUX_GNU.keys())),
}),
},
)
5 changes: 5 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ build_test(
targets = ["//test/aarch64-none-elf:hex"],
)

build_test(
name = "aarch64_none_linux_gnu",
targets = ["//test/aarch64-none-linux-gnu:hex"],
)

build_test(
name = "arm_none_eabi",
targets = ["//test/arm-none-eabi:hex"],
Expand Down
59 changes: 59 additions & 0 deletions test/aarch64-none-linux-gnu/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# project/BUILD.bazel

load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

platform(
name = "aarch64_none_linux_gnu",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
)

cc_library(
name = "arm_library",
srcs = ["library.cpp"],
hdrs = ["library.h"],
copts = [
"-mcpu=cortex-a53",
],
includes = ["includes"],
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
)

cc_binary(
name = "arm_elf",
srcs = ["main.cpp"],
copts = [
"-mcpu=cortex-a53",
],
linkopts = [
"-nostartfiles",
"-Wl,--entry,main",
],
deps = [":arm_library"],
)

platform_transition_filegroup(
name = "elf",
srcs = [":arm_elf"],
target_compatible_with = select({
"@platforms//os:linux": ["@platforms//cpu:x86_64"], # linux x86 (no arm)
"@platforms//os:windows": ["@platforms//cpu:x86_64"], # windows
"//conditions:default": ["@platforms//:incompatible"],
}),
target_platform = ":aarch64_none_linux_gnu",
)

genrule(
name = "hex",
srcs = [":elf"],
outs = ["mock.hex"],
cmd = "$(execpath @aarch64_none_linux_gnu//:objcopy) -O ihex $< $@",
tools = ["@aarch64_none_linux_gnu//:objcopy"],
visibility = ["//visibility:public"],
)
15 changes: 15 additions & 0 deletions test/aarch64-none-linux-gnu/library.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "library.h"
#include <vector>

uint16_t baz(uint8_t a) { return a * 2; }

uint32_t foo() {
static constexpr int k = 5;
return baz(k);
}

uint16_t foobaz() {
std::vector<uint8_t> vec(10);
vec.push_back(1);
return vec[0];
}
Loading

0 comments on commit 3061c51

Please sign in to comment.