'Bazel | How to copy resources to build directory?
I am making some openGL project, and want to just copy one of my directory into build directory (I store my textures there).
So basically this is what my project structure looks like:
|-WORKSPACE
|-/src/
| -BUILD
| -main.cpp
| -*some folders here*
|-/resources/
| -BUILD
| -*some folders here*
All i want is to remain the same relation between directories
This is what i tried:
# src/BUILD file - I use it to build the whole program
cc_binary(
name = "OpenGL_Project",
srcs = ["main.cpp"],
deps = ["//src/renderer:renderer", "//src/scene", "//src/input", "//src/gui"],
data = ["//resources:resources"]
)
genrule(
name = "copy_resources",
srcs = ["//resources"],
outs = ["resources"],
cmd = "cp -r $(SRCS) $(OUTS)"
)
And
# resources/BUILD file
filegroup(
name = "resources",
srcs = glob(["shaders/**","textures/**"]),
visibility = ["//visibility:public"],
)
I don't get any errors during build, i tried cleaning it using
bazel clean --expunge
and building again - but it didn't seem to work. Important to add, there is NO resources folder at build directory at all, not that it's in the wrong place.
Do you guys have any ideas what's wrong ?
Solution 1:[1]
bzlws_copy does the job. See here
Add to your WORKSPACE file:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
http_archive(
name = "bzlws",
strip_prefix = "bzlws-f929e5380f441f50a77776d34a7df8cacdbdf986",
url = "https://github.com/zaucy/bzlws/archive/f929e5380f441f50a77776d34a7df8cacdbdf986.zip",
sha256 = "5bebb821b158b11d81dd25cf031b5b26bae97dbb02025df7d0e41a262b3a030b",
)
Add to your BUILD file:
bzlws_copy(
name = "copy_resources",
out = "resources/{FILENAME}",
force = True,
tags = ["manual"],
srcs = [
"//resources",
],
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vertexwahn |
