@@ -11,35 +11,220 @@ 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_create_cpp1_module,
55+ std::shared_ptr<cpp2b _detail_cpp1_module_impl >(cpp2b_detail_build_impl* impl)
56+ );
57+
58+ CPP2B_BUILD_DECL_FN(
59+ cpp2b_detail_cpp1_module_source_path,
60+ void(
61+ cpp2b_detail_cpp1_module_impl* impl,
62+ std::filesystem::path p,
63+ std::source_location caller_srcloc
64+ )
65+ );
66+
67+ CPP2B_BUILD_DECL_FN(
68+ cpp2b_detail_cpp1_module_include_directory,
69+ void(
70+ cpp2b_detail_cpp1_module_impl* impl,
71+ std::filesystem::path p,
72+ std::source_location caller_srcloc
73+ )
74+ );
75+
76+ CPP2B_BUILD_DECL_FN(
77+ cpp2b_detail_cpp1_module_system_include_directory,
78+ void(
79+ cpp2b_detail_cpp1_module_impl* impl,
80+ std::filesystem::path p,
81+ std::source_location caller_srcloc
82+ )
83+ );
84+
85+ CPP2B_BUILD_DECL_FN(
86+ cpp2b_detail_cpp1_module_define,
87+ void(
88+ cpp2b_detail_cpp1_module_impl* impl,
89+ std::string_view name,
90+ std::string_view value,
91+ std::source_location caller_srcloc
92+ )
93+ );
1794
1895export namespace cpp2b {
96+ class git_repo {
97+ std::shared_ptr< cpp2b_detail_git_repo_impl> impl;
98+
99+ public:
100+ inline git_repo(std::shared_ptr< cpp2b_detail_git_repo_impl> impl)
101+ : impl(impl) {
102+ }
103+
104+ inline git_repo(const git_repo& other) : impl(other.impl) {
105+ }
106+
107+ inline git_repo(git_repo&& other) : impl(other.impl) {
108+ other.impl = nullptr;
109+ }
110+
111+ inline ~git_repo() = default;
112+
113+ inline auto path() const -> std::filesystem::path {
114+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_git_repo_path);
115+ return (*cpp2b_detail_git_repo_path)(impl.get());
116+ }
117+ };
118+
119+ class cpp1_module {
120+ std::shared_ptr< cpp2b_detail_cpp1_module_impl> impl;
121+
122+ public:
123+ inline cpp1_module(std::shared_ptr< cpp2b_detail_cpp1_module_impl> impl)
124+ : impl(impl) {
125+ }
126+
127+ inline cpp1_module(const cpp1_module& other) : impl(other.impl) {
128+ }
129+
130+ inline cpp1_module(cpp1_module&& other) : impl(other.impl) {
131+ other.impl = nullptr;
132+ }
133+
134+ inline ~cpp1_module() = default;
135+
136+ inline auto source_path(
137+ std::filesystem::path p,
138+ std::source_location caller_srcloc = std::source_location::current()
139+ ) -> cpp1_module {
140+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_cpp1_module_source_path);
141+ (*cpp2b_detail_cpp1_module_source_path)(impl.get(), p, caller_srcloc);
142+ return *this;
143+ }
144+
145+ inline auto include_directory(
146+ std::filesystem::path p,
147+ std::source_location caller_srcloc = std::source_location::current()
148+ ) -> cpp1_module {
149+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_cpp1_module_include_directory);
150+ (*cpp2b_detail_cpp1_module_include_directory)(impl.get(), p, caller_srcloc);
151+ return *this;
152+ }
153+
154+ inline auto system_include_directory(
155+ std::filesystem::path p,
156+ std::source_location caller_srcloc = std::source_location::current()
157+ ) -> cpp1_module {
158+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_cpp1_module_system_include_directory);
159+ (*cpp2b_detail_cpp1_module_system_include_directory)(
160+ impl.get(),
161+ p,
162+ caller_srcloc
163+ );
164+ return *this;
165+ }
166+
167+ inline auto define(
168+ std::string_view name,
169+ std::string_view value,
170+ std::source_location caller_srcloc = std::source_location::current()
171+ ) -> cpp1_module {
172+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_cpp1_module_define);
173+ (*cpp2b_detail_cpp1_module_define)(impl.get(), name, value, caller_srcloc);
174+ return *this;
175+ }
176+ };
177+
19178class build {
20- cpp2b_detail_build_impl * impl;
179+ cpp2b_detail_build_impl* impl;
21180
22181public:
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; }
182+ inline build(cpp2b_detail_build_impl* impl) : impl(impl) {
183+ }
184+
185+ inline build(const build& other) : impl(other.impl) {
186+ }
187+
188+ inline build(build&& other) : impl(other.impl) {
189+ other.impl = nullptr;
190+ }
191+
26192 inline ~build() = default;
193+
27194 /**
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.
195+ * Renames a binary. By default binary names are the same name as their
196+ * source file path with the extension replaced with the target platforms
197+ * executable extension.
31198 */
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);
199+ inline auto binary_name(
200+ std::filesystem::path binary_source_path,
201+ std::string_view new_binary_name
202+ ) -> void {
203+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_build_binary_name);
204+ return (*cpp2b_detail_build_binary_name)(
205+ impl,
206+ binary_source_path,
207+ new_binary_name
208+ );
209+ }
210+
211+ inline auto git_clone(std::string_view clone_url, std::string_view commitish)
212+ -> git_repo {
213+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_git_clone);
214+ return git_repo{(*cpp2b_detail_git_clone)(impl, clone_url, commitish)} ;
215+ }
216+
217+ inline auto cpp1_module() -> cpp1_module {
218+ CPP2B_BUILD_FN_CHECK(cpp2b_detail_create_cpp1_module);
219+ return ::cpp2b::cpp1_module{(*cpp2b_detail_create_cpp1_module)(impl)} ;
36220 }
37221};
222+
38223} // namespace cpp2b
39224
40- extern " C" void build(cpp2b::build & b);
225+ extern "C" void build(cpp2b::build& b);
41226
42- CPP2B_BUILD_API void cpp2b_detail_build(cpp2b_detail_build_impl * impl) {
227+ CPP2B_BUILD_API void cpp2b_detail_build(cpp2b_detail_build_impl* impl) {
43228 cpp2b::build b(impl);
44229 ::build(b);
45230}
0 commit comments