Bladeren bron

Support for "builtin" toolchains

default_compile_flags
vector-of-bool 5 jaren geleden
bovenliggende
commit
5148174126
3 gewijzigde bestanden met toevoegingen van 42 en 31 verwijderingen
  1. +11
    -16
      src/dds/build.cpp
  2. +9
    -8
      src/dds/build.hpp
  3. +22
    -7
      src/dds/ddslim.main.cpp

+ 11
- 16
src/dds/build.cpp Bestand weergeven

@@ -99,13 +99,11 @@ void collect_sources(source_list& sf, const fs::path& source_dir) {
}
}

fs::path compile_file(fs::path src_path,
const build_params& params,
const toolchain& tc,
const library_manifest& man) {
fs::path compile_file(fs::path src_path, const build_params& params, const library_manifest& man) {
auto obj_dir = params.out_root / "obj";
auto obj_relpath = fs::relative(src_path, params.root);
obj_relpath.replace_filename(obj_relpath.filename().string() + ".o");
obj_relpath.replace_filename(obj_relpath.filename().string()
+ params.toolchain.object_suffix());
auto obj_path = obj_dir / obj_relpath;
fs::create_directories(obj_path.parent_path());

@@ -125,7 +123,7 @@ fs::path compile_file(fs::path src_path,
spec.definitions.push_back(def);
}

auto cmd = tc.create_compile_command(spec);
auto cmd = params.toolchain.create_compile_command(spec);
auto compile_res = run_proc(cmd);
if (!compile_res.okay()) {
spdlog::error("Compilation failed: {}", spec.source_path.string());
@@ -196,10 +194,8 @@ void generate_export(const build_params& params,
lm_write_pairs(export_root / "lib.lml", lm_pairs);
}

std::vector<fs::path> compile_sources(source_list sources,
const build_params& params,
const toolchain& tc,
const library_manifest& man) {
std::vector<fs::path>
compile_sources(source_list sources, const build_params& params, const library_manifest& man) {
// We don't bother with a nice thread pool, as the overhead of compiling
// source files dwarfs the cost of interlocking.
std::mutex mut;
@@ -226,7 +222,7 @@ std::vector<fs::path> compile_sources(source_list sources,
}
lk.unlock();
try {
auto obj_path = compile_file(source.path, params, tc, man);
auto obj_path = compile_file(source.path, params, man);
lk.lock();
objects.emplace_back(std::move(obj_path));
} catch (...) {
@@ -266,8 +262,6 @@ std::vector<fs::path> compile_sources(source_list sources,
} // namespace

void dds::build(const build_params& params, const library_manifest& man) {
auto tc = toolchain::load_from_file(params.toolchain_file);

auto include_dir = params.root / "include";
auto src_dir = params.root / "src";

@@ -300,12 +294,13 @@ void dds::build(const build_params& params, const library_manifest& man) {
}

archive_spec arc;
arc.input_files = compile_sources(sources, params, tc, man);
arc.input_files = compile_sources(sources, params, man);

arc.out_path = params.out_root / ("lib" + params.export_name + tc.archive_suffix());
arc.out_path
= params.out_root / ("lib" + params.export_name + params.toolchain.archive_suffix());

spdlog::info("Create archive {}", arc.out_path.string());
auto ar_cmd = tc.create_archive_command(arc);
auto ar_cmd = params.toolchain.create_archive_command(arc);
if (fs::exists(arc.out_path)) {
fs::remove(arc.out_path);
}

+ 9
- 8
src/dds/build.hpp Bestand weergeven

@@ -2,6 +2,7 @@
#define DDS_BUILD_HPP_INCLUDED

#include <dds/manifest.hpp>
#include <dds/toolchain.hpp>
#include <dds/util.hpp>

#include <optional>
@@ -9,14 +10,14 @@
namespace dds {

struct build_params {
fs::path root;
fs::path out_root;
fs::path toolchain_file;
std::string export_name;
bool do_export = false;
bool build_tests = false;
bool enable_warnings = false;
int parallel_jobs = 0;
fs::path root;
fs::path out_root;
dds::toolchain toolchain;
std::string export_name;
bool do_export = false;
bool build_tests = false;
bool enable_warnings = false;
int parallel_jobs = 0;
};

void build(const build_params&, const library_manifest& man);

+ 22
- 7
src/dds/ddslim.main.cpp Bestand weergeven

@@ -43,13 +43,13 @@ struct cli_build {
{"export-name", 'n'},
dds::fs::current_path().filename().string()};

path_flag tc_filepath{cmd,
"toolchain_file",
"Path to the toolchain file to use",
{"toolchain-file", 'T'},
dds::fs::current_path() / "toolchain.dds"};
string_flag tc_filepath{cmd,
"toolchain_file",
"Path to the toolchain file to use",
{"toolchain-file", 'T'},
(dds::fs::current_path() / "toolchain.dds").string()};

args::Flag build_tests{cmd, "build_tests", "Build the tests", {"tests"}};
args::Flag build_tests{cmd, "build_tests", "Build the tests", {"tests", 't'}};
args::Flag export_{cmd, "export_dir", "Generate a library export", {"export", 'E'}};

args::Flag enable_warnings{cmd,
@@ -63,12 +63,27 @@ struct cli_build {
{"jobs", 'j'},
0};

dds::toolchain _get_toolchain() {
const auto tc_path = tc_filepath.Get();
if (tc_path.find(":") == 0) {
auto default_tc = tc_path.substr(1);
auto tc = dds::toolchain::get_builtin(default_tc);
if (!tc.has_value()) {
throw std::runtime_error(
fmt::format("Invalid default toolchain name '{}'", default_tc));
}
return std::move(*tc);
} else {
return dds::toolchain::load_from_file(tc_path);
}
}

int run() {
dds::build_params params;
params.root = lib_dir.Get();
params.out_root = out_dir.Get();
params.toolchain_file = tc_filepath.Get();
params.export_name = export_name.Get();
params.toolchain = _get_toolchain();
params.do_export = export_.Get();
params.build_tests = build_tests.Get();
params.enable_warnings = enable_warnings.Get();

Laden…
Annuleren
Opslaan