-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toolchain/gem binary quirks #72
Comments
The way you use the ruleset is very specific and not supported at the moment. Let's start with
This of course ignores all the configuration that happens inside the
The latter binary would not have direct access to the working directory, so you might need to provide an exact path - that's for example how we do it for Rails:
Another option would be to define a BUILD rule that would put all files to the inputs/runfiles and then delegate to the binary. I haven't tested this but it should look like this: rb_binary(
name = "jekyll",
srcs = ["my_jekill_files"],
deps = ["@bundle"],
main = ["@bundle//bin:jekyll"],
)
|
Thanks for the quick reply! I see I'm using these targets wrong. I was hoping to a fully cached I made a pretty simple Bazel rule that attempts to build the site with the The target referencing this rule looks like: jekyll_site(
name = "site",
srcs = [":sources"],
jekyll = "@bundle//bin:jekyll",
config = ":_config.yml",
) However, I get a lot of errors and warning like the following:
Which ultimate leads to an error that fails the build:
Inspecting the build environment from Am I on the right track for running a gem with some args and passed in source files in a build? |
I've tried playing around with Jekyll and I managed to build an example using the following setup:
# MODULE.bazel
bazel_dep(name = "aspect_bazel_lib", version = "2.3.0")
bazel_dep(name = "rules_ruby", version = "0.6.0")
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
version = "3.2.2",
)
ruby.bundle_fetch(
name = "bundle",
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
use_repo(ruby, "ruby", "bundle", "ruby_toolchains")
register_toolchains("@ruby_toolchains//:all")
# BUILD
load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary")
run_binary(
name = "site",
srcs = glob([
"_posts/*",
"*.html",
"*.markdown",
]) + ["_config.yml"],
args = [
"build",
"-d",
"$(GENDIR)/_site",
],
execution_requirements = {"no-sandbox": "1"},
out_dirs = [
"_site",
],
tool = "@bundle//bin:jekyll",
)
# _config.yml
exclude:
- bazel-out/
- external/
I haven't tried to |
Also, to make a build cache more efficient, you can define targets per post like this: [
run_binary(
name = post[7:-9],
srcs = [
"404.html",
"_config.yml",
"about.markdown",
"index.markdown",
post,
],
outs = ["_site/jekyll/update/{year}/{month}/{day}/{title}.html".format(
day = post[7:-9].split("-", 3)[2],
month = post[7:-9].split("-", 3)[1],
title = post[7:-9].split("-", 3)[3],
year = post[7:-9].split("-", 3)[0],
)],
args = [
"build",
"-d",
"$(GENDIR)/_site",
],
tool = "@bundle//bin:jekyll",
)
for post in glob(["_posts/*"])
]
UPD: This is not enough since |
Wow, incredible! I haven't investigated finer-grained caching yet, but I did get Here's my full example: load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
filegroup(
name = "sources",
srcs = glob([
"_posts/**/*",
"_layouts/**/*",
]) + [
"404.html",
"about.markdown",
"index.markdown",
],
)
run_binary(
name = "site_build",
srcs = [
":_config.yml",
":sources",
],
args = [
"build",
"--source",
package_name(), # `package_name` shenigans seems to resolve the site not being at the repo root
"--destination",
"$(GENDIR)/{0}/_site".format(package_name()),
"--config",
"$(location :_config.yml)",
],
env = {
"LC_ALL": "C.UTF-8",
"LANG": "en_US.UTF-8",
"LANGUAGE": "en_US.UTF-8",
},
execution_requirements = {"no-sandbox": "1"},
out_dirs = [
"_site",
],
tool = "@bundle//bin:jekyll",
)
write_file(
name = "site_serve_file",
out = "site_serve_file.sh",
content = [
"#!/bin/bash",
# rules_ruby needs RUNFILES_DIR to be set
"export RUNFILES_DIR=$(readlink -f ../)",
"EXEC_ROOT=$(pwd)",
"$EXEC_ROOT/$1 ${@:2}",
],
)
sh_binary(
name = "site_serve",
srcs = [
":site_serve_file",
],
args = [
"$(location @bundle//bin:jekyll)",
"serve",
"--destination",
"{0}/_site".format(package_name()),
"--skip-initial-build",
"--config",
"$(location :_config.yml)",
],
data = [
":_config.yml",
":site_build",
"@bundle//bin:jekyll",
],
) I still find the I'm also seeing files not in my |
Great, any chance you could strip down your blog so I could put it to |
Yep, opened #74 |
Is there anything else to do in regards to this issue or shall you close it @RyanDraves? |
I'll consider this done for a moment. |
All set, thank you for the help! |
Follow-up for #41.
I've been using
0.6.0
for a bit, and the exposed Gem binaries seem follow weird patterns. Here are a few behaviors I noticed:@ruby//:jekyll
after cleaning my Bazel cache, I'll receive an error like:if I instead first run
bazel run @ruby//:bundle -- install
, then the target is available. This seems like an issue with the hermeticity of the setup.jekyll new
withbazel run @ruby//:jekyll
, I need to fish the output files out ofbazel-out/
jekyll build
andjekyll serve
around@ruby//:jekyll
, and to get the binary to run properly in abazel run
command I needed to wrap it in a script:bazel run @ruby//:bundle -- install
doesn't respectbundle_fetch
settings and defaults to//:Gemfile
. It also doesn't play nicely with path arguments, e.g. if I runbazel run @ruby//:bundle -- install --gemfile dir/Gemfile
, I'll get:I snooped through the Bazel cache a bit and found that
bundle.runfiles/_main
is empty and Bundle defaults to reaching out to../../../../../../../Gemfile
(7 parents, back in theexecroot/_main
which is symlinked to the original workspace). Similarly theGemfile.lock
is ignored.For some extra details, here's a sample from my
MODULE.bazel
:The text was updated successfully, but these errors were encountered: