Skip to content

Commit 1879766

Browse files
committed
Improve cc builds.
1 parent d32b5e4 commit 1879766

9 files changed

Lines changed: 70 additions & 24 deletions

File tree

src/sw/builder/file_storage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void FileStorage::clear()
2222

2323
void FileStorage::reset()
2424
{
25-
for (auto &[k, f] : files)
25+
for (const auto &[k, f] : files)
2626
f.reset();
2727
}
2828

src/sw/client/command/build.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static void applySettingsFromFile(sw::TargetSettings &s, const path &fn)
255255
applySettingsFromJson(s, read_file(fn));
256256
}
257257

258-
static std::vector<sw::TargetSettings> create_settings(const sw::SwCoreContext &swctx)
258+
std::vector<sw::TargetSettings> create_settings(const sw::SwCoreContext &swctx)
259259
{
260260
std::vector<sw::TargetSettings> settings;
261261
settings.push_back(swctx.getHostSettings());

src/sw/client/command/commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@
3737
std::unique_ptr<sw::SwContext> createSwContext();
3838
sw::SourceDirMap fetch(sw::SwBuild &);
3939
sw::PackageDescriptionMap getPackages(const sw::SwBuild &, const sw::SourceDirMap & = {});
40+
std::vector<sw::TargetSettings> create_settings(const sw::SwCoreContext &swctx);

src/sw/client/command/generate.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,17 @@ SUBCOMMAND_DECL2(generate)
6565

6666
auto b = swctx.createBuild();
6767
for (auto &a : build_arg)
68-
b.addInput(a);
68+
{
69+
auto &i = b.addInput(a);
70+
for (auto &s : create_settings(swctx))
71+
i.addSettings(s);
72+
}
6973
b.load();
7074
b.setTargetsToBuild();
7175
b.resolvePackages();
76+
b.loadPackages();
7277
b.prepare();
7378

7479
auto generator = Generator::create(gGenerator);
75-
generator->generate(swctx);
80+
generator->generate(b);
7681
}

src/sw/core/target.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sw/manager/source.h>
1515

1616
#include <any>
17+
#include <variant>
1718

1819
namespace sw
1920
{
@@ -137,7 +138,7 @@ struct SimpleExpected : std::variant<SimpleExpectedErrorCode, T, Args...>
137138
: Base(e)
138139
{}
139140

140-
operator bool() const { return index() == 1; }
141+
operator bool() const { return Base::index() == 1; }
141142
T &operator*() { return std::get<1>(*this); }
142143
const T &operator*() const { return std::get<1>(*this); }
143144
T &operator->() { return std::get<1>(*this); }

src/sw/driver/checks.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ void ChecksStorage::add(const Check &c)
177177
all_checks[h] = c.Value.value();
178178
}
179179

180-
static String make_function_var(const String &d, const String &prefix = "HAVE_")
180+
static String make_function_var(const String &d, const String &prefix = "HAVE_", const String &suffix = {})
181181
{
182-
return prefix + boost::algorithm::to_upper_copy(d);
182+
return prefix + boost::algorithm::to_upper_copy(d) + suffix;
183183
}
184184

185185
static String make_include_var(const String &i)
@@ -193,9 +193,9 @@ static String make_include_var(const String &i)
193193
return v_def;
194194
}
195195

196-
static String make_type_var(const String &t, const String &prefix = "HAVE_")
196+
static String make_type_var(const String &t, const String &prefix = "HAVE_", const String &suffix = {})
197197
{
198-
String v_def = make_function_var(t, prefix);
198+
String v_def = make_function_var(t, prefix, suffix);
199199
for (auto &c : v_def)
200200
{
201201
if (c == '*')
@@ -272,7 +272,7 @@ int main() { return IsBigEndian(); }
272272
// this path is used with wait_for_cc_checks
273273
auto i = cs.all_checks.find(h);
274274
if (i != cs.all_checks.end())
275-
c->Value = i->second;
275+
ic->second->Value = i->second;
276276

277277
return std::pair{ false, ic->second };
278278
}
@@ -485,6 +485,13 @@ int main() { return IsBigEndian(); }
485485
std::cout << "Run '" << normalize_path(out) << "' and press and key to continue...\n";
486486
getchar();
487487
cs.load_manual(fn);
488+
for (auto &[h, c] : cs.manual_checks)
489+
{
490+
if (cs.all_checks.find(h) == cs.all_checks.end())
491+
continue;
492+
c->requires_manual_setup = false;
493+
}
494+
cs.manual_checks.clear();
488495
return performChecks(ts);
489496
}
490497

@@ -862,6 +869,9 @@ TypeSize::TypeSize(const String &t, const String &def)
862869

863870
Definitions.insert(make_type_var(data));
864871
Definitions.insert(make_type_var(data, "SIZEOF_"));
872+
// some cmake new thing
873+
// https://cmake.org/cmake/help/latest/module/CheckTypeSize.html
874+
Definitions.insert(make_type_var(data, "SIZEOF_", "_CODE"));
865875
Definitions.insert(make_type_var(data, "SIZE_OF_"));
866876
// some libs want these
867877
Definitions.insert(make_type_var(data, "HAVE_SIZEOF_"));

