diff --git a/d/d.bzl b/d/d.bzl index fbc57ce..5f9cc13 100644 --- a/d/d.bzl +++ b/d/d.bzl @@ -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 ( @@ -241,7 +240,10 @@ 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) @@ -249,10 +251,10 @@ def _d_library_impl(ctx): # 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( @@ -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, @@ -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(