I noticed that a number of build rule arguments in the Buck documentation expect actual file paths as opposed to other build targets. Some examples of this are arguments such as exported_headers, static_lib, headers, etc. In all of my Buck projects I use a combination of genrule(), remote_file() and prebuilt_cxx_library() to get all my dependencies remotely and build them locally, yet when using rules such as prebuilt_cxx_library() these file-only rule arguments only add complexity to this approach, as I can't just incorporate the files produced by my other build rules.
Is there any way to access the file paths of files contained in a build rule, or even just another genrule()? I'd prefer to not have to clone all my dependencies locally and Buck-ify them just to have this work. Just to give an example, here's how I'm attempting to get GTest programatically:
remote_file(
name = 'get-gtest',
url = 'https://github.com/google/googletest/archive/release-1.8.0.zip',
sha1 = '667f873ab7a4d246062565fad32fb6d8e203ee73',
type = 'exploded_zip'
)
genrule(
name = 'build-gtest',
srcs = [':get-gtest'],
cmd = 'cd $SRCS/googletest-release-1.8.0/googletest && cmake . && make && cp -r ./libgtest.a ./include $OUT',
out = '.'
)
genrule(
name = 'headers-gtest',
srcs = [':build-gtest'],
cmd = 'cp -r $SRCS/include/* $OUT',
out = '.'
)
genrule(
name = 'lib-gtest',
srcs = [':build-gtest'],
cmd = 'cp $SRCS/libgtest.a $OUT',
out = 'libgtest.a'
)
prebuilt_cxx_library(
name = 'gtest',
header_dirs = [':headers-gtest'],
# exported_headers expects file paths. There's no way to export these programatic files.
exported_headers = [':headers-gtest'],
static_lib = ':lib-gtest',
visibility = ['PUBLIC']
)
As commented above, there's no way to export GTest's headers seeing the argument only expects file paths.
The fix would be to make
be a List<SourcePath> instead (which would support both file paths and build target outputs)
@kageiit Interesting... should I open a PR for this or just a use a custom fork of Buck or something?
@Nickersoft Please open a pr :)
Most helpful comment
The fix would be to make
https://github.com/facebook/buck/blob/master/src/com/facebook/buck/cxx/PrebuiltCxxLibraryDescription.java#L920
be a
List<SourcePath>instead (which would support both file paths and build target outputs)https://github.com/facebook/buck/blob/001677c8b20213c2ba019028fc3459e89d4b8c12/src/com/facebook/buck/shell/AbstractGenruleDescription.java#L212