Skip to content

Commit 6b8e849

Browse files
committed
feat: allow adding cpp1 module third party deps in build.cpp2
1 parent 41b9339 commit 6b8e849

File tree

4 files changed

+438
-30
lines changed

4 files changed

+438
-30
lines changed

.clang-format

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,100 @@
1-
UseTab: Always
2-
IndentWidth: 4
3-
TabWidth: 4
1+
AccessModifierOffset: -2
2+
AlignAfterOpenBracket: BlockIndent
3+
AlignConsecutiveAssignments: false
4+
AlignConsecutiveDeclarations: true
5+
AlignEscapedNewlines: Left
6+
AlignOperands: DontAlign
7+
AlignTrailingComments: false
8+
AllowAllArgumentsOnNextLine: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: None
13+
AllowShortIfStatementsOnASingleLine: WithoutElse
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterDefinitionReturnType: None
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: true
18+
AlwaysBreakTemplateDeclarations: Yes
19+
BinPackArguments: false
20+
BinPackParameters: false
21+
BraceWrapping:
22+
AfterClass: false
23+
AfterControlStatement: false
24+
AfterEnum: false
25+
AfterFunction: false
26+
AfterNamespace: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
AfterExternBlock: false
30+
BeforeCatch: false
31+
BeforeElse: false
32+
IndentBraces: false
33+
SplitEmptyFunction: false
34+
SplitEmptyRecord: false
35+
SplitEmptyNamespace: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakBeforeBinaryOperators: None
38+
BreakBeforeBraces: Custom
39+
BreakBeforeInheritanceComma: false
40+
BreakBeforeTernaryOperators: true
41+
BreakConstructorInitializers: BeforeComma
42+
BreakConstructorInitializersBeforeComma: false
43+
BreakStringLiterals: true
44+
ColumnLimit: 80
45+
CompactNamespaces: false
46+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
47+
ConstructorInitializerIndentWidth: 2
48+
ContinuationIndentWidth: 2
49+
Cpp11BracedListStyle: true
50+
DerivePointerAlignment: false
51+
DisableFormat: false
52+
ExperimentalAutoDetectBinPacking: false
53+
FixNamespaceComments: true
54+
IncludeBlocks: Preserve
55+
IncludeIsMainRegex: "(Test)?$"
56+
IndentCaseLabels: true
57+
IndentPPDirectives: AfterHash
58+
IndentWrappedFunctionNames: false
59+
InsertBraces: true
60+
JavaScriptQuotes: Leave
61+
JavaScriptWrapImports: true
62+
KeepEmptyLinesAtTheStartOfBlocks: false
63+
MacroBlockBegin: ""
64+
MacroBlockEnd: ""
65+
MaxEmptyLinesToKeep: 1
66+
NamespaceIndentation: None
67+
PackConstructorInitializers: NextLine
68+
PenaltyBreakAssignment: 10
69+
PenaltyBreakBeforeFirstCallParameter: 30
70+
PenaltyBreakComment: 10
71+
PenaltyBreakFirstLessLess: 0
72+
PenaltyBreakString: 10
73+
PenaltyExcessCharacter: 400
74+
PenaltyReturnTypeOnItsOwnLine: 350
75+
PointerAlignment: Left
76+
ReflowComments: true
77+
RequiresClausePosition: OwnLine
78+
SortIncludes: false
79+
SortUsingDeclarations: true
80+
SpaceAfterCStyleCast: false
81+
SpaceAfterLogicalNot: false
82+
SpaceAfterTemplateKeyword: false
83+
SpaceBeforeAssignmentOperators: true
84+
SpaceBeforeCtorInitializerColon: true
85+
SpaceBeforeInheritanceColon: true
86+
SpaceBeforeParens: Never
87+
SpaceBeforeRangeBasedForLoopColon: true
88+
SpaceInEmptyParentheses: false
89+
SpacesBeforeTrailingComments: 1
90+
SpacesInAngles: Never
91+
SpacesInContainerLiterals: false
92+
SpacesInCStyleCastParentheses: false
93+
SpacesInParentheses: false
94+
SpacesInSquareBrackets: false
95+
SeparateDefinitionBlocks: Always
96+
Standard: Latest
97+
UseTab: Never
98+
IndentWidth: 2
99+
TabWidth: 2
100+

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ insert_final_newline = true
66
indent_style = tab
77
indent_size = 4
88

9+
[*.{cppm.tpl}]
10+
indent_style = space
11+
indent_size = 2
12+
913
[*.{sh,cmd}]
1014
indent_size = 4
1115
indent_style = space

share/cpp2b/cpp2b.build.cppm.tpl

Lines changed: 172 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,191 @@ export module cpp2b.build;
1111
import std;
1212

1313
struct 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("\033[0;31mINTERNAL ERROR\033[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

1882
export 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+
19149
class build {
20-
cpp2b_detail_build_impl *impl;
150+
cpp2b_detail_build_impl* impl;
21151
22152
public:
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

Comments
 (0)