Skip to content
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
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "curl", version = "8.8.0.bcr.3")
bazel_dep(name = "package_metadata", version = "0.0.5")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.2.0")
bazel_dep(name = "rules_cc", version = "0.2.1")

bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True)
bazel_dep(name = "bazelrc-preset.bzl", version = "1.6.0", dev_dependency = True)
Expand Down
9 changes: 6 additions & 3 deletions d/private/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

def _dinfo_init(
*,
compilation_output = None,
compiler_flags = None,
imports = None,
interface_srcs = None,
libraries = None,
linker_flags = None,
linking_context = None,
source_only = False,
string_imports = None,
versions = None):
"""Initializes the DInfo provider."""
return {
"compilation_output": compilation_output,
"compiler_flags": compiler_flags or depset(),
"imports": imports or depset(),
"interface_srcs": interface_srcs or depset(),
"libraries": libraries or depset(),
"linker_flags": linker_flags or depset(),
"linking_context": linking_context or depset(),
"source_only": source_only,
"string_imports": string_imports or depset(),
"versions": versions or depset(),
Expand All @@ -25,11 +27,12 @@ def _dinfo_init(
DInfo, _new_dinfo = provider(
doc = "Provider containing D compilation information",
fields = {
"compilation_output": "The output of the compilation action.",
"compiler_flags": "List of compiler flags.",
"imports": "A depset of import paths.",
"interface_srcs": "A depset of interface source files, transitive sources included.",
"libraries": "A depset of libraries, transitive libraries too.",
"linker_flags": "List of linker flags, passed directly to the linker.",
"linking_context": "A rules_cc LinkingContext (essentially a depset of needed libraries, including transitive ones).",
"source_only": "If true, the source files are compiled, but no library is produced.",
"string_imports": "A depset of string import paths.",
"versions": "A depset of version identifiers.",
Expand Down
43 changes: 34 additions & 9 deletions d/private/rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ bzl_library(
"//d:__subpackages__",
"//docs:__subpackages__",
],
deps = ["//d/private/rules:common"],
deps = [
"//d/private/rules:compile",
"//d/private/rules:link",
"@bazel_lib//lib:expand_make_vars",
],
)

bzl_library(
Expand All @@ -30,19 +34,17 @@ bzl_library(
)

bzl_library(
name = "common",
srcs = ["common.bzl"],
name = "compile",
srcs = ["compile.bzl"],
visibility = [
"//d:__subpackages__",
"//docs:__subpackages__",
],
deps = [
"//d/private:providers",
"//d/private/rules:cc_toolchain",
"@bazel_lib//lib:expand_make_vars",
"//d/private/rules:utils",
"@bazel_skylib//lib:dicts",
"@bazel_skylib//lib:paths",
"@rules_cc//cc/common",
],
)

Expand All @@ -54,8 +56,20 @@ bzl_library(
"//docs:__subpackages__",
],
deps = [
"//d/private/rules:common",
"@rules_cc//cc:find_cc_toolchain_bzl",
"//d/private/rules:compile",
],
)

bzl_library(
name = "link",
srcs = ["link.bzl"],
visibility = [
"//d:__subpackages__",
"//docs:__subpackages__",
],
deps = [
"//d/private/rules:cc_toolchain",
"@rules_cc//cc:defs_bzl",
],
)

Expand All @@ -67,7 +81,18 @@ bzl_library(
"//docs:__subpackages__",
],
deps = [
"//d/private/rules:common",
"//d/private/rules:compile",
"//d/private/rules:link",
"@bazel_lib//lib:expand_make_vars",
"@rules_cc//cc:find_cc_toolchain_bzl",
],
)

bzl_library(
name = "utils",
srcs = ["utils.bzl"],
visibility = [
"//d:__subpackages__",
"//docs:__subpackages__",
],
)
18 changes: 16 additions & 2 deletions d/private/rules/binary.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
"""D test rule for compiling binaries."""

load("@bazel_lib//lib:expand_make_vars.bzl", "expand_variables")
load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
load("//d/private/rules:common.bzl", "TARGET_TYPE", "compilation_action", "runnable_attrs")
load("//d/private/rules:compile.bzl", "TARGET_TYPE", "compilation_action", "runnable_attrs")
load("//d/private/rules:link.bzl", "link_action")

def _d_binary_impl(ctx):
"""Implementation of d_binary rule."""
return compilation_action(ctx, target_type = TARGET_TYPE.BINARY)
d_info = compilation_action(ctx, target_type = TARGET_TYPE.BINARY)
output = link_action(ctx, d_info)
env_with_expansions = {
k: expand_variables(ctx, ctx.expand_location(v, ctx.files.data), [output], "env")
for k, v in ctx.attr.env.items()
}
return [
DefaultInfo(
executable = output,
runfiles = ctx.runfiles(files = ctx.files.data),
),
RunEnvironmentInfo(environment = env_with_expansions),
]

d_binary = rule(
implementation = _d_binary_impl,
Expand Down
4 changes: 4 additions & 0 deletions d/private/rules/cc_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ _UNSUPPORTED_FEATURES = [
"use_header_modules",
"fdo_instrument",
"fdo_optimize",
# disable PIC support for now
# TODO: re-enable, but we need to have pic_objects/pic_static_library everywhere
"supports_pic",
# This is a nonspecific unsupported feature which allows the authors of C++
# toolchain to apply separate flags when compiling D code.
"rules_d_unsupported_feature",
Expand Down Expand Up @@ -86,4 +89,5 @@ def find_cc_toolchain_for_linking(ctx):
cc_compiler = cc_compiler,
cc_linking_options = cc_linking_options,
env = env,
feature_configuration = feature_configuration,
)
Loading
Loading