0

I'm new to using bazel and I don't know how to make the path of my includes not have to be a full path. You can see the comment in src/main/main.c file.

My directory tree:

.
├── WORKSPACE
├── src
│   ├── lib
│   │   ├── BUILD
│   │   └── mytypes.h
│   └── main
│       ├── BUILD
│       └── main.c
└── test
    └── BUILD

src/lib/mytypes.h file:

#ifndef MYTYPES_H
#define MYTYPES_H

typedef unsigned char byte_t;

#endif

src/lib/BUILDfile:

cc_library(
    name = "mytypes",
    #srcs = glob(["*.c"]),
    hdrs = glob(["*.h"]),
    visibility = ["//src/main:__pkg__"],
)

src/main/main.c file:

#include <stdio.h>
#include "src/lib/mytypes.h"  // I would like to use: #include "mytypes.h"

int main(int argc, char **argv)
{
    byte_t byte = 0xAF;
    printf("%X\n", byte);
    return 0;
}

src/main/BUILD file:

cc_library(
    name = "mytypes",
    #srcs = glob(["*.c"]),
    hdrs = glob(["*.h"]),
    visibility = ["//src/main:__pkg__"],
)

WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "com_google_googletest",
    sha256 = "7b100bb68db8df1060e178c495f3cbe941c9b058",
    strip_prefix = "googletest-release-1.11.0",
    urls = ["https://github.com/google/googletest/archive/release-1.11.0.tar.gz"],
)
barroco
  • 3,018
  • 6
  • 28
  • 38

1 Answers1

1

cc_library.includes is what you're looking for. Change your src/lib/BUILD contents to:

cc_library(
    name = "mytypes",
    includes = ["."],
    hdrs = glob(["*.h"]),
    visibility = ["//src/main:__pkg__"],
)
Brian Silverman
  • 3,085
  • 11
  • 13
  • It works! Than you. But, now I have a problem with Visual Studio Code because lint give me an error in the include statements. Do you know if there is any way to configure vscode to work with bazel together? – barroco Jan 22 '22 at 18:28
  • https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel is the only thing I've seen for vscode, I've never used it. If you want help setting that up, try asking another question so somebody with knowledge there can see it. – Brian Silverman Jan 23 '22 at 19:04