Skip to content
Open
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
14 changes: 8 additions & 6 deletions d/d.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def _build_compile_arglist(ctx, srcs, out, depinfo, extra_flags = []):
srcs
)


def _build_link_arglist(ctx, objs, out, depinfo):
"""Returns a string containing the D link command."""
return (
Expand Down Expand Up @@ -241,18 +240,21 @@ def _setup_deps(ctx, deps, name, working_dir):

def _d_library_impl(ctx):
"""Implementation of the d_library rule."""
d_lib = ctx.actions.declare_file((ctx.label.name + ".lib") if _is_windows(ctx) else ("lib" + ctx.label.name + ".a"))
if ctx.attr.shared:
d_lib = ctx.actions.declare_file((ctx.label.name + ".dll") if _is_windows(ctx) else ("lib" + ctx.label.name + ".so"))
else:
d_lib = ctx.actions.declare_file((ctx.label.name + ".lib") if _is_windows(ctx) else ("lib" + ctx.label.name + ".a"))

# Dependencies
depinfo = _setup_deps(ctx, ctx.attr.deps, ctx.label.name, d_lib.dirname)

# Build compile command.
compile_args = _build_compile_arglist(
ctx = ctx,
srcs = [src.path for src in ctx.files.srcs],
srcs = [src.path for src in ctx.files.srcs] + [src.path for src in depinfo.d_srcs] + [src.path for src in depinfo.transitive_d_srcs.to_list()],
out = d_lib,
depinfo = depinfo,
extra_flags = ["-lib"],
extra_flags = ["-shared"] if ctx.attr.shared else ["-lib"],
)

compile_inputs = depset(
Expand Down Expand Up @@ -306,7 +308,7 @@ def _d_binary_impl_common(ctx, extra_flags = []):
# Build compile command
compile_args = _build_compile_arglist(
ctx = ctx,
srcs = [src.path for src in ctx.files.srcs],
srcs = [src.path for src in ctx.files.srcs] + [src.path for src in depinfo.transitive_d_srcs.to_list()],
depinfo = depinfo,
out = d_obj,
extra_flags = ["-c"] + extra_flags,
Expand Down Expand Up @@ -564,7 +566,7 @@ _d_compile_attrs = {

d_library = rule(
_d_library_impl,
attrs = dict(_d_common_attrs.items() + _d_compile_attrs.items()),
attrs = dict(_d_common_attrs.items() + _d_compile_attrs.items() + {"shared": attr.bool()}.items()),
)

d_source_library = rule(
Expand Down