src/sw/driver/driver.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,21 @@ void Driver::load_spec_file(SwBuild &b, const path &fn, const std::set<TargetSet
172172
void Driver::load_dll(SwBuild &b, const path &dll, const std::set<TargetSettings> &settings)
173173
{
174174
auto ep = std::make_shared<NativeModuleTargetEntryPoint>(b.getContext().getModuleStorage().get(dll));
175+
176+
// find difference to set entry points
177+
auto old = b.getTargets();
178+
179+
// load all
175180
for (auto &s : settings)
176-
ep->loadPackages(b, s, {}); // load all
181+
ep->loadPackages(b, s, {});
182+
183+
// don't forget to set EPs for loaded targets
184+
for (const auto &[pkg, tgts] : b.getTargets())
185+
{
186+
if (old.find(pkg) != old.end())
187+
continue;
188+
b.getContext().getTargetData(pkg).setEntryPoint(ep);
189+
}
177190
}
178191

179192
const StringSet &Driver::getAvailableFrontendNames()

src/sw/driver/target/native.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <primitives/emitter.h>
2323
#include <primitives/debug.h>
2424
#include <primitives/sw/cl.h>
25+
#include <pystring.h>
2526

2627
#include <charconv>
2728

@@ -1760,20 +1761,23 @@ NativeCompiledTarget::ActiveDeps &NativeCompiledTarget::getActiveDependencies()
17601761
if (!active_deps)
17611762
{
17621763
ActiveDeps deps;
1763-
TargetOptionsGroup::iterate([this, &deps](auto &v, auto i)
1764+
if (!DryRun)
17641765
{
1765-
for (auto &d : v.getRawDependencies())
1766+
TargetOptionsGroup::iterate([this, &deps](auto &v, auto i)
17661767
{
1767-
if (d->isDisabled())
1768-
continue;
1768+
for (auto &d : v.getRawDependencies())
1769+
{
1770+
if (d->isDisabled())
1771+
continue;
17691772

1770-
TargetDependency td;
1771-
td.dep = d;
1772-
td.inhtype = i;
1773-
td.dep->settings = ts;
1774-
deps.push_back(td);
1775-
}
1776-
});
1773+
TargetDependency td;
1774+
td.dep = d;
1775+
td.inhtype = i;
1776+
td.dep->settings = ts;
1777+
deps.push_back(td);
1778+
}
1779+
});
1780+
}
17771781
active_deps = deps;
17781782
}
17791783
return *active_deps;
@@ -1821,7 +1825,11 @@ void NativeCompiledTarget::merge1()
18211825
bool NativeCompiledTarget::prepare()
18221826
{
18231827
if (DryRun)
1828+
{
1829+
getActiveDependencies();
18241830
return false;
1831+
}
1832+
18251833
if (getSolution().skipTarget(Scope))
18261834
return false;
18271835

@@ -3034,7 +3042,10 @@ void NativeCompiledTarget::setChecks(const String &name, bool check_definitions)
30343042
{
30353043
add(Definition{ d.value() });
30363044
}
3037-
Variables[k] = v;
3045+
if (pystring::endswith(k, "_CODE"))
3046+
Variables[k] = "#define " + k.substr(0, k.size() - 5) + " " + std::to_string(v);
3047+
else
3048+
Variables[k] = v;
30383049
}
30393050
}
30403051

sw.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void build(Solution &s)
8484
manager.ExportIfStatic = true;
8585
manager.CPPVersion = CPPLanguageStandard::CPP17;
8686
manager.Public += "BOOST_DLL_USE_STD_FS"_def;
87+
8788
manager.Public += support, protos,
8889
"pub.egorpugin.primitives.date_time-master"_dep,
8990
"pub.egorpugin.primitives.db.sqlite3-master"_dep,
@@ -92,13 +93,17 @@ void build(Solution &s)
9293
"pub.egorpugin.primitives.source-master"_dep,
9394
"pub.egorpugin.primitives.sw.settings-master"_dep,
9495
"pub.egorpugin.primitives.version-master"_dep,
95-
"pub.egorpugin.primitives.win32helpers-master"_dep,
9696
"pub.egorpugin.primitives.yaml-master"_dep,
9797
"org.sw.demo.nlohmann.json-3"_dep,
9898
"org.sw.demo.boost.variant"_dep,
9999
"org.sw.demo.boost.dll"_dep,
100100
"org.sw.demo.rbock.sqlpp11_connector_sqlite3-develop"_dep
101101
;
102+
103+
manager.Public -= "pub.egorpugin.primitives.win32helpers-master"_dep;
104+
if (manager.getSettings().TargetOS.Type == OSType::Windows)
105+
manager.Public += "pub.egorpugin.primitives.win32helpers-master"_dep;
106+
102107
manager += "src/sw/manager/.*"_rr;
103108
manager.Public.Definitions["VERSION_MAJOR"] += std::to_string(manager.getPackage().version.getMajor());
104109
manager.Public.Definitions["VERSION_MINOR"] += std::to_string(manager.getPackage().version.getMinor());

0 commit comments

Comments
 (0)