Skip to content

Commit

Permalink
😍 Add module std
Browse files Browse the repository at this point in the history
See https://reviews.llvm.org/D144994 for progress on this.
  • Loading branch information
aaronmondal committed Apr 24, 2023
1 parent 7ad57b2 commit 24635c9
Show file tree
Hide file tree
Showing 9 changed files with 12,708 additions and 6 deletions.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ llvm_project_overlay.configure(
"@rules_ll//patches:rules_ll_overlay_patch.diff",
"@rules_ll//patches:clang_new_offload_driver.diff",
"@rules_ll//patches:llvm_use_zlib-ng.diff",
"@rules_ll//patches:std_modules.diff",
],
)

Expand Down
8 changes: 8 additions & 0 deletions examples/std_module_example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@rules_ll//ll:defs.bzl", "ll_binary")

ll_binary(
name = "std_module_example",
srcs = ["main.cpp"],
compile_flags = ["-std=c++2b"],
visibility = ["@//:__pkg__"],
)
6 changes: 6 additions & 0 deletions examples/std_module_example/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import std;

auto main() -> int {
std::cout << "Hello, World!" << std::endl;
return 0;
}
7 changes: 7 additions & 0 deletions ll/args.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ def compile_object_args(
omit_if_empty = True,
)

if ctx.attr.compilation_mode != "bootstrap":
args.add_all(
toolchain.cpp_stdmodules,
map_each = _create_module_import,
format_each = "-fmodule-file=%s",
)

# Input file.
args.add(in_file)

Expand Down
4 changes: 2 additions & 2 deletions ll/inputs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def compile_object_inputs(
toolchain.unwind_library +
toolchain.cpp_abihdrs +
toolchain.compiler_runtime
)
) + [module.bmi for module in toolchain.cpp_stdmodules]

if config == "cpp":
pass
Expand Down Expand Up @@ -120,7 +120,7 @@ def link_executable_inputs(ctx, in_files):
ctx.files.deps +
ctx.files.libraries +
ctx.files.data
)
) + [module.bmi for module in toolchain.cpp_stdmodules]

