google / yggdrasil-decision-forests

A library to train, evaluate, interpret, and productionize decision forest models such as Random Forest and Gradient Boosted Decision Trees.
https://ydf.readthedocs.io/
Apache License 2.0
473 stars 49 forks source link

Not able to use yggdrasil-decision-forests as a dependency through Bazel #7

Closed JNSFilipe closed 3 years ago

JNSFilipe commented 3 years ago

I am trying to use yggdrasil-decision-forests as a C++ dependency in other project, that uses Bazel. I am using the suggestions in the documentation, mainly:

cc_library(
    name = "models",
    srcs = ["models.cpp"],
    hdrs = ["models.h"],
    deps = [
        "@ydf//yggdrasil_decision_forests/model:all_models",
        "@ydf//yggdrasil_decision_forests/learners:all_learners",
    ]
)

In the BUILD file and:

http_archive(
    name = "ydf",
    strip_prefix = "yggdrasil_decision_forests-master",
    urls = ["https://github.com/google/yggdrasil_decision_forests/archive/master.zip"],
)

load("@ydf//yggdrasil_decision_forests:library.bzl", ydf_load_deps = "load_dependencies")
ydf_load_deps(repo_name = "@ydf")

In the WORKSPACE file.

Nonetheless, I am getting the following error, when making bazel build models:

ERROR: /home/jfilipe/Repos/vvc-early-term-models/deploy/WORKSPACE:9:1: name 'http_archive' is not defined
ERROR: error loading package '': Encountered error while reading extension file 'yggdrasil_decision_forests/library.bzl': no such package '@ydf//yggdrasil_decision_forests': error loading package 'external': Could not load //external package
achoum commented 3 years ago

http_archive is a Bazel macro that should be imported before being used. Add the following line in your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

More details at https://docs.bazel.build/versions/main/repo/http.html.

JNSFilipe commented 3 years ago

I did manage to fix that, thanks. Furthermore, I think the link in urls is wrong. I changed the WORKSPACE file to:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "ydf",
    strip_prefix = "yggdrasil-decision-forests-0.1.3",
    urls = ["https://github.com/google/yggdrasil-decision-forests/archive/refs/tags/0.1.3.zip"],
)

load("@ydf//yggdrasil_decision_forests:library.bzl", ydf_load_deps = "load_dependencies")
ydf_load_deps(repo_name = "@ydf", exclude_repo=[])

Nonetheless, I still do not manage to get it to work. As far as I can understand from the error message below, the dependencies of ydf are not being pulled, despite being included by the last two lines of the WORKSPACE file:

Unable to find package for @bazel_skylib//lib:versions.bzl: The repository '@bazel_skylib' could not be resolved
achoum commented 3 years ago

I'll create a standalone repo to demonstrate it. This will be easier this way :).

I'll update the issue when available.

JNSFilipe commented 3 years ago

Thank you very much, I appreciate it!

achoum commented 3 years ago

Hi,

The directory yggdrasil-decision-forests/tree/main/examples/standalone now contains a standalone example. The compilation requirements and trouble shooting instructions are the same as for the library.