Compare commits

...
Author SHA1 Message Date
camierjs fce6061fc5 Update bazel build modes 2025-03-19 11:47:44 -07:00
camierjs 77dbf913cd Merge branch 'master' into bazel 2025-03-19 10:27:44 -07:00
camierjs 7634876c4a Bazel options and external paths 2025-03-19 10:27:37 -07:00
camierjs 32ef3785b8 Bazel update 2025-03-19 08:54:01 -07:00
camierjs ae3b5679d8 Update to latest Bazel 2024-12-10 06:48:24 -08:00
camierjs 3c0b691399 Merge branch 'master' into bazel 2024-12-10 06:22:21 -08:00
camierjs 78c9e777dc Merge branch 'master' into bazel 2024-11-20 20:00:44 -08:00
camierjs c909cf3d17 Update MODULE 2024-11-20 19:57:41 -08:00
camierjs e64606661f Merge branch 'master' into bazel 2024-10-16 15:22:11 -07:00
camierjs 07bf3bc22e Bazel WIP ubuntu focal externals 2024-09-29 17:45:27 +00:00
camierjs 2e3061f25e Add config file with mode, precision flags 2024-09-28 14:16:44 -07:00
camierjs 4ff56c6c33 Add disk cache 2024-09-27 14:50:49 -07:00
camierjs 80350d99a2 Add mode settings: serial and parallel 2024-09-27 14:25:25 -07:00
camierjs bf284f5405 MFEM macOS serial, parallel 2024-09-26 16:30:06 -07:00
camierjs d77dd735ab Merge remote-tracking branch 'origin/master' 2024-09-26 09:27:07 -07:00
camierjs 44837e59e8 Bazel script tries 2024-09-25 12:36:42 -07:00
camierjs a3d6ffa758 Bazel init 2024-09-23 17:11:15 -07:00
11 changed files with 803 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
bazel-bazel
bazel-bin
bazel-out
bazel-testlogs
+44
View File
@@ -0,0 +1,44 @@
# Bazel configuration file
# https://docs.bazel.build/versions/main/guide.html#bazelrc
# --compilation_mode [-c] (fastbuild, dbg or opt; default: "fastbuild")
# --[no]subcommands [-s] (true, pretty_print or false; default: "false")
# bazel clean --expunge
# Enable Bzlmod for every Bazel command
common --enable_bzlmod
# Build options ###############################################################
build --color=yes
# Disk cache setup ############################################################
build --disk_cache=/tmp/bazel_disk_cache
# Alias definition ############################################################
# Allow to specify the build mode and precision with the following flags:
# --mode=[serial|parallel]
# --precision=[single|double]
build --flag_alias=mode=//:mode
build --flag_alias=precision=//:precision
# Compilation options #########################################################
build --copt=-g
build --copt=-Wall
# build --copt=-Wextra
# build --copt=-Werror
build --copt=-std=c++17
build --cxxopt=-Wno-unused-parameter
build --strip=never
# build:macos --copt=-Werror
# build:macos --cxxopt=-Wno-error=deprecated-declarations
# build:macos --cxxopt=-Wno-error=deprecated-enum-enum-conversion
# build:macos --cxxopt=-Wno-error=deprecated-anon-enum-enum-conversion
# build:macos --cxxopt=-Wno-error=inconsistent-missing-override
# build:macos --cxxopt=-Wno-error=overloaded-virtual
# Prevent Bazel from detecting the system's C++ toolchain.
# build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
# build --incompatible_strict_action_env=true
# Enable the CC toolchain resolution based on platforms.
# build --incompatible_enable_cc_toolchain_resolution
+8
View File
@@ -19,6 +19,9 @@ CMakeFiles/
# Clangd server cache
*.cache*
# VSCode files
.vscode/
# Backup files
*~
@@ -51,6 +54,11 @@ doc/warnings.log
*.dSYM
.DS_Store
# Bazel specific
bazel-*
*.bazel_cache
MODULE.bazel.lock
# Example and miniapp binaries and outputs
examples/ex[0-9]
+468
View File
@@ -0,0 +1,468 @@
### String Flags ##############################################################
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
### Load rules ################################################################
load("@rules_cc//cc:defs.bzl", "cc_library")
### Load config/bazel/config ##################################################
load("//config/bazel:config.bzl", "mfem_serial_examples",
"mfem_parallel_examples", "mfem_use")
### Load config/bazel/settings ################################################
### https://bazel.build/docs/configurable-attributes
load("//config/bazel:settings.bzl", "mode", "precision", "print_mode", "print_precision")
# FLAG: Serial/Parallel MODE ##################################################
string_flag(
name = "mode",
values = ["serial", "parallel"],
build_setting_default = "serial",
)
mode(name = "serial")
mode(name = "parallel")
config_setting(
name = "serial_mode",
flag_values = {":mode": "serial"},
)
config_setting(
name = "parallel_mode",
flag_values = {":mode": "parallel"},
)
print_mode(
name = "print_mode",
mode = select({
":serial_mode": "serial",
":parallel_mode": "parallel",
}),
)
# FLAG: Double/Single PRECISION ###############################################
string_flag(
name = "precision",
values = ["single", "double"],
build_setting_default = "double",
)
precision(name = "double")
precision(name = "single")
config_setting(
name = "single_precision",
flag_values = {":precision": "single"},
)
config_setting(
name = "double_precision",
flag_values = {":precision": "double"},
)
print_precision(
name = "print_precision",
precision = select({
":single_precision": "single",
":double_precision": "double",
}),
)
# MFEM_USE_* definitions ######################################################
mfem_use(
name = "mfem_not_mpi",
define = "MFEM_USE_MPI",
use = False,
)
mfem_use(
name = "mfem_use_mpi",
define = "MFEM_USE_MPI",
use = True,
)
mfem_use(
name = "mfem_not_metis",
define = "MFEM_USE_METIS",
use = False,
)
mfem_use(
name = "mfem_use_metis",
define = "MFEM_USE_METIS",
use = True,
)
mfem_use(
name = "mfem_not_metis_5",
define = "MFEM_USE_METIS_5",
use = False,
)
mfem_use(
name = "mfem_use_metis_5",
define = "MFEM_USE_METIS_5",
use = True,
)
mfem_use(
name = "no_mfem_hypre_version",
define = "MFEM_HYPRE_VERSION",
use = False,
)
mfem_use(
name = "mfem_hypre_version",
define = "MFEM_HYPRE_VERSION",
use = True,
)
mfem_use(
name = "mfem_not_double",
define = "MFEM_USE_DOUBLE",
use = False,
)
mfem_use(
name = "mfem_use_double",
define = "MFEM_USE_DOUBLE",
use = True,
)
mfem_use(
name = "mfem_not_single",
define = "MFEM_USE_SINGLE",
use = False,
)
mfem_use(
name = "mfem_use_single",
define = "MFEM_USE_SINGLE",
use = True,
)
### https://bazel.build/reference/be/general#genrule
genrule(
name = "genrule_config_bazel",
srcs = ["BUILD"],
outs = ["config/bazel.hpp"],
cmd = """cat <<EOF > $@
// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.
#ifndef MFEM_CONFIG_HEADER
#define MFEM_CONFIG_HEADER
// MFEM version: integer of the form: (major*100 + minor)*100 + patch.
#define MFEM_VERSION 40701
// MFEM version string of the form "3.3" or "3.3.1".
#define MFEM_VERSION_STRING "4.7.1"
// MFEM version type, see the MFEM_VERSION_TYPE_* constants below.
#define MFEM_VERSION_TYPE ((MFEM_VERSION) % 2)
// MFEM version type constants.
#define MFEM_VERSION_TYPE_RELEASE 0
#define MFEM_VERSION_TYPE_DEVELOPMENT 1
// Separate MFEM version numbers for major, minor, and patch.
#define MFEM_VERSION_MAJOR ((MFEM_VERSION) / 10000)
#define MFEM_VERSION_MINOR (((MFEM_VERSION) / 100) % 100)
#define MFEM_VERSION_PATCH ((MFEM_VERSION) % 100)
// The absolute path of the MFEM source prefix.
#define MFEM_SOURCE_DIR "$$(realpath $$(realpath BUILD)/..)"
// The absolute path of the MFEM installation prefix.
#define MFEM_INSTALL_DIR "$$(realpath $(BINDIR))"
// Description of the git commit used to build MFEM.
#define MFEM_GIT_STRING "heads/bazel-git-..."
// Build the parallel MFEM library.
// Requires an MPI compiler, and the libraries HYPRE and METIS.
$(MFEM_USE_MPI)
// Enable MFEM features that use the METIS library (parallel MFEM).
$(MFEM_USE_METIS)
// Enable this option if linking with METIS version 5 (parallel MFEM).
$(MFEM_USE_METIS_5)
// Version of HYPRE used for building MFEM.
// macOS: 23200, ubuntu: 21821
$(MFEM_HYPRE_VERSION) 23200
// Use single/double-precision floating point type
$(MFEM_USE_DOUBLE)
$(MFEM_USE_SINGLE)
// Internal MFEM option: enable group/batch allocation for some small objects.
#define MFEM_USE_MEMALLOC
// Which library functions to use in class StopWatch for measuring time.
// For a list of the available options, see INSTALL.
// If not defined, an option is selected automatically.
// 0/1/2/3/4/5/6/NO
#define MFEM_TIMER_TYPE 0
#endif // MFEM_CONFIG_HEADER
EOF""",
local = False,
message = "Generating config bazel.hpp file",
toolchains = select({
":serial_mode": [
":mfem_not_mpi",
":mfem_not_metis",
":mfem_not_metis_5",
":no_mfem_hypre_version",
],
":parallel_mode": [
":mfem_use_mpi",
":mfem_use_metis",
":mfem_use_metis_5",
":mfem_hypre_version",
],
"//conditions:default": [
":mfem_not_mpi",
":mfem_not_metis",
":mfem_not_metis_5",
":mfem_hypre_version",
":mfem_use_double",
":mfem_not_single",
],
}) + select({
":double_precision": [
":mfem_use_double",
":mfem_not_single",
],
":single_precision": [
":mfem_not_double",
":mfem_use_single",
],
}),
)
cc_library(
name = "config_bazel_hpp",
srcs = ["config/bazel.hpp"],
includes = ["config"],
)
### MFEM Examples #############################################################
mfem_serial_examples()
mfem_parallel_examples()
### MFEM library ##############################################################
cc_library(
name = "mfem",
deps = [
"fem",
"general",
"linalg",
"mesh",
"@config",
] + select({
":parallel_mode": ["@mpi"],
"//conditions:default": [],
}),
)
### Sources ###################################################################
cc_library(
name = "fem",
srcs = glob([
"fem/*.cpp",
"fem/ceed/**/*.cpp",
"fem/fe/*.cpp",
"fem/integ/*.cpp",
"fem/lor/*.cpp",
# skip moonolith
"fem/qinterp/*.cpp",
"fem/tmop/*.cpp",
]),
deps = [
"config_hpp",
"fem_hpp",
"general_hpp",
"linalg_hpp",
"mesh_hpp",
] + select({
":parallel_mode": ["@mpi"],
"//conditions:default": [],
}),
)
cc_library(
name = "general",
srcs = glob(["general/*.cpp"]),
deps = [
"config_hpp",
"general_hpp",
"linalg_hpp",
] + select({
":parallel_mode": ["@mpi"],
"//conditions:default": [],
}),
)
cc_library(
name = "linalg",
srcs = glob(["linalg/**/*.cpp"]),
deps = [
"config_hpp",
"fem_hpp",
"general_hpp",
"linalg_hpp",
"mesh_hpp",
] + select({
":parallel_mode": ["@mpi"],
"//conditions:default": [],
}),
)
cc_library(
name = "mesh",
srcs = glob([
"mesh/*.cpp",
"mesh/submesh/*.cpp",
]),
deps = [
"config_hpp",
"fem_hpp",
"general_hpp",
"linalg_hpp",
"mesh_hpp",
] + select({
":parallel_mode": ["@mpi"],
"//conditions:default": [],
}),
)
### Headers ###################################################################
cc_library(
name = "examples_hpp",
srcs = glob(["examples/*.hpp"]),
)
cc_library(
name = "general_hpp",
srcs = glob(
[
"general/*.hpp",
"general/*.h",
],
),
)
cc_library(
name = "mfem_hpp",
srcs = ["mfem.hpp"],
deps = ["config_hpp"],
)
cc_library(
name = "config_hpp",
srcs = glob(["config/*.hpp"]),
deps = [
":config_bazel_hpp",
"@config",
],
)
cc_library(
name = "fem_hpp",
srcs = glob([
"fem/*.hpp",
"fem/*.h",
]),
deps = [
"config_hpp",
"fem_ceed_hpp",
"fem_fe_hpp",
"fem_integ_hpp",
"fem_lor_hpp",
# "fem_moonolith_hpp",
"fem_qinterp_hpp",
"fem_tmop_hpp",
],
)
cc_library(
name = "fem_ceed_hpp",
srcs = glob(["fem/ceed/**/*.hpp"]),
)
cc_library(
name = "fem_moonolith_hpp",
srcs = glob(["fem/moonolith/**/*.hpp"]),
)
cc_library(
name = "fem_fe_hpp",
srcs = glob(["fem/fe/*.hpp"]),
)
cc_library(
name = "fem_integ_hpp",
srcs = glob(["fem/integ/*.hpp"]),
)
cc_library(
name = "fem_lor_hpp",
srcs = glob(["fem/lor/*.hpp"]),
)
cc_library(
name = "fem_qinterp_hpp",
srcs = glob(["fem/qinterp/*.hpp"]),
)
cc_library(
name = "fem_tmop_hpp",
srcs = glob(["fem/tmop/*.hpp"]),
)
cc_library(
name = "linalg_hpp",
srcs = glob(["linalg/*.hpp"]),
deps = [
"linalg_batched_hpp",
"linalg_simd_hpp",
],
)
cc_library(
name = "linalg_batched_hpp",
srcs = glob(["linalg/batched/*.hpp"]),
)
cc_library(
name = "linalg_simd_hpp",
srcs = glob(["linalg/simd/*.hpp"]),
)
cc_library(
name = "mesh_hpp",
srcs = glob(["mesh/*.hpp"]),
deps = ["submesh_hpp"],
)
cc_library(
name = "submesh_hpp",
srcs = glob(["mesh/submesh/*.hpp"]),
)
+36
View File
@@ -0,0 +1,36 @@
"""
Bazel Central Registry: https://registry.bazel.build
"""
module(name = "mfem", version = "4.7")
# https://github.com/bazelbuild/rules_cc
# https://registry.bazel.build/modules/rules_cc
bazel_dep(name = "rules_cc", version = "0.1.1")
# https://github.com/bazel-contrib/toolchains_llvm/releases
# https://github.com/bazel-contrib/toolchains_llvm/blob/master/toolchain/internal/llvm_distributions.bzl
bazel_dep(name = "toolchains_llvm", version = "1.3.0")
# Configure and register the toolchain.
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
# llvm.toolchain(llvm_version = "16.0.0")
llvm.toolchain(llvm_version = "18.1.8")
# x86_64-linux-gnu-ubuntu-20.04 13.0.0
# x86_64-linux-gnu-ubuntu-22.04 17.0.6
# macOS 17.0.6
# llvm.toolchain(llvm_version = "17.0.6", stdlib = {"linux-x86_64": "stdc++"}) # libc++ / stdc++
use_repo(llvm, "llvm_toolchain")
register_toolchains("@llvm_toolchain//:all")
# https://github.com/bazelbuild/bazel-skylib/releases
bazel_dep(name = "bazel_skylib", version = "1.7.1")
# External dependencies
external = use_extension("//config/bazel:external.bzl", "external")
use_repo(external, "mpi")
use_repo(external, "hypre")
use_repo(external, "metis")
use_repo(external, "config")
View File
+49
View File
@@ -0,0 +1,49 @@
"""
Bazel configuration helper functions
"""
load("@rules_cc//cc:defs.bzl", "cc_binary")
### Examples ##################################################################
def mfem_serial_examples():
for n in range(1, 40):
example = "ex" + str(n)
cc_binary(
name = example,
srcs = ["examples/" + example + ".cpp"],
deps = [
"mfem",
"mfem_hpp",
"examples_hpp",
],
)
def mfem_parallel_examples():
for n in range(1, 40):
example = "ex" + str(n) + "p"
cc_binary(
name = example,
srcs = ["examples/" + example + ".cpp"],
deps = [
"mfem",
"mfem_hpp",
"examples_hpp",
"@mpi",
],
)
### MFEM_USE_* ################################################################
def _mfem_use(ctx):
value = "//" if not ctx.attr.use else ""
value += "#define " + ctx.attr.define
return [
platform_common.TemplateVariableInfo({ctx.attr.define: value}),
]
mfem_use = rule(
implementation = _mfem_use,
attrs = {
"define": attr.string(),
"use": attr.bool(),
},
)
+57
View File
@@ -0,0 +1,57 @@
"""Modules for dependencies not included in the Bazel Central Registry"""
# https://bazel.build/rules/lib/repo/local
load("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
def _external(_):
# MFEM configuration file
new_local_repository(
name = "config",
build_file_content = """
cc_library(
name = "config",
defines = ["MFEM_CONFIG_FILE=\\\\\\"config/bazel.hpp\\\\\\""],
visibility = ["//visibility:public"],
)""",
path = "",
)
# MPI implementation
new_local_repository(
name = "mpi",
build_file_content = """
cc_library(
name = "mpi",
srcs = ["lib/libmpi.dylib"],
hdrs = glob(["include/**/*.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
deps = ["@hypre", "@metis"],
)""",
path = "/opt/homebrew/opt/open-mpi",
)
new_local_repository(
name = "hypre",
build_file_content = """
cc_library(
name = "hypre",
srcs = ["lib/libHYPRE.a"],
hdrs = glob(["include/*.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
)""",
path = "/opt/homebrew/opt/hypre",
)
new_local_repository(
name = "metis",
build_file_content = """
cc_library(
name = "metis",
srcs = ["lib/libmetis.dylib"],
hdrs = glob(["include/metis.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
)""",
path = "/opt/homebrew/opt/metis",
)
external = module_extension(implementation = _external)
+61
View File
@@ -0,0 +1,61 @@
"""Modules for dependencies not included in the Bazel Central Registry"""
# https://bazel.build/rules/lib/repo/local
load("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
def _external(_):
new_local_repository(
name = "config",
build_file_content = """
cc_library(
name = "config",
defines = ["MFEM_CONFIG_FILE=\\\\\\"config/bazel.hpp\\\\\\""],
visibility = ["//visibility:public"],
)""",
path = "",
)
new_local_repository(
name = "mpi",
build_file_content = """
cc_library(
name = "mpi",
# srcs = ["lib/libmpi.dylib"],
srcs = ["lib/libmpi.so"],
hdrs = glob(["include/**/*.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
deps = ["@hypre", "@metis"],
)""",
path = "/usr/lib/x86_64-linux-gnu/openmpi"
)
new_local_repository(
name = "hypre",
build_file_content = """
cc_library(
name = "hypre",
# srcs = ["lib/libHYPRE.a"],
srcs = ["lib/x86_64-linux-gnu/libHYPRE.so",
"lib/x86_64-linux-gnu/libHYPRE_core.so"],
hdrs = glob(["include/hypre/*.h"]),
# includes = ["include"],
includes = ["include/hypre"],
visibility = ["//visibility:public"],
)""",
path = "/usr"
)
new_local_repository(
name = "metis",
build_file_content = """
cc_library(
name = "metis",
# srcs = ["lib/libmetis.dylib"],
srcs = ["lib/x86_64-linux-gnu/libmetis.so.5"],
hdrs = glob(["include/metis.h"]),
# includes = ["include"],
visibility = ["//visibility:public"],
)""",
# path = "/opt/homebrew/Cellar/metis/5.1.0",
path = "/usr",
)
external = module_extension(implementation = _external)
+55
View File
@@ -0,0 +1,55 @@
"""Modules for dependencies not included in the Bazel Central Registry"""
# https://bazel.build/rules/lib/repo/local
load("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
def _external(_):
new_local_repository(
name = "config",
build_file_content = """
cc_library(
name = "config",
defines = ["MFEM_CONFIG_FILE=\\\\\\"config/bazel.hpp\\\\\\""],
visibility = ["//visibility:public"],
)""",
path = "",
)
new_local_repository(
name = "mpi",
build_file_content = """
cc_library(
name = "mpi",
srcs = ["lib/libmpi.dylib"],
hdrs = glob(["include/**/*.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
deps = ["@hypre", "@metis"],
)""",
path = "/opt/homebrew/opt/open-mpi",
)
new_local_repository(
name = "hypre",
build_file_content = """
cc_library(
name = "hypre",
srcs = ["lib/libHYPRE.a"],
hdrs = glob(["include/*.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
)""",
path = "/opt/homebrew/opt/hypre",
)
new_local_repository(
name = "metis",
build_file_content = """
cc_library(
name = "metis",
srcs = ["lib/libmetis.dylib"],
hdrs = glob(["include/metis.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
)""",
path = "/opt/homebrew/opt/metis",
)
external = module_extension(implementation = _external)
+21
View File
@@ -0,0 +1,21 @@
"""
This module defines build settings: 'mode' and 'precision'.
"""
# Mode ########################################################################
ModeInfo = provider(doc = "serial or parallel", fields = ["type"])
def PrintMode(ctx):
ctx.actions.write(output = ctx.outputs.log,
content = "Compiling in " + ctx.attr.mode[ModeInfo].type + "!")
print_mode = rule(implementation = PrintMode, attrs = {"mode": attr.label()})
def Mode(ctx): return ModeInfo(type = ctx.label.name)
mode = rule(implementation = Mode)
# Precision ###################################################################
PrecisionInfo = provider(doc = "single or double", fields = ["type"])
def PrintPrecision(ctx):
ctx.actions.write(output = ctx.outputs.log,
content = "Compiling in " + ctx.attr.precision[PrecisionInfo].type + "!")
print_precision = rule(implementation = PrintPrecision, attrs = {"precision": attr.label()})
def Precision(ctx): return PrecisionInfo(type = ctx.label.name)
precision = rule(implementation = Precision)