Giter Site home page Giter Site logo

toolchains_riscv_gnu's Introduction

GitHub license GitHub stars GitHub issues CI

The goal of the project is to make cross compilation toolchains readily available (and customizable) for bazel developers.

If this project was useful to you, give it a ⭐️ and I'll keep improving it!

Features

Use the toolchain from this repo

.bazelrc

And this to your .bazelrc

# .bazelrc

# Build using platforms by default
build --incompatible_enable_cc_toolchain_resolution

MODULE

bazel_dep(name = "toolchains_riscv_gnu", version = "<module_version>")

riscv_toolchain = use_extension("@toolchains_riscv_gnu//:extensions.bzl", "riscv_toolchain")
riscv_toolchain.riscv_none_elf()
use_repo(riscv_toolchain, "riscv_none_elf")

register_toolchains("@riscv_none_elf//toolchain:all")

WORKSPACE

Add this git repository to your WORKSPACE to use the compiler

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_cc",
    sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf",
    strip_prefix = "rules_cc-0.0.9",
    urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz"],
)

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
    name = "toolchains_riscv_gnu",
    remote = "https://github.com/hexdae/toolchains_riscv_gnu",
    branch = "main",
)

load("@toolchains_riscv_gnu//:deps.bzl", "riscv_none_elf_deps")
riscv_none_elf_deps()
register_toolchains("@riscv_none_elf//toolchain:all")

Now Bazel will automatically use riscv-none-elf-gcc as a compiler.

Custom toolchain

If you want to bake certain compiler flags in to your toolchain, you can define a custom toolchain in your repo.

In a BUILD file:

# path/to/toolchains/BUILD

load("@riscv_none_elf//toolchain:toolchain.bzl", "riscv_none_elf_toolchain")
riscv_none_elf_toolchain(
    name = "custom_toolchain",
    target_compatible_with = [
        "<your additional constraints>",
    ],
    copts = [
        "<your additional copts>",
    ],
    linkopts = [
        "<your additional linkopts>",
    ],
)

And in your WORKSPACE / MODULE file:

register_toolchains("//path/to/toolchains:all")

Be careful about registering the default toolchains when using a custom one

Direct access to gcc tools

If you need direct access to gcc tools, they are available as @riscv_none_elf//:<tool>. For example, the following genrules could be used to produce .bin and .hex artifacts from a generic .out target.

cc_binary(
    name = "target.out"
    srcs = [...],
    deps = [...],
    copts = [...],
    ...
)

genrule(
    name = "bin",
    srcs = [":target.out"],
    outs = ["target.bin"],
    cmd = "$(execpath @riscv_none_elf//:objcopy) -O binary $< $@",
    tools = ["@riscv_none_elf//:objcopy"],
)

genrule(
    name = "hex",
    srcs = [":target.out"],
    outs = ["target.hex"],
    cmd = "$(execpath @riscv_none_elf//:objcopy) -O ihex $< $@",
    tools = ["@riscv_none_elf//:objcopy"],
)

Remote execution

This toolchain is compatible with remote execution, see remote.yml

toolchains_riscv_gnu's People

Contributors

hexdae avatar

Stargazers

 avatar sooriya avatar fengchunsong avatar Suraj avatar Elisa Cadamuro avatar Hex avatar Sarang Zambare avatar Lenny Khazan avatar  avatar

Watchers

 avatar

toolchains_riscv_gnu's Issues

no matching toolchains found for types @bazel_tools//tools/jdk:runtime_toolchain_type

environment:

$ cat /etc/os-release
NAME="openEuler"
VERSION="24.03 (LTS)"
ID="openEuler"
VERSION_ID="24.03"
PRETTY_NAME="openEuler 24.03 (LTS)"
ANSI_COLOR="0;31"
$ uname -a
Linux openeuler-riscv64-worker1 6.6.0 bazelbuild/bazel#1 SMP Tue Jul 2 11:21:06 CST 2024 riscv64 riscv64 riscv64 GNU/Linux

steps:

git clone https://github.com/bazelbuild/bazel.git
cd bazel
git checkout tags/6.1.0
bazel build //src:bazel

bug:

$ bazel build //src:bazel
Starting local Bazel server and connecting to it...
... still trying to connect to local Bazel server after 10 seconds ...
... still trying to connect to local Bazel server after 20 seconds ...
... still trying to connect to local Bazel server after 30 seconds ...
... still trying to connect to local Bazel server after 40 seconds ...
... still trying to connect to local Bazel server after 50 seconds ...
... still trying to connect to local Bazel server after 60 seconds ...
... still trying to connect to local Bazel server after 70 seconds ...
DEBUG: /home/tf/.cache/bazel/_bazel_tf/df2e2a63529870a88d6ad4f4a2babaae/external/build_bazel_rules_nodejs/index.bzl:122:10: WARNING: check_rules_nodejs_version has been removed. This is a no-op, please remove the call.
ERROR: /home/tf/.cache/bazel/_bazel_tf/df2e2a63529870a88d6ad4f4a2babaae/external/bazel_tools/tools/jdk/BUILD:29:19: While resolving toolchains for target @bazel_tools//tools/jdk:current_java_runtime: no matching toolchains found for types @bazel_tools//tools/jdk:runtime_toolchain_type
ERROR: Analysis of target '//src:bazel' failed; build aborted:
INFO: Elapsed time: 239.920s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (186 packages loaded, 1709 targets configured)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.