Skip to content

Commit 3ba70b6

Browse files
authored
Bazelify gensas (#1)
* Added OpenBlas, SuperLU, Armadillo as dependencies * Bazelify util and sas folder * Bazelify pf dir * Bazelify libz, szlib, aec, hdf5, matio * Bazelify io, fix third_party build issue * Successful build and run of gensas (Modelica portion only)
1 parent 370e51f commit 3ba70b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3209
-221
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bazel-gensas

.bazelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://github.com/bazelbuild/rules_foreign_cc/issues/1129#issuecomment-1863628259
2+
build --noincompatible_sandbox_hermetic_tmp
3+
test --test_output=all

.bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.0.0

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bazel-gensas
2+
bazel-bin
3+
bazel-out
4+
bazel-testlogs
5+
.vscode
6+
genhtml
7+
*.log

BUILD.bazel

+243
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_test","cc_library")
2+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "make", "configure_make")
3+
4+
package(default_visibility = ["//visibility:public"])
5+
6+
cmake(
7+
name = "pcre",
8+
cache_entries = {
9+
"CMAKE_C_FLAGS": "-fPIC",
10+
},
11+
lib_source = "@pcre//:all_srcs",
12+
out_static_libs = ["libpcre.a"],
13+
)
14+
15+
# Each full make will take about 10 minutes to run
16+
make(
17+
name = "openblas_lib",
18+
lib_source = "@openblas//:all_srcs",
19+
out_static_libs = ["libopenblas.a"],
20+
# experiment to export build data
21+
build_data = [
22+
"@openblas//:README.md",
23+
],
24+
out_data_dirs = ["share"],
25+
)
26+
27+
cc_library(
28+
name = "openblas_lib_bazel",
29+
srcs = [],
30+
visibility = ["//visibility:public"],
31+
deps = [
32+
":openblas_lib",
33+
]
34+
)
35+
36+
# There may be a bad symlinked header and the workaround is at:
37+
# https://github.com/bazelbuild/rules_foreign_cc/issues/1129#issuecomment-1863628259
38+
cmake(
39+
name = "superlu_lib",
40+
cache_entries = {
41+
# "CMAKE_INSTALL_PREFIX": ".",
42+
# "CMAKE_INSTALL_INCLUDEDIR": "include",
43+
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
44+
# The directory structure of ":openblas_lib_bazel" are retained,
45+
# usually libraries are under /lib and headers are under /include
46+
"TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
47+
},
48+
lib_source = "@superlu//:all_srcs",
49+
out_static_libs = ["libsuperlu.a"],
50+
deps = [
51+
# cannot directly use ":openblas_lib",
52+
# need bridged through a `cc_library` containing ":openblas_lib"
53+
# i.e. ":openblas_lib_bazel"
54+
":openblas_lib_bazel"
55+
],
56+
linkopts = ["-lpthread"],
57+
)
58+
59+
cmake(
60+
name = "armadillo_lib",
61+
cache_entries = {
62+
# "CMAKE_INSTALL_PREFIX": ".",
63+
# "CMAKE_INSTALL_INCLUDEDIR": "include",
64+
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
65+
# The directory structure of ":openblas_lib_bazel" are retained,
66+
# usually libraries are under /lib and headers are under /include
67+
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
68+
"BUILD_SHARED_LIBS": "OFF",
69+
},
70+
lib_source = "@armadillo//:all_srcs",
71+
out_static_libs = ["libarmadillo.a"],
72+
# out_include_dir = "include",
73+
deps = [
74+
# cannot directly use ":openblas_lib",
75+
# need bridged through a `cc_library` containing ":openblas_lib"
76+
# i.e. ":openblas_lib_bazel"
77+
":openblas_lib_bazel"
78+
],
79+
copts =[
80+
"-DARMA_DONT_USE_WRAPPER"
81+
],
82+
linkopts = [
83+
# "-lpthread",
84+
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
85+
"-lgfortran",
86+
],
87+
)
88+
89+
cc_library(
90+
name = "hdf5_deps_lib",
91+
deps = [
92+
":z_lib",
93+
":libaec",
94+
],
95+
)
96+
97+
cmake(
98+
name = "hdf5_lib",
99+
cache_entries = {
100+
# "CMAKE_INSTALL_PREFIX": ".",
101+
# "CMAKE_INSTALL_INCLUDEDIR": "include",
102+
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
103+
# The directory structure of ":openblas_lib_bazel" are retained,
104+
# usually libraries are under /lib and headers are under /include
105+
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
106+
"BUILD_SHARED_LIBS": "OFF",
107+
"CMAKE_BUILD_TYPE": "Release",
108+
"HDF5_BUILD_TOOLS": "ON",
109+
"BUILD_TESTING": "ON",
110+
"SZIP_USE_EXTERNAL": "ON",
111+
"ZLIB_USE_EXTERNAL": "ON",
112+
"USE_LIBAEC_STATIC": "ON",
113+
"SZIP_INCLUDE_DIR": "$EXT_BUILD_DEPS/include",
114+
"ZLIB_INCLUDE_DIR": "$EXT_BUILD_DEPS/include",
115+
"SZIP_LIBRARY": "$EXT_BUILD_DEPS/lib/libsz.a",
116+
"ZLIB_LIBRARY": "$EXT_BUILD_DEPS/lib/libz.a",
117+
},
118+
lib_source = "@hdf5//:all_srcs",
119+
out_static_libs = ["libhdf5.a"],
120+
# out_include_dir = "include",
121+
deps = [
122+
# cannot directly use ":openblas_lib",
123+
# need bridged through a `cc_library` containing ":openblas_lib"
124+
# i.e. ":openblas_lib_bazel"
125+
# ":openblas_lib_bazel"
126+
":hdf5_deps_lib",
127+
],
128+
linkopts = [
129+
# "-lpthread",
130+
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
131+
# "-lgfortran",
132+
# "-lsz", "-lz",
133+
],
134+
)
135+
136+
cmake(
137+
name = "z_lib",
138+
cache_entries = {
139+
# "CMAKE_INSTALL_PREFIX": ".",
140+
# "CMAKE_INSTALL_INCLUDEDIR": "include",
141+
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
142+
# The directory structure of ":openblas_lib_bazel" are retained,
143+
# usually libraries are under /lib and headers are under /include
144+
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
145+
"BUILD_SHARED_LIBS": "OFF",
146+
},
147+
lib_source = "@zlib//:all_srcs",
148+
out_static_libs = ["libz.a"],
149+
# out_include_dir = "include",
150+
deps = [
151+
# cannot directly use ":openblas_lib",
152+
# need bridged through a `cc_library` containing ":openblas_lib"
153+
# i.e. ":openblas_lib_bazel"
154+
# ":openblas_lib_bazel"
155+
],
156+
linkopts = [
157+
# "-lpthread",
158+
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
159+
# "-lgfortran",
160+
],
161+
)
162+
163+
cmake(
164+
name = "libaec",
165+
cache_entries = {
166+
# "CMAKE_INSTALL_PREFIX": ".",
167+
# "CMAKE_INSTALL_INCLUDEDIR": "include",
168+
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
169+
# The directory structure of ":openblas_lib_bazel" are retained,
170+
# usually libraries are under /lib and headers are under /include
171+
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
172+
"BUILD_SHARED_LIBS": "OFF",
173+
},
174+
lib_source = "@libaec//:all_srcs",
175+
out_static_libs = [
176+
"libaec.a",
177+
"libsz.a",
178+
],
179+
# out_include_dir = "include",
180+
deps = [
181+
# cannot directly use ":openblas_lib",
182+
# need bridged through a `cc_library` containing ":openblas_lib"
183+
# i.e. ":openblas_lib_bazel"
184+
# ":openblas_lib_bazel"
185+
],
186+
linkopts = [
187+
# "-lpthread",
188+
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
189+
# "-lgfortran",
190+
],
191+
)
192+
193+
#
194+
configure_make(
195+
name = "libmatio_lib",
196+
configure_in_place = True,
197+
configure_options = [
198+
"--enable-mat73=yes",
199+
"--enable-extended-sparse=yes",
200+
"--with-zlib=\"$EXT_BUILD_DEPS/hdf5_lib/lib\"",
201+
"--with-hdf5=\"$EXT_BUILD_DEPS/z_lib/lib\"",
202+
"--with-default-file-ver=7.3",
203+
],
204+
lib_source = "@libmatio//:all_srcs",
205+
deps = [
206+
# cannot directly use ":openblas_lib",
207+
# need bridged through a `cc_library` containing ":openblas_lib"
208+
# i.e. ":openblas_lib_bazel"
209+
":hdf5_lib",
210+
":z_lib",
211+
],
212+
out_static_libs = ["libmatio.a"],
213+
linkopts = ["-lpthread"],
214+
)
215+
216+
cmake(
217+
name = "libjsoncpp",
218+
cache_entries = {
219+
# "CMAKE_INSTALL_PREFIX": ".",
220+
# "CMAKE_INSTALL_INCLUDEDIR": "include",
221+
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
222+
# The directory structure of ":openblas_lib_bazel" are retained,
223+
# usually libraries are under /lib and headers are under /include
224+
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
225+
"BUILD_SHARED_LIBS": "OFF",
226+
},
227+
lib_source = "@jsoncpp//:all_srcs",
228+
out_static_libs = [
229+
"libjsoncpp.a",
230+
],
231+
# out_include_dir = "include",
232+
deps = [
233+
# cannot directly use ":openblas_lib",
234+
# need bridged through a `cc_library` containing ":openblas_lib"
235+
# i.e. ":openblas_lib_bazel"
236+
# ":openblas_lib_bazel"
237+
],
238+
linkopts = [
239+
# "-lpthread",
240+
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
241+
# "-lgfortran",
242+
],
243+
)

MODULE.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
###############################################################################
2+
# Bazel now uses Bzlmod by default to manage external dependencies.
3+
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
4+
#
5+
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
6+
###############################################################################

0 commit comments

Comments
 (0)