if config == "bootstrap":
return depset(direct)
Expand Down
6 changes: 6 additions & 0 deletions ll/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This file declares the `ll_toolchain` rule.
"""

load("//ll:attributes.bzl", "LL_TOOLCHAIN_ATTRS")
load("//ll:providers.bzl", "LlInfo")

def _ll_toolchain_impl(ctx):
# We always need to invoke lld via an ld.lld -> lld symlink.
Expand All @@ -20,6 +21,10 @@ def _ll_toolchain_impl(ctx):
])
llvm_project_artifacts = ctx.files.llvm_project_deps

std_modules = []
for target in ctx.attr.cpp_stdlib:
std_modules += target[LlInfo].exposed_bmis.to_list()

return [
platform_common.ToolchainInfo(
c_driver = ctx.executable.c_driver,
Expand All @@ -42,6 +47,7 @@ def _ll_toolchain_impl(ctx):
builtin_includes = ctx.files.builtin_includes,
cpp_stdlib = ctx.files.cpp_stdlib,
cpp_stdhdrs = ctx.files.cpp_stdhdrs,
cpp_stdmodules = std_modules,
cpp_abilib = ctx.files.cpp_abilib,
cpp_abihdrs = ctx.files.cpp_abihdrs,
compiler_runtime = ctx.files.compiler_runtime,
Expand Down
120 changes: 119 additions & 1 deletion llvm-project-overlay/libcxx/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,115 @@
load("@rules_ll//ll:defs.bzl", "ll_library")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")

STD_PARTITIONS = [
"algorithm",
"any",
"array",
"atomic",
"barrier",
"bit",
"bitset",
"cassert",
"cctype",
"cerrno",
"cfenv",
"cfloat",
"charconv",
"chrono",
"cinttypes",
"climits",
"clocale",
"cmath",
"codecvt",
"compare",
"complex",
"concepts",
"condition_variable",
"coroutine",
"csetjmp",
"csignal",
"cstdarg",
"cstddef",
"cstdio",
"cstdlib",
"cstring",
"ctime",
"cuchar",
"cwchar",
"cwctype",
"deque",
"exception",
"execution",
"expected",
"filesystem",
"flat_map",
"flat_set",
"format",
"forward_list",
"fstream",
"functional",
"future",
"generator",
"initializer_list",
"iomanip",
"ios",
"iosfwd",
"iostream",
"istream",
"iterator",
"latch",
"limits",
"list",
"locale",
"map",
"mdspan",
# "memory", # Bugged?
"memory_resource",
"mutex",
# "new", # Needs special treatment. Module is called __new.
"numbers",
"numeric",
"optional",
"ostream",
"print",
"queue",
"random",
"ranges",
"ratio",
"regex",
"scoped_allocator",
"semaphore",
"set",
"shared_mutex",
"source_location",
"span",
"spanstream",
"sstream",
"stack",
"stacktrace",
"stdexcept",
"stdfloat",
"stop_token",
"streambuf",
"string",
"string_view",
"strstream",
"syncstream",
"system_error",
"thread",
"tuple",
"typeindex",
"typeinfo",
"type_traits",
"unordered_map",
"unordered_set",
"utility",
"valarray",
"variant",
"vector",
"version",
]

expand_template(
name = "module_modulemap_gen",
out = "include/module.modulemap",
Expand Down Expand Up @@ -152,7 +261,7 @@ ll_library(
],
compilation_mode = "bootstrap",
compile_flags = [
"-std=c++20",
"-std=c++2b",
"-faligned-allocation",
"-fno-omit-frame-pointer",
"-funwind-tables",
Expand All @@ -178,9 +287,18 @@ ll_library(
exposed_hdrs = [
"//libcxx:headers",
],
exposed_interfaces = {
"modules/std.cppm": "std",
},
includes = [
"libcxx/src",
],
interfaces = {
"modules/std/{}.cppm".format(name): "std:{}".format(name)
for name in STD_PARTITIONS
} | {
"modules/std/new.cppm": "std:__new",
},
visibility = ["//visibility:public"],
deps = ["//libcxxabi"],
)
124 changes: 121 additions & 3 deletions patches/rules_ll_overlay_patch.diff
Original file line number Diff line number Diff line change
Expand Up @@ -1270,13 +1270,122 @@ index 000000000000..8ad56ad46df6
+)
diff --git a/utils/bazel/llvm-project-overlay/libcxx/BUILD.bazel b/utils/bazel/llvm-project-overlay/libcxx/BUILD.bazel
new file mode 100644
index 000000000000..c1b167e454c6
index 000000000000..c103a1dcdff7
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/libcxx/BUILD.bazel
@@ -0,0 +1,186 @@
@@ -0,0 +1,304 @@
+load("@rules_ll//ll:defs.bzl", "ll_library")
+load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+
+STD_PARTITIONS = [
+ "algorithm",
+ "any",
+ "array",
+ "atomic",
+ "barrier",
+ "bit",
+ "bitset",
+ "cassert",
+ "cctype",
+ "cerrno",
+ "cfenv",
+ "cfloat",
+ "charconv",
+ "chrono",
+ "cinttypes",
+ "climits",
+ "clocale",
+ "cmath",
+ "codecvt",
+ "compare",
+ "complex",
+ "concepts",
+ "condition_variable",
+ "coroutine",
+ "csetjmp",
+ "csignal",
+ "cstdarg",
+ "cstddef",
+ "cstdio",
+ "cstdlib",
+ "cstring",
+ "ctime",
+ "cuchar",
+ "cwchar",
+ "cwctype",
+ "deque",
+ "exception",
+ "execution",
+ "expected",
+ "filesystem",
+ "flat_map",
+ "flat_set",
+ "format",
+ "forward_list",
+ "fstream",
+ "functional",
+ "future",
+ "generator",
+ "initializer_list",
+ "iomanip",
+ "ios",
+ "iosfwd",
+ "iostream",
+ "istream",
+ "iterator",
+ "latch",
+ "limits",
+ "list",
+ "locale",
+ "map",
+ "mdspan",
+ # "memory", # Bugged?
+ "memory_resource",
+ "mutex",
+ # "new", # Needs special treatment. Module is called __new.
+ "numbers",
+ "numeric",
+ "optional",
+ "ostream",
+ "print",
+ "queue",
+ "random",
+ "ranges",
+ "ratio",
+ "regex",
+ "scoped_allocator",
+ "semaphore",
+ "set",
+ "shared_mutex",
+ "source_location",
+ "span",
+ "spanstream",
+ "sstream",
+ "stack",
+ "stacktrace",
+ "stdexcept",
+ "stdfloat",
+ "stop_token",
+ "streambuf",
+ "string",
+ "string_view",
+ "strstream",
+ "syncstream",
+ "system_error",
+ "thread",
+ "tuple",
+ "typeindex",
+ "typeinfo",
+ "type_traits",
+ "unordered_map",
+ "unordered_set",
+ "utility",
+ "valarray",
+ "variant",
+ "vector",
+ "version",
+]
+
+expand_template(
+ name = "module_modulemap_gen",
+ out = "include/module.modulemap",
Expand Down Expand Up @@ -1428,7 +1537,7 @@ index 000000000000..c1b167e454c6
+ ],
+ compilation_mode = "bootstrap",
+ compile_flags = [
+ "-std=c++20",
+ "-std=c++2b",
+ "-faligned-allocation",
+ "-fno-omit-frame-pointer",
+ "-funwind-tables",
Expand All @@ -1454,9 +1563,18 @@ index 000000000000..c1b167e454c6
+ exposed_hdrs = [
+ "//libcxx:headers",
+ ],
+ exposed_interfaces = {
+ "modules/std.cppm": "std",
+ },
+ includes = [
+ "libcxx/src",
+ ],
+ interfaces = {
+ "modules/std/{}.cppm".format(name): "std:{}".format(name)
+ for name in STD_PARTITIONS
+ } | {
+ "modules/std/new.cppm": "std:__new",
+ },
+ visibility = ["//visibility:public"],
+ deps = ["//libcxxabi"],
+)
Expand Down
Loading

0 comments on commit 24635c9

Please sign in to comment.