Skip to content

Commit

Permalink
Add a new build script
Browse files Browse the repository at this point in the history
  • Loading branch information
wortiz committed Aug 7, 2024
1 parent a08cb0f commit ec8fe8f
Show file tree
Hide file tree
Showing 29 changed files with 1,631 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.a
*.o
*.pyc
__pycache__
goma
.cproject
.project
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ endif()

option(ENABLE_OMEGA_H "ENABLE_OMEGA_H" ON)
if(ENABLE_OMEGA_H)
find_package(Omega_h 9)
find_package(Omega_h)
if(Omega_h_FOUND)
set_target_properties(Omega_h::omega_h PROPERTIES INTERFACE_COMPILE_OPTIONS
"")
Expand Down
23 changes: 23 additions & 0 deletions tpls/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:22.04

RUN apt update
RUN apt install -y git build-essential m4 zlib1g-dev libx11-dev gfortran pkg-config autoconf python3-dev vim tmux nano gdb valgrind gcc-12 g++-12 gfortran-12 libssl-dev
RUN apt autoremove && apt clean

COPY ./ /opt/build-script/

RUN /opt/build-script/install-tpls.py --cc=gcc-12 --cxx=g++-12 --fc=gfortran-12 --build-shared=yes --download-dir=/tmp/downloads -j 32 --extract-dir=/tmp/extract /opt/goma_libs


RUN cp /opt/build-script/config.sh > /entrypoint.sh \
&& chmod a+x /entrypoint.sh

RUN { \
echo '#!/usr/bin/env bash' \
&& echo ". /opt/goma_libs/config.sh" \
&& echo 'exec "$@"'; \
} > /entrypoint.sh \

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/bin/bash" ]

96 changes: 96 additions & 0 deletions tpls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,99 @@
These are third party libraries with separate license files.

Please look at comments or license files for the separate license

# Script to install all tpls

Third party libraries required for Goma can be installed using the `install-tpls.py` script
available in this directory.

Examples:

Build with a nonstandard compiler:

./install-tpls.py --cc=gcc-13 --cxx=g++-13 --fc=gfortran-13 /path/to/install

Build with a prebuilt openmpi:

./install-tpls.py --cc=mpicc --cxx=mpicxx --fc==mpifort --openmpi-dir=$MPI_HOME /path/to/install

Build with static libraries, shared is set by default:

./install-tpls.py --build-shared=no /path/to/install

Reuse downloads:

./install-tpls.py --download-dir=/path/to/downloads /path/to/install

Default locations:

Downloads are downloaded to `/path/to/install/downloads`, and sources/builds are found in `/path/to/install/sources`
feel free to remove after installation.

## Usage

Once installed a `config.sh` and `config.fish` file are generated in `/path/to/install` and can be sourced
in your shell of choice and used to compile and run Goma.


Usage:

usage: install-tpls.py [-h] [--cc CC] [--cxx CXX] [--fc FC] [--download-dir DOWNLOAD_DIR] [--extract-dir EXTRACT_DIR] [--build-shared BUILD_SHARED]
[-j JOBS] [--cmake-dir CMAKE_DIR] [--openmpi-dir OPENMPI_DIR] [--hdf5-dir HDF5_DIR] [--pnetcdf-dir PNETCDF_DIR]
[--netcdf-dir NETCDF_DIR] [--fmt-dir FMT_DIR] [--seacas-dir SEACAS_DIR] [--openblas-dir OPENBLAS_DIR] [--metis-dir METIS_DIR]
[--parmetis-dir PARMETIS_DIR] [--arpack_ng-dir ARPACK_NG_DIR] [--scalapack-dir SCALAPACK_DIR] [--mumps-dir MUMPS_DIR]
[--superlu_dist-dir SUPERLU_DIST_DIR] [--suitesparse-dir SUITESPARSE_DIR] [--trilinos-dir TRILINOS_DIR] [--petsc-dir PETSC_DIR]
[--omega_h-dir OMEGA_H_DIR]
INSTALL_DIR

Third party library installer for the finite element code Goma

positional arguments:
INSTALL_DIR Install location of TPLs

options:
-h, --help show this help message and exit
--cc CC C compiler to use
--cxx CXX C++ compiler to use
--fc FC Fortran compiler to use
--download-dir DOWNLOAD_DIR
Download location of tarballs
--extract-dir EXTRACT_DIR
Extract and Build location
--build-shared BUILD_SHARED
Build shared libraries
-j JOBS, --jobs JOBS Number of parallel jobs
--cmake-dir CMAKE_DIR
System location of package cmake
--openmpi-dir OPENMPI_DIR
System location of package openmpi
--hdf5-dir HDF5_DIR System location of package hdf5
--pnetcdf-dir PNETCDF_DIR
System location of package pnetcdf
--netcdf-dir NETCDF_DIR
System location of package netcdf
--fmt-dir FMT_DIR System location of package fmt
--seacas-dir SEACAS_DIR
System location of package seacas
--openblas-dir OPENBLAS_DIR
System location of package openblas
--metis-dir METIS_DIR
System location of package metis
--parmetis-dir PARMETIS_DIR
System location of package parmetis
--arpack_ng-dir ARPACK_NG_DIR
System location of package arpack-ng
--scalapack-dir SCALAPACK_DIR
System location of package scalapack
--mumps-dir MUMPS_DIR
System location of package mumps
--superlu_dist-dir SUPERLU_DIST_DIR
System location of package superlu_dist
--suitesparse-dir SUITESPARSE_DIR
System location of package suitesparse
--trilinos-dir TRILINOS_DIR
System location of package trilinos
--petsc-dir PETSC_DIR
System location of package petsc
--omega_h-dir OMEGA_H_DIR
System location of package omega-h
146 changes: 146 additions & 0 deletions tpls/install-tpls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env python3
from tpl_tools.builder import Builder
from tpl_tools.registry import Registry
import importlib
import tpl_tools.utils as utils
import os
import argparse
import pathlib

packages = [
"cmake",
"openmpi",
"hdf5",
"pnetcdf",
"netcdf",
"fmt",
"seacas",
"openblas",
"metis",
"parmetis",
"arpack-ng",
"scalapack",
"mumps",
"superlu_dist",
"suitesparse",
"trilinos",
"petsc",
"omega_h",
]


if __name__ == "__main__":
CC = os.environ.get("CC")
CXX = os.environ.get("CXX")
FC = os.environ.get("FC")
tpl_registry = Registry()
logger = utils.PrintLogger()
parser = argparse.ArgumentParser(
description="""Third party library installer for the finite element code Goma"""
)
parser.add_argument("--cc", help="C compiler to use", type=pathlib.Path)
parser.add_argument("--cxx", help="C++ compiler to use", type=pathlib.Path)
parser.add_argument("--fc", help="Fortran compiler to use", type=pathlib.Path)
parser.add_argument(
"--download-dir", help="Download location of tarballs", type=pathlib.Path
)
parser.add_argument(
"--extract-dir", help="Extract and Build location", type=pathlib.Path
)
parser.add_argument(
"--build-shared", help="Build shared libraries", type=bool, default=False
)
parser.add_argument(
"-j", "--jobs", help="Number of parallel jobs", type=int, default=1
)
parser.add_argument(
"INSTALL_DIR", help="Install location of TPLs", type=pathlib.Path
)

for p in packages:
pm = importlib.import_module("tpl_tools." + ".".join(["packages", p]))
pc = pm.Package()
parser.add_argument(
"--" + pc.name.replace("-", "_") + "-dir",
help="System location of package {}".format(pc.name),
type=pathlib.Path,
)

args = parser.parse_args()

install_dir = os.path.abspath(os.path.expanduser(args.INSTALL_DIR))
download_dir = os.path.join(install_dir, "downloads")
if args.download_dir:
download_dir = os.path.abspath(os.path.expanduser(args.download_dir))
extract_dir = os.path.join(install_dir, "sources")
if args.extract_dir:
extract_dir = os.path.abspath(os.path.expanduser(args.extract_dir))

jobs = args.jobs

if args.cc:
if CC:
logger.log(
"CC {} is environment variable, overriding with --cc={}".format(
CC, args.cc
)
)
CC = str(args.cc)
if args.cxx:
CXX = str(args.cxx)
logger.log(
"CXX {} is environment variable, overriding with --cxx={}".format(
CXX, args.cxx
)
)
if args.fc:
FC = str(args.fc)
logger.log(
"FC {} is environment variable, overriding with --fc={}".format(FC, args.fc)
)

if CC:
tpl_registry.set_environment_variable("CC", CC)
if CXX:
tpl_registry.set_environment_variable("CXX", CXX)
if FC:
tpl_registry.set_environment_variable("FC", FC)
tpl_registry.set_environment_variable("F77", FC)

for p in packages:
pm = importlib.import_module("tpl_tools." + ".".join(["packages", p]))
pc = pm.Package()
if getattr(args, pc.name.replace("-", "_") + "_dir"):
package_dir = getattr(args, pc.name + "_dir")

build = Builder(
pc, jobs, download_dir, extract_dir, package_dir, logger, tpl_registry, args.build_shared
)
if build.check(True):
build.logger.log("Package {} found at {}".format(pc.name, package_dir))
else:
break
build.register()
else:
build = Builder(
pc, jobs, download_dir, extract_dir, install_dir, logger, tpl_registry, args.build_shared
)

if build.check():
build.logger.log(
"Package {} already built, skipping".format(build._package.name)
)
build.register()
continue
build.download()
build.extract()
build.build()
build.install()
if not build.check():
break
build.register()
tpl_registry.config.write_config(os.path.join(install_dir,"config.sh"))
logger.log("Bash config written to {}, source with bash".format(os.path.join(install_dir, "config.sh")))

tpl_registry.config.write_config(os.path.join(install_dir,"config.fish"), shell="fish")
logger.log("Fish config written to {}, source with fish".format(os.path.join(install_dir, "config.fish")))
Empty file added tpls/tpl_tools/__init__.py
Empty file.
Loading

0 comments on commit ec8fe8f

Please sign in to comment.