49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
|
|
import std;
|
||
|
|
import Crafter.Build;
|
||
|
|
namespace fs = std::filesystem;
|
||
|
|
using namespace Crafter;
|
||
|
|
|
||
|
|
// Build a tiny module-only static library and confirm libgreet.a lands in
|
||
|
|
// BinDir(). Exercises ConfigurationType::LibraryStatic, interface module
|
||
|
|
// parsing via GetInterfacesAndImplementations, and the ar/llvm-lib archive
|
||
|
|
// step in Crafter.Build-Clang.cpp.
|
||
|
|
int main() {
|
||
|
|
Configuration cfg;
|
||
|
|
cfg.path = fs::current_path() / "tests" / "StaticLib" / "fixture";
|
||
|
|
cfg.name = "greet";
|
||
|
|
cfg.outputName = "greet";
|
||
|
|
cfg.target = HostTarget();
|
||
|
|
cfg.type = ConfigurationType::LibraryStatic;
|
||
|
|
|
||
|
|
std::array<fs::path, 1> ifaces = { "Greet" };
|
||
|
|
std::array<fs::path, 0> impls = {};
|
||
|
|
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||
|
|
|
||
|
|
if (cfg.interfaces.size() != 1) {
|
||
|
|
std::println(std::cerr, "expected 1 interface, got {}", cfg.interfaces.size());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
if (cfg.interfaces[0]->name != "Greet") {
|
||
|
|
std::println(std::cerr, "expected interface 'Greet', got '{}'", cfg.interfaces[0]->name);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
|
||
|
|
std::mutex depMutex;
|
||
|
|
BuildResult r = Build(cfg, depResults, depMutex);
|
||
|
|
if (!r.result.empty()) {
|
||
|
|
std::println(std::cerr, "build failed: {}", r.result);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
fs::path archive = cfg.BinDir() / "libgreet.a";
|
||
|
|
if (!fs::exists(archive)) {
|
||
|
|
std::println(std::cerr, "archive not produced at {}", archive.string());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
if (fs::file_size(archive) == 0) {
|
||
|
|
std::println(std::cerr, "archive {} is empty", archive.string());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|