Why one target produces expected output and another target which depends on the first one does not produce any output?

73 views
Skip to first unread message

Konstantin Erman

unread,
Feb 10, 2020, 7:07:43 PM2/10/20
to bazel-discuss

I am trying to write a macro to build Windows shared libraries (DLL) based on this example: https://github.com/bazelbuild/bazel/tree/master/examples/windows/dll

 

When I run “bazel build //examples/windows/dll:hello_world-link-to-dll-via-lib” I get the result expected – out folder contains hellolib.dll and import library hellolib.dll.if.lib.

 

But when I try to just build the DLL target specifically with “bazel build //examples/windows/dll:hellolib” I get nothing – empty out folder.

 

Interestingly “bazel build //examples/windows/dll:hellolib.dll” produces DLL and the import library as expected.

 

This is very confusing, why the target “:hellolib.dll” produces the output and the target “:hellolib” which depend on the target “:hellolib.dll” does not produce the output.

 

Can anybody comment?

 

Konstantin

 

László Csomor

unread,
Feb 12, 2020, 7:55:52 AM2/12/20
to Konstantin Erman, bazel-discuss
Hi Konstantin,

This looks like a cc_library + cc_import combination bug. Could you
please report it on GitHub? (https://github.com/bazelbuild/bazel/issues/new)

I can repro it on Linux too:

# Build the shared library
cc_binary(
name = "foo.so",
srcs = ["foo.cc", "foo.h"],
linkshared = 1,
#copts = ["/DCOMPILING_DLL"],
copts = ["-fPIC"],
)

# Get the import library for the dll
filegroup(
name = "foo_imp_lib",
srcs = [":foo.so"],
output_group = "interface_library",
)

# Because we cannot directly depend on cc_binary from other cc
# rules in deps attribute, we use cc_import as a bridge to depend
# on the dll.
cc_import(
name = "foo_import",
interface_library = ":foo_imp_lib",
shared_library = ":foo.so",
)

# Create a new cc_library to also include the headers needed for
# the shared library
cc_library(
name = "foo",
hdrs = ["foo.h"],
deps = [":foo_import"],
)

Building ":foo" does not compile or link anything, but building
"foo_imp_lib" does.


--
László Csomor | Software Engineer | laszlo...@google.com

Google Germany GmbH | Erika-Mann-Str. 33 | 80636 München | Germany
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
> --
> You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/d6f74ab1-6df4-4245-8236-e5dc87e5573e%40googlegroups.com.

Konstantin Erman

unread,
Feb 12, 2020, 11:19:08 AM2/12/20
to bazel-discuss
Thank you, László! Issue opened: https://github.com/bazelbuild/bazel/issues/10770

Konstantin
Reply all
Reply to author
Forward
0 new messages