rules_jsonnet
rules_jsonnet copied to clipboard
Using external libraries that depend on other libraries
I'm trying to find a way to use external libraries that depend on other libraries, where I cannot control the import path.
To give you an example, this library uses k
, which is imported from github.com/grafana/jsonnet-libs/ksonnet-util/kausal.libsonnet
.
This import path is compatible to jsonnonet-bundler.
So using the jsonnet rules, it is possible to import the previously mentioned library for example, but the build would fail with something like
RUNTIME ERROR: couldn't open import "github.com/grafana/jsonnet-libs/ksonnet-util/kausal.libsonnet": no match locally or in the Jsonnet library paths
The easiest way I can think of would be to fetch the repository via http_archive
and build a structure like the following with a link to the actual directory.
github.com
└── grafana
└── jsonnet-libs -> /path/to/bazel/external/com_github_grafana_jsonnet-libs
Do you know any way to achieve that?
It might also be possible to implement something that uses jsonnet-bundler behind the scenes similar to what rules_python did with their pip_install
function.
This constructs a repository with the given name (e.g. my_deps
) which can be used to get the dependencies.
I can think of creating a repository like @jb
, so that dependencies might be selected by using for example @jb//github.com/grafana/jsonnet-libs:pkg
.
Anyway... feedback about these ideas are appreciated. I can try to implement something, but I might need some help since I'm still not that familiar with Bazel and its internals.
With #182 merged, this should be addressed. You can now just import files using workspace root relative paths. So if you have a file named @foo//my/package:foo.jsonnet
, it can now be imported through my/package/foo.jsonnet
. (Or you can abbreviate it even further by adding imports
).