简体   繁体   中英

Bazel installation on windows

How to install Bazel on Windows 10? And how to run the command bazel build ? Whenever I run the command bazel build it shows an error saying that it only works from workspace. I don't know how to create a workspace.

在您的目录中创建一个空的工作区文件

copy NUL WORKSPACE

Bazel considers a folder that contains a file named WORKSPACE or WORKSPACE.bazel (since Bazel 1.0.0) as a workspace. The WORKSPACE file can be empty.

The Bazel documentation (Bazel version 2.0.0) says about a workspace:

A workspace is a directory on your filesystem that contains the source files for the software you want to build, as well as symbolic links to directories that contain the build outputs. Each workspace directory has a text file named WORKSPACE which may be empty, or may contain references to external dependencies required to build the outputs.

Directories containing a file called WORKSPACE are considered the root of a workspace. Therefore, Bazel ignores any directory trees in a workspace rooted at a subdirectory containing a WORKSPACE file (as they form another workspace).

Bazel also supports WORKSPACE.bazel file as an alias of WORKSPACE file. If both files exist, WORKSPACE.bazel will take the priority.

Here is an example:

File/directory layout:

<directory> HelloWorld
├── <file> BUILD.bazel
├── <file> main.cpp
└── <file> WORKSPACE.bazel

WORKSPACE.bazel

workspace(name = "HelloWorld")

BUILD.bazel

cc_binary(
    name = "HelloWorld",
    srcs = ["main.cpp"],
)

main.cpp

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World!" << endl;
}

How to build on Windows?

Open PowerShell and switch to the directory that contains the WORKSPACE.bazel file.

Type

bazel build //:HelloWorld

To run the application

bazel run //:HelloWorld

Details about how to install Bazel on Windows can be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM