Skip to content

Commit

Permalink
nix build --lto flag
Browse files Browse the repository at this point in the history
  • Loading branch information
aothms committed May 12, 2024
1 parent 3bb651f commit b2db755
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion nix/build-all.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
###############################################################################
import logging
import os
import re
import sys
import subprocess as sp
import shutil
Expand Down Expand Up @@ -468,6 +469,8 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
# If the linker supports GC sections, set it up to reduce binary file size
# -fPIC is required for the shared libraries to work

compiler_flags = "CFLAGS", "CXXFLAGS", "LDFLAGS"

CXXFLAGS = os.environ.get("CXXFLAGS", "")
CFLAGS = os.environ.get("CFLAGS", "")
LDFLAGS = os.environ.get("LDFLAGS", "")
Expand All @@ -493,7 +496,11 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
CXXFLAGS=CXXFLAGS_MINIMAL
CFLAGS=CFLAGS_MINIMAL
LDFLAGS = f"{LDFLAGS} {ADDITIONAL_ARGS_STR}"


if "lto" in flags:
for f in compiler_flags:
locals()[f] += f" -flto={IFCOS_NUM_BUILD_PROCS}"

os.environ["CXXFLAGS"] = CXXFLAGS
os.environ["CFLAGS"] = CFLAGS
os.environ["LDFLAGS"] = LDFLAGS
Expand All @@ -503,6 +510,11 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
# build_dependency(name="cmake-%s" % (CMAKE_VERSION,), mode="autoconf", build_tool_args=[], download_url="https://cmake.org/files/v%s" % (CMAKE_VERSION_2,), download_name="cmake-%s.tar.gz" % (CMAKE_VERSION,))

if 'hdf5' in targets:
# not supported
orig = [os.environ[f] for f in compiler_flags]
for f in compiler_flags:
os.environ[f] = re.sub("-flto(=\w+)?", "", os.environ[f])

HDF5_MAJOR = ".".join(HDF5_VERSION.split(".")[:-1])
build_dependency(
name=f"hdf5-{HDF5_VERSION}",
Expand All @@ -513,6 +525,10 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
ctest_result=f"HDF5-{HDF5_VERSION}-{platform.system()}",
ctest_result_path=f"HDF_Group/HDF5/{HDF5_VERSION}"
)

for f, o in zip(compiler_flags, orig):
os.environ[f] = o


if "json" in targets:
json_url = f"https://github.com/nlohmann/json/releases/download/{JSON_VERSION}/json.hpp"
Expand Down

0 comments on commit b2db755

Please sign in to comment.