feat(initial): added portable mfem build system

This commit is contained in:
2026-09-05 07:11:05 -04:00
commit 6a54f2625e
49 changed files with 4344 additions and 0 deletions

2387
tools/build_mfem_bundle.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,51 @@
// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and
// other CEED contributors. All Rights Reserved.
// SPDX-License-Identifier: BSD-2-Clause
// Relocatable replacement for libCEED's installed JIT source-root object.
// Upstream normally compiles the installation prefix into libceed. Native
// source bundles here are shared libraries, so derive ../include from the
// loaded library instead. Emscripten has no runtime compiler/JIT filesystem.
#if defined(__EMSCRIPTEN__)
const char *CeedJitSourceRootDefault = "";
#else
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <dlfcn.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
static char ceed_jit_source_root[PATH_MAX];
const char *CeedJitSourceRootDefault = ceed_jit_source_root;
__attribute__((constructor)) static void CeedSetRelocatableJitSourceRoot(void) {
Dl_info info;
char library_path[PATH_MAX];
if (!dladdr((void *)&CeedJitSourceRootDefault, &info) || !info.dli_fname) {
return;
}
if (snprintf(library_path, sizeof library_path, "%s", info.dli_fname) < 0) {
return;
}
char *separator = strrchr(library_path, '/');
if (!separator) {
return;
}
*separator = '\0';
(void)snprintf(ceed_jit_source_root, sizeof ceed_jit_source_root,
"%s/../include/", library_path);
}
#endif

39
tools/install_bundle.py Normal file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env python3
"""Copy a build-tree MFEM prefix into a Meson/meson-python destination."""
from __future__ import annotations
import argparse
import os
from pathlib import Path
import shutil
def staged_destination(destination: Path) -> Path:
destdir = os.environ.get("DESTDIR", "")
if not destdir or not destination.is_absolute():
return destination
destination_text = os.fspath(destination)
relative = destination_text[len(destination.anchor) :].lstrip("/\\")
return Path(destdir) / relative
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--source", type=Path, required=True)
parser.add_argument("--destination", type=Path, required=True)
args = parser.parse_args()
destination = staged_destination(args.destination)
destination.mkdir(parents=True, exist_ok=True)
for child in args.source.iterdir():
target = destination / child.name
if child.is_dir():
shutil.copytree(child, target, dirs_exist_ok=True, symlinks=True)
else:
shutil.copy2(child, target, follow_symlinks=False)
print(f"Installed MFEM native bundle to {destination}")
return 0
if __name__ == "__main__":
raise SystemExit(main())

33
tools/run_mpi_test.py Normal file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env python3
"""Run one MPI test without baking a particular MPI launcher into the meson build tree."""
from __future__ import annotations
import argparse
import os
import sys
import subprocess
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--launcher", required=True)
parser.add_argument("--processes", type=int, default=2)
parser.add_argument("executable")
parser.add_argument("arguments", nargs="*")
args = parser.parse_args()
command = [args.launcher, "-n", str(args.processes), args.executable, *args.arguments]
environment = dict(os.environ)
environment.setdefault("OMPI_ALLOW_RUN_AS_ROOT", "1")
environment.setdefault("OMPI_ALLOW_RUN_AS_ROOT_CONFIRM", "1")
loopback = "lo0" if sys.platform == "darwin" else "lo"
environment.setdefault("FI_PROVIDER", "sockets")
environment.setdefault("FI_SOCKETS_IFACE", loopback)
environment.setdefault("HYDRA_IFACE", loopback)
if sys.platform == "darwin":
environment.setdefault("MPICH_INTERFACE_HOSTNAME", "127.0.0.1")
return subprocess.run(command, env=environment, check=False).returncode
if __name__ == "__main__":
raise SystemExit(main())

66
tools/validate_matrix.sh Executable file
View File

@@ -0,0 +1,66 @@
#!/bin/sh
set -eu
project_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
meson_bin=${MESON_BIN:-meson}
meson_dir=$(CDPATH= cd -- "$(dirname -- "$meson_bin")" && pwd)
profile=${MFEM_MATRIX_PROFILE:-portable}
jobs=${MFEM_JOBS:-4}
compiler_family() {
"$1" --version 2>&1 | sed -n '1p'
}
require_clang() {
version=$(compiler_family "$1")
case "$version" in
*clang*|*Clang*) ;;
*) echo "error: $1 is not a Clang compiler: $version" >&2; exit 2 ;;
esac
}
require_gnu() {
version=$(compiler_family "$1")
case "$version" in
*gcc*|*GCC*|*"Free Software Foundation"*) ;;
*) echo "error: $1 is not a GNU compiler: $version" >&2; exit 2 ;;
esac
}
run_configuration() {
name=$1
c_compiler=$2
cxx_compiler=$3
mode=$4
build_dir="$project_root/build-$name"
if test -f "$build_dir/meson-private/coredata.dat"; then
wipe_flag=--wipe
else
wipe_flag=
fi
env PATH="$meson_dir:$PATH" CC="$c_compiler" CXX="$cxx_compiler" \
"$meson_bin" setup $wipe_flag "$build_dir" "$project_root" \
--buildtype="$mode" \
-Dallow_preinstalled=false \
-Dfeature_profile="$profile" \
-Dbuild_examples=true \
-Dbuild_tests=true \
-Dbuild_python=false \
-Djobs="$jobs"
env PATH="$meson_dir:$PATH" "$meson_bin" compile -C "$build_dir"
env PATH="$meson_dir:$PATH" "$meson_bin" test -C "$build_dir" --print-errorlogs
}
clang_cc=${CLANG_CC:-clang}
clang_cxx=${CLANG_CXX:-clang++}
gcc_cc=${GNU_CC:-gcc}
gcc_cxx=${GNU_CXX:-g++}
require_clang "$clang_cxx"
require_gnu "$gcc_cxx"
run_configuration clang-debug "$clang_cc" "$clang_cxx" debug
run_configuration clang-release "$clang_cc" "$clang_cxx" release
run_configuration gcc-debug "$gcc_cc" "$gcc_cxx" debug
run_configuration gcc-release "$gcc_cc" "$gcc_cxx" release