From 6a3e215bc7b8544e5924006e33f14e209c0c6a5d Mon Sep 17 00:00:00 2001 From: David Young-chan Kay Date: Tue, 17 Aug 2021 08:51:58 -0700 Subject: [PATCH 1/3] d_library now consumes source code from dependencies (depinfo.d_srcs) --- d/d.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d/d.bzl b/d/d.bzl index fbc57ce..a866d14 100644 --- a/d/d.bzl +++ b/d/d.bzl @@ -249,7 +249,7 @@ 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], out = d_lib, depinfo = depinfo, extra_flags = ["-lib"], From 9eb7cab12981d0529f0f8f7708ccf4f73e03daf9 Mon Sep 17 00:00:00 2001 From: David Young-chan Kay Date: Tue, 17 Aug 2021 09:05:53 -0700 Subject: [PATCH 2/3] Made d_library and d_binary both consume transitive_d_srcs. NOTE: it seems like d_library and d_src_library currently behave the same way. Seems like we should make d_library actually consume/produce-as-dep .a file --- d/d.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/d/d.bzl b/d/d.bzl index a866d14..d62bc37 100644 --- a/d/d.bzl +++ b/d/d.bzl @@ -249,7 +249,7 @@ def _d_library_impl(ctx): # Build compile command. compile_args = _build_compile_arglist( ctx = ctx, - srcs = [src.path for src in ctx.files.srcs] + [src.path for src in depinfo.d_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"], @@ -306,7 +306,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, From 75107fbdd1b691ead6d89ed34d446c02032d5ae3 Mon Sep 17 00:00:00 2001 From: David Young-chan Kay Date: Sat, 14 Aug 2021 15:15:52 -0700 Subject: [PATCH 3/3] Very basic shared lib support in d_library --- d/d.bzl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/d/d.bzl b/d/d.bzl index d62bc37..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) @@ -252,7 +254,7 @@ def _d_library_impl(ctx): 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( @@ -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(