Comments (4)
Take a look at how rustdoc works. It also writes to an output directory.
from buck2.
Generally you would declare an output directory, and write it out.
output = ctx.actions.declare_output("protoc", dir=True)
cmd = cmd_args("protoc", "--cpp_out", output.as_output())
You will normally get an error about overlapping paths if you have defined that one output is in foo
, and then you say the whole output is in .
because the .
output will overlap/contain the foo
, so is no longer isolated from foo
.
The above will given you a relative path, which I guess is probably fine (it will be relative to the root of the repo, which will also be the $PWD for the command). If you really need absolute, then use realpath
in a shell script to convert, but I suspect relative is just fine.
If you have to do --cpp_out=something
rather than just --cpp_out something
, then the approach @dtolnay described is the way to do it.
from buck2.
With that approach I get an output directory. I'm using cxx_library_parameterized
though which needs srcs
, see ctx.attrs.srcs.extend(ccs)
in the snippet below.
glob
isn't available so I'm missing the link to go from a directory of files to a list of individual source artifacts. Is there anything to support that?
def proto_library_impl(ctx: "context") -> ["provider"]:
headers = []
ccs = []
out = ctx.actions.declare_output("out", dir=True)
ctx.attrs.headers.append(out)
cmd = cmd_args(["protoc", "--cpp_out", out.as_output()])
for s in ctx.attrs.srcs:
name = paths.replace_extension(s.short_path, "")
h = ctx.actions.declare_output(out.short_path + "/" + name + ".pb.h") # conflict warning
cc = ctx.actions.declare_output(out.short_path + "/" + name + ".pb.cc") # conflict warning
cmd.hidden([h.as_output(), cc.as_output()])
ccs.extend([cc])
headers.extend([h])
cmd.add(ctx.attrs.srcs)
# replace sources because cxx_library_parameterized uses ctx.srcs
ctx.actions.run(cmd, category="protoc", identifier = "compile", no_outputs_cleanup = True)
ctx.attrs.srcs.clear()
ctx.attrs.srcs.extend(ccs)
# ... snip much more code to call cxx_library_parameterized
from buck2.
After a bit more of trial and error I landed on the following solution which relies on the fact that rule
outputs are generated in the same directory. This way I can declare non-conflicting
individual outputs and the out directory for protoc
.
out = ctx.actions.declare_output('out')
cmd = cmd_args("protoc")
# ... snip
cmd.add("--cpp_out")
cmd.add(cmd_args(out.as_output()).parent())
cmd.add(ctx.attrs.srcs)
I don't know whether this is always true but works for now.
from buck2.
Related Issues (20)
- --show-output (and related options show nothing in column 2) when using DefaultInfo with default_outs HOT 1
- Full rebuild after killing daemon HOT 8
- Suggestion: Use tar or zip for release artifacts
- Why can not Buck trigger Buildbarn's g++ using system_cxx_toolchain?
- 'buck2 build //tests:' can not find 'sh' when using case 'buck2/examples/remote_execution/buildbarn/tests'
- License details (for SPDX compliance) HOT 2
- Buck2 performance on single-file update in erlang project HOT 13
- `SRCDIR` is not absolute in genrule script HOT 2
- It should be possible to consume multiple `default_outputs` in an `attrs.list(attrs.source())` HOT 5
- RE: upload cancelled with "stream error: stream no longer needed" HOT 5
- Zig support HOT 2
- Handling environment variables for local and remote builds HOT 1
- How can I check and/or override the path for the linker for rust/cxx? HOT 1
- C++ mixed linking HOT 4
- Read output of `actions.run` from BXL HOT 6
- [Feature request] Support custom caching for non-reproducible actions? HOT 4
- Making sha256 or sha1 sum for http_archive optional HOT 3
- Transitive shared libraries not added to rpath of otherwise static binaries HOT 3
- Errant octal escape strings in prelude docs HOT 1
- RE: Error, message length too large for `BatchReadBlobs` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buck2.