Skip to content

Commit 69042da

Browse files
authored
Fixing -DNDEBUG handling in HiGHS dependency (#35)
1 parent 1d81f0b commit 69042da

File tree

4 files changed

+181
-3
lines changed

4 files changed

+181
-3
lines changed

.bazelrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
common --enable_bzlmod --enable_workspace
22
build --cxxopt='-std=c++20'
3-
# HIGHS requires this define or else it is about 1.5x slower
4-
build --copt="-DNDEBUG=0"

WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ git_repository(
2828
http_archive(
2929
name = "highs",
3030
sha256 = HIGHS_SHA_256,
31+
build_file = "//external:highs.BUILD",
3132
strip_prefix = "HiGHS-" + HIGHS_VERSION,
3233
urls = ["https://github.com/ERGO-Code/HiGHS/archive/refs/tags/v" + HIGHS_VERSION + ".tar.gz"],
3334
)

external/highs.BUILD

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
2+
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_binary", "cc_test")
3+
4+
NDEBUG_COPTS = [
5+
"-DNDEBUG",
6+
]
7+
8+
copy_file(
9+
name = "highs-config",
10+
src = "src/HConfig.h.bazel.in",
11+
out = "HConfig.h",
12+
visibility = ["//visibility:public"],
13+
)
14+
15+
cc_library(
16+
name = "config",
17+
srcs = ["HConfig.h"],
18+
copts = NDEBUG_COPTS,
19+
visibility = ["//visibility:public"],
20+
)
21+
22+
cc_library(
23+
name = "highs",
24+
srcs = glob([
25+
"extern/filereaderlp/*.cpp",
26+
"src/interfaces/highs_c_api.cpp",
27+
"src/io/*.cpp",
28+
"src/ipm/*.cpp",
29+
"src/ipm/ipx/*.cc",
30+
"src/ipm/basiclu/*.c",
31+
"src/lp_data/*.cpp",
32+
"src/mip/*.cpp",
33+
"src/model/*.cpp",
34+
"src/parallel/*.cpp",
35+
"src/pdlp/*.cpp",
36+
"src/pdlp/cupdlp/*.c",
37+
"src/presolve/*.cpp",
38+
"src/qpsolver/*.cpp",
39+
"src/simplex/*.cpp",
40+
"src/test/*.cpp",
41+
"src/util/*.cpp",
42+
]),
43+
hdrs = glob([
44+
"**/*.h",
45+
"src/qpsolver/*.hpp",
46+
"src/Highs.h",
47+
"extern/filereaderlp/*.hpp",
48+
"extern/zstr/*.hpp",
49+
]),
50+
copts = [
51+
"-Wno-unused-variable",
52+
"-Wno-unused-but-set-variable",
53+
] + NDEBUG_COPTS,
54+
includes = [
55+
"extern",
56+
# "extern/filereaderlp",
57+
# "extern/zstr",
58+
"src",
59+
# "src/ipm",
60+
# "src/ipm/ipx",
61+
# "src/ipm/basiclu",
62+
# "src/lp_data",
63+
# "src/mip",
64+
# "src/model",
65+
# "src/parallel",
66+
# "src/presolve",
67+
# "src/qpsolver",
68+
# "src/simplex",
69+
# "src/test",
70+
# "src/util",
71+
"bazel-bin",
72+
],
73+
linkopts = ["-lpthread"],
74+
visibility = ["//visibility:public"],
75+
deps = [
76+
"//:config",
77+
"@zlib",
78+
],
79+
)
80+
81+
cc_binary(
82+
name = "call-highs-example",
83+
srcs = ["examples/call_highs_from_cpp.cpp"],
84+
visibility = ["//visibility:public"],
85+
deps = [
86+
"//:highs",
87+
],
88+
)
89+
90+
## Add tests
91+
copy_file(
92+
name = "highs-check-config",
93+
src = "check/HCheckConfig.h.bazel.in",
94+
out = "HCheckConfig.h",
95+
)
96+
97+
cc_library(
98+
name = "check-config",
99+
srcs = ["HCheckConfig.h"],
100+
)
101+
102+
cc_library(
103+
name = "test_lib",
104+
testonly = True,
105+
srcs = [
106+
"HCheckConfig.h",
107+
"check/Avgas.cpp",
108+
"check/TestMain.cpp",
109+
],
110+
hdrs = [
111+
"check/Avgas.h",
112+
"check/SpecialLps.h",
113+
"check/matrix_multiplication.hpp",
114+
"extern/catch.hpp",
115+
],
116+
copts = ["-Iextern"],
117+
data = glob(["check/instances/*"]),
118+
includes = ["check"],
119+
deps = [
120+
":highs",
121+
"//:check-config",
122+
],
123+
)
124+
125+
TEST_NAMES = [
126+
"TestAlienBasis",
127+
"TestBasis",
128+
"TestBasisSolves",
129+
"TestCheckSolution",
130+
"TestCrossover",
131+
"TestDualize",
132+
"TestEkk",
133+
"TestFactor",
134+
"TestFilereader",
135+
"TestFreezeBasis",
136+
"TestHighsGFkSolve",
137+
"TestHighsHash",
138+
"TestHighsHessian",
139+
"TestHighsIntegers",
140+
"TestHighsModel",
141+
"TestHighsParallel",
142+
"TestHighsRbTree",
143+
"TestHotStart",
144+
"TestHSet",
145+
"TestICrash",
146+
"TestInfo",
147+
"TestIO",
148+
"TestIpx",
149+
"TestLogging",
150+
"TestLpModification",
151+
"TestLpOrientation",
152+
"TestLpSolvers",
153+
"TestLpValidation",
154+
"TestMipSolver",
155+
"TestPresolve",
156+
"TestQpSolver",
157+
"TestRanging",
158+
"TestRays",
159+
"TestSemiVariables",
160+
"TestSetup",
161+
"TestSort",
162+
"TestSpecialLps",
163+
"TestThrow",
164+
]
165+
166+
[cc_test(
167+
name = name,
168+
srcs = ["check/%s.cpp" % name],
169+
copts = [
170+
"-Iextern",
171+
"-Wno-unused-variable",
172+
"-Wno-unused-but-set-variable",
173+
],
174+
deps = [
175+
":highs",
176+
":test_lib",
177+
],
178+
) for name in TEST_NAMES]

src/simplex.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ void SimplexDecoder::decode_to_errors(const std::vector<uint64_t>& detections) {
316316
}
317317

318318
// Get the model status
319-
const HighsModelStatus& model_status = highs->getModelStatus();
319+
[[maybe_unused]] const HighsModelStatus& model_status =
320+
highs->getModelStatus();
320321
assert(model_status == HighsModelStatus::kOptimal);
321322
}
322323

0 commit comments

Comments
 (0)