@@ -11,35 +11,191 @@ export module cpp2b.build;
1111import std;
1212
1313struct cpp2b_detail_build_impl;
14- CPP2B_BUILD_API void (*cpp2b_detail_build_binary_name)(
15- cpp2b_detail_build_impl *, std::filesystem::path,
16- std::string_view) = nullptr;
14+ struct cpp2b_detail_git_repo_impl;
15+ struct cpp2b_detail_cpp1_module_impl;
16+
17+ template<typename Signature >
18+ using func_ptr = Signature*;
19+
20+ #define CPP2B_BUILD_DECL_FN(name, signature) \
21+ CPP2B_BUILD_API func_ptr<signature > name = nullptr
22+
23+ #define CPP2B_BUILD_FN_CHECK(name) \
24+ if(name == nullptr) { \
25+ std::println(" \0 33[0;31mINTERNAL ERROR\0 33[0m: {} is unset" , #name); \
26+ std::exit(1); \
27+ } \
28+ static_assert(true, "macro needs semicolon")
29+
30+ CPP2B_BUILD_DECL_FN(
31+ cpp2b_detail_build_binary_name,
32+ void(
33+ cpp2b_detail_build_impl* impl,
34+ std::filesystem::path p,
35+ std::string_view name
36+ )
37+ );
38+
39+ CPP2B_BUILD_DECL_FN(
40+ cpp2b_detail_git_clone,
41+ std::shared_ptr<cpp2b _detail_git_repo_impl >(
42+ cpp2b_detail_build_impl* impl,
43+ std::string_view clone_url,
44+ std::string_view commitish
45+ )
46+ );
47+
48+ CPP2B_BUILD_DECL_FN(
49+ cpp2b_detail_git_repo_path,
50+ std::filesystem::path(const cpp2b_detail_git_repo_impl* impl)
51+ );
52+
53+ CPP2B_BUILD_DECL_FN(
54+ cpp2b_detail_cpp1_module_source_path,
55+ void(cpp2b_detail_cpp1_module_impl* impl, std::filesystem::path p)
56+ );
57+
58+ CPP2B_BUILD_DECL_FN(
59+ cpp2b_detail_cpp1_module_include_directory,
60+ void(cpp2b_detail_cpp1_module_impl* impl, std::filesystem::path p)
61+ );
62+
63+ CPP2B_BUILD_DECL_FN(
64+ cpp2b_detail_cpp1_module_system_include_directory,
65+ void(cpp2b_detail_cpp1_module_impl* impl, std::filesystem::path p)
66+ );
67+
68+ CPP2B_BUILD_DECL_FN(
69+ cpp2b_detail_cpp1_module_define,
70+ void(
71+ cpp2b_detail_cpp1_module_impl* impl,
72+ std::string_view name,
73+ std::string_view value
74+ )
75+ );
76+
77+ CPP2B_BUILD_DECL_FN(
78+ cpp2b_detail_create_cpp1_module,
79+ std::shared_ptr<cpp2b _detail_cpp1_module_impl >(cpp2b_detail_build_impl* impl)
80+ );
1781
1882export namespace cpp2b {
83+ class git_repo {
84+ std::shared_ptr< cpp2b_detail_git_repo_impl> impl;
85+
86+ public:
87+ inline git_repo(std::shared_ptr< cpp2b_detail_git_repo_impl> impl)
88+ : impl(impl) {
89+ }
90+
91+ inline git_repo(const git_repo& other) : impl(other.impl) {
92+ }
93+
94+ inline git_repo(git_repo&& other) : impl(other.impl) {
95+ other.impl = nullptr;
96+ }
97+
98+ inline ~git_repo() = default;
99+
100+ inline auto path() const -> std::filesystem::path {
101+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_git_repo_path);
102+ return (*cpp2b_detail_git_repo_path)(impl.get());
103+ }
104+ };
105+
106+ class cpp1_module {
107+ std::shared_ptr< cpp2b_detail_cpp1_module_impl> impl;
108+
109+ public:
110+ inline cpp1_module(std::shared_ptr< cpp2b_detail_cpp1_module_impl> impl)
111+ : impl(impl) {
112+ }
113+
114+ inline cpp1_module(const cpp1_module& other) : impl(other.impl) {
115+ }
116+
117+ inline cpp1_module(cpp1_module&& other) : impl(other.impl) {
118+ other.impl = nullptr;
119+ }
120+
121+ inline ~cpp1_module() = default;
122+
123+ inline auto source_path(std::filesystem::path p) -> cpp1_module {
124+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_cpp1_module_source_path);
125+ (*cpp2b_detail_cpp1_module_source_path)(impl.get(), p);
126+ return *this;
127+ }
128+
129+ inline auto include_directory(std::filesystem::path p) -> cpp1_module {
130+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_cpp1_module_include_directory);
131+ (*cpp2b_detail_cpp1_module_include_directory)(impl.get(), p);
132+ return *this;
133+ }
134+
135+ inline auto system_include_directory(std::filesystem::path p) -> cpp1_module {
136+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_cpp1_module_system_include_directory);
137+ (*cpp2b_detail_cpp1_module_system_include_directory)(impl.get(), p);
138+ return *this;
139+ }
140+
141+ inline auto define(std::string_view name, std::string_view value)
142+ -> cpp1_module {
143+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_cpp1_module_define);
144+ (*cpp2b_detail_cpp1_module_define)(impl.get(), name, value);
145+ return *this;
146+ }
147+ };
148+
19149class build {
20- cpp2b_detail_build_impl * impl;
150+ cpp2b_detail_build_impl* impl;
21151
22152public:
23- inline build(cpp2b_detail_build_impl *impl) : impl(impl) {}
24- inline build(const build &other) : impl(other.impl ) {}
25- inline build(build &&other) : impl(other.impl ) { other.impl = nullptr; }
153+ inline build(cpp2b_detail_build_impl* impl) : impl(impl) {
154+ }
155+
156+ inline build(const build& other) : impl(other.impl) {
157+ }
158+
159+ inline build(build&& other) : impl(other.impl) {
160+ other.impl = nullptr;
161+ }
162+
26163 inline ~build() = default;
164+
27165 /**
28- * Renames a binary. By default binary names are the same name as their source
29- * file path with the extension replaced with the target platforms executable
30- * extension.
166+ * Renames a binary. By default binary names are the same name as their
167+ * source file path with the extension replaced with the target platforms
168+ * executable extension.
31169 */
32- inline auto binary_name(std::filesystem::path binary_source_path,
33- std::string_view new_binary_name) -> void {
34- return (*cpp2b_detail_build_binary_name)(impl, binary_source_path,
35- new_binary_name);
170+ inline auto binary_name(
171+ std::filesystem::path binary_source_path,
172+ std::string_view new_binary_name
173+ ) -> void {
174+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_build_binary_name);
175+ return (*cpp2b_detail_build_binary_name)(
176+ impl,
177+ binary_source_path,
178+ new_binary_name
179+ );
180+ }
181+
182+ inline auto git_clone(std::string_view clone_url, std::string_view commitish)
183+ -> git_repo {
184+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_git_clone);
185+ return git_repo{(*cpp2b_detail_git_clone)(impl, clone_url, commitish)} ;
186+ }
187+
188+ inline auto cpp1_module() -> cpp1_module {
189+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_create_cpp1_module);
190+ return ::cpp2b::cpp1_module{(*cpp2b_detail_create_cpp1_module)(impl)} ;
36191 }
37192};
193+
38194} // namespace cpp2b
39195
40- extern " C" void build(cpp2b::build & b);
196+ extern "C" void build(cpp2b::build& b);
41197
42- CPP2B_BUILD_API void cpp2b_detail_build(cpp2b_detail_build_impl * impl) {
198+ CPP2B_BUILD_API void cpp2b_detail_build(cpp2b_detail_build_impl* impl) {
43199 cpp2b::build b(impl);
44200 ::build(b);
45201}
0 commit comments