Skip to content

Commit

Permalink
Add -static flag to MARCO driver and enable shared MARCO runtime libr…
Browse files Browse the repository at this point in the history
…aries
  • Loading branch information
mscuttari committed Nov 2, 2024
1 parent 90c866d commit a782363
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 25 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5516,7 +5516,7 @@ def start_no_unused_arguments : Flag<["--"], "start-no-unused-arguments">,
def static_libgcc : Flag<["-"], "static-libgcc">;
def static_libstdcxx : Flag<["-"], "static-libstdc++">;
def static : Flag<["-", "--"], "static">, Group<Link_Group>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption, MarcoOption]>,
Flags<[NoArgumentUnused]>;
def std_default_EQ : Joined<["-"], "std-default=">;
def std_EQ : Joined<["-", "--"], "std=">,
Expand Down
5 changes: 0 additions & 5 deletions clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ if(WIN32)
set(system_libs version)
endif()

add_compile_definitions(
MARCO_LIBS_PATH=${MARCORuntime_LIBS_PATH}
MARCO_DEPENDENCIES_LIBS_PATH=${MARCORuntime_DEPENDENCIES_LIB_PATHS}
MARCO_LINK_EXTRA_FLAGS=${MARCORuntime_EXTRA_LINK_ARGS})

add_clang_library(clangDriver
Action.cpp
Compilation.cpp
Expand Down
85 changes: 66 additions & 19 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,16 @@ void tools::addMarcoLinkerArgs(
const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs)
{
bool staticBuild = Args.hasArg(options::OPT_static);

if (staticBuild) {
CmdArgs.push_back("-Bstatic");
} else {
CmdArgs.push_back("-Bdynamic");
}

// Get the name of the requested solver.
auto solverString =
auto solver =
Args.getLastArgValue(options::OPT_solver, "euler-forward");

// Add the main function to the simulation, if not explicitly discarded.
Expand All @@ -1367,41 +1375,80 @@ void tools::addMarcoLinkerArgs(
CmdArgs.push_back("-lMARCORuntimeSimulation");

// Add the libraries of the solver.
if (solverString == "euler-forward") {
if (solver == "euler-forward") {
CmdArgs.push_back("-lMARCORuntimeDriverEulerForward");
CmdArgs.push_back("-lMARCORuntimeSolverEulerForward");
} else if (solverString == "ida") {
} else if (solver == "ida") {
CmdArgs.push_back("-lMARCORuntimeDriverIDA");
CmdArgs.push_back("-lMARCORuntimeSolverIDA");
} else if (solverString == "rk4" ||
solverString.starts_with("rk-")) {
} else if (solver == "rk4" ||
solver.starts_with("rk-")) {
CmdArgs.push_back("-lMARCORuntimeDriverRungeKutta");
CmdArgs.push_back("-lMARCORuntimeSolverRungeKutta");
}

// Add the remaining runtime libraries.
CmdArgs.push_back("-lMARCORuntimeSolverKINSOL");
CmdArgs.push_back("-lMARCORuntimeSolverSUNDIALS");
CmdArgs.push_back("-lMARCORuntimePrinterCSV");
// Add the Modelica support library.
CmdArgs.push_back("-lMARCORuntimeSupport");

// Add the printer library.
CmdArgs.push_back("-lMARCORuntimePrinterCSV");

// Add the solver libraries.
if (staticBuild) {
CmdArgs.push_back("-lMARCORuntimeSolverKINSOL_static");
CmdArgs.push_back("-lMARCORuntimeSolverSUNDIALS_static");
} else {
CmdArgs.push_back("-lMARCORuntimeSolverKINSOL");
CmdArgs.push_back("-lMARCORuntimeSolverSUNDIALS");
}

// Add the utility libraries.
CmdArgs.push_back("-lMARCORuntimeCLI");
CmdArgs.push_back("-lMARCORuntimeModeling");
CmdArgs.push_back("-lMARCORuntimeMultithreading");
CmdArgs.push_back("-lMARCORuntimeProfiling");

if (solverString == "ida") {
CmdArgs.push_back("-lsundials_ida");
if (staticBuild) {
CmdArgs.push_back("-lMARCORuntimeProfiling_static");
} else {
CmdArgs.push_back("-lMARCORuntimeProfiling");
}

CmdArgs.push_back("-lsundials_kinsol");
CmdArgs.push_back("-lsundials_nvecserial");
CmdArgs.push_back("-lsundials_sunlinsolklu");
CmdArgs.push_back("-lklu");
// Add the options libraries.
if (staticBuild) {
CmdArgs.push_back("-lMARCORuntimeOptionsCSVPrinter_static");

if (solver == "euler-forward") {
CmdArgs.push_back("-lMARCORuntimeOptionsEulerForward_static");
} else if (solver == "ida") {
CmdArgs.push_back("-lMARCORuntimeOptionsIDA_static");
} else if (solver == "rk4" ||
solver.starts_with("rk-")) {
CmdArgs.push_back("-lMARCORuntimeOptionsRungeKutta_static");
}

CmdArgs.push_back("-lMARCORuntimeOptionsKINSOL_static");

// Utility functions provided by MLIR.
CmdArgs.push_back("-lmlir_c_runner_utils");
CmdArgs.push_back("-lMARCORuntimeOptionsMultithreading_static");
CmdArgs.push_back("-lMARCORuntimeOptionsSimulation_static");
} else {
CmdArgs.push_back("-lMARCORuntimeOptionsCSVPrinter");

if (solver == "euler-forward") {
CmdArgs.push_back("-lMARCORuntimeOptionsEulerForward");
} else if (solver == "ida") {
CmdArgs.push_back("-lMARCORuntimeOptionsIDA");
} else if (solver == "rk4" ||
solver.starts_with("rk-")) {
CmdArgs.push_back("-lMARCORuntimeOptionsRungeKutta");
}

CmdArgs.push_back("-lMARCORuntimeOptionsKINSOL");

CmdArgs.push_back("-lMARCORuntimeOptionsMultithreading");
CmdArgs.push_back("-lMARCORuntimeOptionsSimulation");
}

// Standard libraries.
// System libraries.
CmdArgs.push_back("-lm");
CmdArgs.push_back("-lpthread");

Expand Down

0 comments on commit a782363

Please sign in to comment.