Browse Source

Support for "builtin" toolchains

default_compile_flags
vector-of-bool 5 years ago
parent
commit
5148174126
3 changed files with 42 additions and 31 deletions
  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 View File

} }
} }


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_dir = params.out_root / "obj";
auto obj_relpath = fs::relative(src_path, params.root); 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; auto obj_path = obj_dir / obj_relpath;
fs::create_directories(obj_path.parent_path()); fs::create_directories(obj_path.parent_path());


spec.definitions.push_back(def); 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); auto compile_res = run_proc(cmd);
if (!compile_res.okay()) { if (!compile_res.okay()) {
spdlog::error("Compilation failed: {}", spec.source_path.string()); spdlog::error("Compilation failed: {}", spec.source_path.string());
lm_write_pairs(export_root / "lib.lml", lm_pairs); 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 // We don't bother with a nice thread pool, as the overhead of compiling
// source files dwarfs the cost of interlocking. // source files dwarfs the cost of interlocking.
std::mutex mut; std::mutex mut;
} }
lk.unlock(); lk.unlock();
try { try {
auto obj_path = compile_file(source.path, params, tc, man);
auto obj_path = compile_file(source.path, params, man);
lk.lock(); lk.lock();
objects.emplace_back(std::move(obj_path)); objects.emplace_back(std::move(obj_path));
} catch (...) { } catch (...) {
} // namespace } // namespace


void dds::build(const build_params& params, const library_manifest& man) { 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 include_dir = params.root / "include";
auto src_dir = params.root / "src"; auto src_dir = params.root / "src";


} }


archive_spec arc; 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()); 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)) { if (fs::exists(arc.out_path)) {
fs::remove(arc.out_path); fs::remove(arc.out_path);
} }

+ 9
- 8
src/dds/build.hpp View File

#define DDS_BUILD_HPP_INCLUDED #define DDS_BUILD_HPP_INCLUDED


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


#include <optional> #include <optional>
namespace dds { namespace dds {


struct build_params { 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); void build(const build_params&, const library_manifest& man);

+ 22
- 7
src/dds/ddslim.main.cpp View File

{"export-name", 'n'}, {"export-name", 'n'},
dds::fs::current_path().filename().string()}; 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 export_{cmd, "export_dir", "Generate a library export", {"export", 'E'}};


args::Flag enable_warnings{cmd, args::Flag enable_warnings{cmd,
{"jobs", 'j'}, {"jobs", 'j'},
0}; 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() { int run() {
dds::build_params params; dds::build_params params;
params.root = lib_dir.Get(); params.root = lib_dir.Get();
params.out_root = out_dir.Get(); params.out_root = out_dir.Get();
params.toolchain_file = tc_filepath.Get();
params.export_name = export_name.Get(); params.export_name = export_name.Get();
params.toolchain = _get_toolchain();
params.do_export = export_.Get(); params.do_export = export_.Get();
params.build_tests = build_tests.Get(); params.build_tests = build_tests.Get();
params.enable_warnings = enable_warnings.Get(); params.enable_warnings = enable_warnings.Get();

Loading…
Cancel
Save