Code Monkey home page Code Monkey logo

Comments (7)

irengrig avatar irengrig commented on August 30, 2024 1

Hi @rnburn, you can have only one configure_make target, with different paths to select only headers or headers and libraries together.
Here is the example how I was able to select headers:
`
filegroup(
name = "httpd_dir",
srcs = [
":apache_httpd",
],
output_group = "gen_dir"
)
genrule(
name = "select_headers",
srcs = [":httpd_dir"],
cmd = "cp -r $(location httpd_dir)/include $(location out_dir)",
outs = ["out_dir"]
)

genrule(
name = "list_headers",
srcs = [":select_headers"],
cmd = "ls $(location select_headers) > $(location list.txt)",
outs = ["list.txt"]
)
`

  • I used list_headers only to make select_headers to be built and demonstrate it works, you do not need it in the real build.
  • You can also have a custom rule for filtering and do everything with Starlark, because with genrule it is platform-bound.
  • Unfortunately, it seems to not work just woth filegroup like: srcs = glob([":target/subdir"]) - probably, glob syntax will always look into the current directory where the BUILD file is and not at the target...

from rules_foreign_cc.

rnburn avatar rnburn commented on August 30, 2024

Thanks @irengrig. I'm still having some trouble getting this to work. Here's the setup I have to produce a cpython_header_only library to use with a C++ python module

configure_make(
    name = "openssl",
    configure_command = "config",
    configure_options = [
        "no-shared",
    ],
    lib_source = "@com_github_openssl_openssl//:all",
    static_libraries = [
        "libcrypto.a",
        "libssl.a",
    ],
)

configure_make(
    name = "cpython",
    configure_options = [
        "--with-openssl=$EXT_BUILD_DEPS/openssl",
        # Hack to work around https://github.com/bazelbuild/rules_foreign_cc/issues/239
        "CFLAGS='-Dredacted=\"redacted\"'",
    ],
    lib_source = "@com_github_python_cpython//:all",
    out_include_dir = "include/python3.7m",
    binaries = [
        "python3",
    ],
    visibility = [
        "//visibility:public",
    ],
    deps = [
        ":openssl",
    ],
)

filegroup(
    name = "cpython_files",
    srcs = [
        ":cpython",
    ],
    visibility = [
        "//visibility:public",
    ],
    output_group = "gen_dir",
)

genrule(
    name = "cpython_includes",
    srcs = [
        ":cpython_files",
    ],
    cmd = "cp -r $(location cpython_files)/include/python3.7m $(location include)",
    outs = ["include"],
)

cc_library(
    name = "cpython_header_only",
    srcs = [
        ":cpython_includes",
    ],
    copts = ["-isystem include"],
)

But I get the error

root@193498bdc412:/src# bazel build //...
ERROR: /src/3rd_party/BUILD:65:12: in srcs attribute of cc_library rule //3rd_party:cpython_header_only: '//3rd_party:cpython_includes' does not produce any cc_library srcs files (expected .cc, .cpp, .cxx, .c++, .C, .c, .h, .hh, .hpp, .ipp, .hxx, .inc, .inl, .H, .S, .s, .asm, .a, .lib, .pic.a, .lo, .lo.lib, .pic.lo, .so, .dylib, .dll, .o, .obj or .pic.o)
ERROR: Analysis of target '//3rd_party:cpython_header_only' failed; build aborted: Analysis of target '//3rd_party:cpython_header_only' failed; build aborted
INFO: Elapsed time: 0.638s
INFO: 0 processes.

Any ideas?

from rules_foreign_cc.

rnburn avatar rnburn commented on August 30, 2024

I was able to get things to work with this variant

cc_library(
    name = "cpython_header_only",
    hdrs = [
        ":cpython_includes",
    ],
    copts = ["-isystem include"],
)

though not sure why that fixed the problem

from rules_foreign_cc.

rnburn avatar rnburn commented on August 30, 2024

Another curious error

If I use this version (which works better when the project is used externally bazelbuild/bazel#2670 )

cc_library(
    name = "cpython_header_only",
    hdrs = [
        ":cpython_includes",
    ],
    includes = ["include"],
)

I get

ERROR: /src/src/lib/BUILD:9:1: undeclared inclusion(s) in rule '//src/lib:bridge_tracer_lib':
this rule is missing dependency declarations for the following files included by 'src/lib/python_object_wrapper.cpp':
  'bazel-out/k8-fastbuild/genfiles/3rd_party/include/Python.h'
  'bazel-out/k8-fastbuild/genfiles/3rd_party/include/patchlevel.h'
...

from rules_foreign_cc.

rnburn avatar rnburn commented on August 30, 2024

@irengrig - this approach doesn't quite work. It still links in dependencies. This is my setup for a cpython_header_only library.

But when I build I get

bazel build -s //:bridge_tracer.so
...
/usr/bin/gcc -shared -o bazel-out/k8-fastbuild/bin/bridge_tracer.so -Wl,-S '-fuse-ld=gold' -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -pass-exit-codes -Wl,@bazel-out/k8-fastbuild/bin/bridge_tracer.so-2.params

And bazel-out/k8-fastbuild/bin/bridge_tracer.so-2.params has the cpython dependencies linked in

cat bazel-out/k8-fastbuild/bin/bridge_tracer.so-2.params
...
-whole-archive
bazel-out/k8-fastbuild/genfiles/3rd_party/openssl/lib/libssl.a
-no-whole-archive

from rules_foreign_cc.

github-actions avatar github-actions commented on August 30, 2024

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_foreign_cc!

from rules_foreign_cc.

github-actions avatar github-actions commented on August 30, 2024

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

from rules_foreign_cc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.