Skip to content

Commit

Permalink
feat: gcc toolchain (#1)
Browse files Browse the repository at this point in the history
* feat: gcc toolchain

Signed-off-by: Thulio Ferraz Assis <[email protected]>

* fix: generated header

* fix: set -lstdc++ by default

Many libraries under Bazel rely on this behaviour by default.

Signed-off-by: Thulio Ferraz Assis <[email protected]>

* fix: set -I and -isystem flags

Signed-off-by: Thulio Ferraz Assis <[email protected]>

* feat: switch to use bootlin pre-compiled tools

Signed-off-by: Thulio Ferraz Assis <[email protected]>

* feat: explicit search dirs

Signed-off-by: Thulio Ferraz Assis <[email protected]>

* refactor: reduce hops and expose more attrs

Signed-off-by: Thulio Ferraz Assis <[email protected]>

* fix: use header substitution

Signed-off-by: Thulio Ferraz Assis <[email protected]>
  • Loading branch information
f0rmiga authored Mar 18, 2022
1 parent d4949f2 commit 579774a
Show file tree
Hide file tree
Showing 12 changed files with 805 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build --extra_toolchains=@gcc_toolchain//:toolchain --incompatible_enable_cc_toolchain_resolution

test --sandbox_default_allow_network=false
test --test_output=errors

build:debug --verbose_failures --sandbox_debug --toolchain_resolution_debug
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
Empty file added BUILD.bazel
Empty file.
32 changes: 32 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
workspace(name = "bazel_gcc_toolchain")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
],
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz"],
sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
)

load("//toolchain:defs.bzl", "gcc_register_toolchain")

gcc_register_toolchain(
name = "gcc_toolchain",
url = "https://toolchains.bootlin.com/downloads/releases/toolchains/x86-64/tarballs/x86-64--glibc--stable-2021.11-5.tar.bz2",
sha256 = "6fe812add925493ea0841365f1fb7ca17fd9224bab61a731063f7f12f3a621b0",
strip_prefix = "x86-64--glibc--stable-2021.11-5",
target_arch = "x86_64",
)
4 changes: 4 additions & 0 deletions examples/hello_world_c/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cc_binary(
name = "hello_world_c",
srcs = ["main.c"],
)
7 changes: 7 additions & 0 deletions examples/hello_world_c/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main()
{
printf("Hello World!\n");
return 0;
}
5 changes: 5 additions & 0 deletions examples/hello_world_cpp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cc_binary(
name = "hello_world_cpp",
srcs = ["main.cpp"],
linkopts = ["-lstdc++"],
)
7 changes: 7 additions & 0 deletions examples/hello_world_cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>

int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
Empty file added toolchain/BUILD.bazel
Empty file.
Loading

0 comments on commit 579774a

Please sign in to comment.