Skip to content

Commit 350495e

Browse files
committed
Add build configurations for Linux and Windows
Move some build flags to the build configuration (bazelrc). Enable more warnings and treat them as errors.
1 parent 2c45413 commit 350495e

File tree

10 files changed

+53
-19
lines changed

10 files changed

+53
-19
lines changed

.bazelrc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
# Try loading per-user configuration.
22
try-import %workspace%/user.bazelrc
33

4+
# Linux-specific configuration.
5+
build:linux --cxxopt=-std=c++17
6+
build:linux --copt=-Wall
7+
build:linux --copt=-Wextra
8+
build:linux --copt=-Wpedantic
9+
build:linux --copt=-Werror
10+
11+
# Windows-specific configuration.
12+
build:windows --cxxopt=/std:c++17
13+
build:windows --copt=/W4
14+
build:windows --copt=/WX
15+
416
# On Windows clang.exe tries to find the MSVC toolchain by looking at environmental variables,
517
# querying Visual Studio instances via COM (>=2017) and reading Registry keys (<=2015).
618
# ProgramData data is typically required for COM api querying, unless a custom location for
719
# Visual Studio package cache is defined.
8-
9-
build --action_env=ProgramData
20+
build:windows --action_env=ProgramData
1021

1122
# AddressSanitizer (ASan).
1223
build:asan --strip=never
13-
build:asan --copt -fsanitize=address
14-
build:asan --copt -DADDRESS_SANITIZER
15-
build:asan --copt -O0
16-
build:asan --copt -g
17-
build:asan --copt -fno-omit-frame-pointer
24+
build:asan --copt=-fsanitize=address
25+
build:asan --copt=-DADDRESS_SANITIZER
26+
build:asan --copt=-O0
27+
build:asan --copt=-g
28+
build:asan --copt=-fno-omit-frame-pointer
1829
build:asan --linkopt -fsanitize=address
1930

2031
# MemorySanitizer (MSan).

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
sudo ./llvm.sh ${{ matrix.tag }}
2626
sudo apt install -y llvm-${{ matrix.tag }}-dev libclang-${{ matrix.tag }}-dev liblldb-${{ matrix.tag }}-dev
2727
28+
- name: Setup Bazel
29+
run: |
30+
echo "build --config=linux" > user.bazelrc
31+
2832
- name: Build
2933
run: bazel build :all
3034

BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ COPTS = select({
2121
"/external:I external/llvm_project/include",
2222
],
2323
"//conditions:default": [
24-
"-std=c++17",
2524
"-fno-exceptions",
2625
"-fno-rtti",
2726
],

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,35 @@ Now you can build and test `lldb-eval`:
8787

8888
```bash
8989
# Build and run all tests
90-
bazel test :all
90+
bazel test --config=linux :all
9191

9292
# Evaluate a sample expression
93-
bazel run :main -- "(1 + 2) * 42 / 4"
93+
bazel run --config=windows :main -- "(1 + 2) * 42 / 4"
9494
```
9595

96-
Depending on your distribution of LLVM, you may need to provide
96+
> **Hint:** You can add this option to your `user.bazelrc` !
97+
98+
Depending on your distribution of LLVM, you may also need to provide
9799
`--@llvm_project//:llvm_build={static,dynamic}` flag. For example, if your
98100
`liblldb.so` is linked dynamically (this is the case when installing via `apt`),
99101
then you need to use `llvm_build=dynamic`. The build script [tries to choose the
100102
correct default value automatically](/build_defs/repo_rules.bzl#L21), but it can
101103
be wrong in some situations (please, report and contribute 🙂).
102104

103-
> **Hint:** You can add this option to your `user.bazelrc`
105+
> **Hint:** You can add this option to your `user.bazelrc` !
106+
107+
### Local per-repo Bazel config
108+
109+
You can create `user.bazelrc` in the repository root and put there your local
110+
configuration. Check [Bazel docs](https://docs.bazel.build/versions/master/guide.html#bazelrc)
111+
for the format. For example:
112+
113+
```bash
114+
# Building on Linux
115+
build --config=linux
116+
# Using statically linked liblldb.so
117+
build ----@llvm_project//:llvm_build=static
118+
```
104119

105120
## Disclamer
106121

src/eval.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void EvalError::Set(EvalErrorCode code, const std::string& message) {
4343
void EvalError::Clear() { *this = {}; }
4444

4545
EvalErrorCode EvalError::code() const { return code_; }
46-
const std::string& EvalError::message() const { return message_; };
46+
const std::string& EvalError::message() const { return message_; }
4747

4848
EvalError::operator bool() const { return code_ != EvalErrorCode::OK; }
4949

src/runner.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void SetupLLDBServerEnv(const Runfiles& runfiles) {
4747
#ifndef _WIN32
4848
std::string lldb_server = runfiles.Rlocation("llvm_project/bin/lldb-server");
4949
setenv("LLDB_DEBUGSERVER_PATH", lldb_server.c_str(), 0);
50+
#else
51+
(void)runfiles;
5052
#endif // !_WIN32
5153
}
5254

src/value.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ lldb::SBValue Value::AsSbValue(lldb::SBTarget target) const {
149149
lldb::eBasicTypeDouble);
150150
}
151151
}
152+
unreachable("Scalar::Type wasn't exhausted in the switch statement.");
152153
}
153154
case Type::POINTER: {
154155
return CreateSbValue(target, pointer_.addr(), pointer_.type());

tools/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ COPTS = select({
88
"/external:I external/llvm_project/include",
99
],
1010
"//conditions:default": [
11-
"-std=c++17",
1211
"-fno-exceptions",
1312
"-fno-rtti",
1413
],

tools/fuzzer/expr_gen.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ struct ExprKindInfo {
3030
};
3131

3232
static const std::array<ExprKindInfo, NUM_EXPR_KINDS> EXPR_KIND_INFO = {{
33-
{1.0, 0.0}, // ExprKind::IntegerConstant
34-
{0.0, 0.0}, // ExprKind::DoubleConstant
35-
{1.0, 0.0}, // ExprKind::VariableExpr
36-
{7.0, 0.4}, // ExprKind::BinaryExpr
37-
{3.0, 0.4}, // ExprKind::UnaryExpr
33+
{1.0f, 0.0f}, // ExprKind::IntegerConstant
34+
{0.0f, 0.0f}, // ExprKind::DoubleConstant
35+
{1.0f, 0.0f}, // ExprKind::VariableExpr
36+
{7.0f, 0.4f}, // ExprKind::BinaryExpr
37+
{3.0f, 0.4f}, // ExprKind::UnaryExpr
3838
}};
3939

4040
bool ExprGenerator::fifty_fifty() {
@@ -136,6 +136,7 @@ Expr ExprGenerator::gen_with_weights(const WeightsArray& weights) {
136136

137137
default:
138138
assert(false && "Unreachable");
139+
exit(1);
139140
}
140141
}
141142

tools/lexer.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "llvm/Support/Host.h"
3333

3434
int main(int argc, char** argv) {
35+
(void)argc;
36+
3537
// "parse" command line arguments.
3638
std::string expr = argv[1];
3739

0 commit comments

Comments
 (0)