Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

😍 Add module std #98

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ llvm_project_overlay = use_extension(
"llvm_project_overlay",
)
llvm_project_overlay.configure(
commit = "de45ab3c92d530c00d9c7ce20a85e01da4d37303",
sha256 = "be51ca84dd5888ab0b160e22e65bc6ee43045f8974df03092a8ea48a9cd7fe6d",
commit = "4ef1393e1b35049f0d35b0b74dbffeaa104288f0",
sha256 = "756af75d3a3b02033e8979d19b9a94c9bda55e3178fa202aea823f2caf6112b0",
targets = ["AMDGPU", "NVPTX", "X86", "WebAssembly"],
patches = [
"@rules_ll//patches:back_inserter_patch.diff",
"@rules_ll//patches:compiler-rt_float128_patch.diff",
"@rules_ll//patches:mallinfo2_patch.diff",
"@rules_ll//patches:rules_ll_overlay_patch.diff",
"@rules_ll//patches:clang_new_offload_driver.diff",
"@rules_ll//patches:std_modules_tuple_fix.diff",
],
)

Expand Down
1 change: 1 addition & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ EXAMPLES = [
# "sanitizers",
# "clang_tidy_example",
"shared_library_example",
"std_module_example",
"modules_draft_example",
]

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 @@ -365,6 +365,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
11 changes: 9 additions & 2 deletions ll/inputs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def compile_object_inputs(
toolchain.omp_header +
toolchain.rocm_device_libs +
toolchain.unwind_library
),
) + [
module.bmi
for module in toolchain.cpp_stdmodules
],
transitive = [
headers,
depset([interface.bmi for interface in interfaces.to_list()]),
Expand Down Expand Up @@ -104,7 +107,11 @@ def link_executable_inputs(ctx, in_files):
toolchain.unwind_library +
(
toolchain.llvm_project_artifacts if ctx.attr.depends_on_llvm else []
),
) +
[
module.bmi
for module in toolchain.cpp_stdmodules
],
)

def link_shared_object_inputs(ctx, in_files):
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
122 changes: 121 additions & 1 deletion llvm-project-overlay/libcxx/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,116 @@
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",
"cstdint",
"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",
"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", # Manually had to include <functional>.
"unordered_map",
"unordered_set",
"utility",
"valarray",
"variant",
"vector",
"version",
]

expand_template(
name = "module_modulemap_gen",
out = "include/module.modulemap",
Expand Down Expand Up @@ -151,13 +261,14 @@ ll_library(
],
compilation_mode = "bootstrap",
compile_flags = [
"-std=c++20",
"-std=c++2b",
"-faligned-allocation",
"-fno-omit-frame-pointer",
"-funwind-tables",
"-fstrict-aliasing",
"-fvisibility-inlines-hidden",
"-Wno-user-defined-literals",
"-Wno-reserved-module-identifier",
],
defines = [
"_LIBCPP_BUILDING_LIBRARY",
Expand All @@ -177,9 +288,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"],
)
Loading