summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2026-02-07 22:27:05 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2026-02-08 17:25:52 +0100
commit627843d2517a5cc8885939d6396fb052cd873aa7 (patch)
treeb667b48327f127dd29ca160588ee5630d2ca4518
parent668158a83bc9e5af7bf65fe88d22d1958e33443f (diff)
Use REG function for configuration, like with build_configurations, to get rid of the hacky weak symbol method.no_more_weak
-rw-r--r--src/configure.cc28
-rw-r--r--src/ctor.h3
-rw-r--r--test/ctor.cc7
-rw-r--r--test/source_type_test.cc3
-rw-r--r--test/tasks_test.cc4
-rw-r--r--test/tools_test.cc23
6 files changed, 37 insertions, 31 deletions
diff --git a/src/configure.cc b/src/configure.cc
index 1b8caa6..5ba87c3 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -10,6 +10,7 @@
#include <optional>
#include <span>
#include <cstring>
+#include <functional>
#include "execute.h"
#include "ctor.h"
@@ -26,8 +27,30 @@ const std::filesystem::path configHeaderFile("config.h");
std::map<std::string, std::string> external_includedir;
std::map<std::string, std::string> external_libdir;
-const ctor::configuration& __attribute__((weak)) ctor::get_configuration()
+std::function<const ctor::configuration&()>& getConfigurationCallback()
{
+ static std::function<const ctor::configuration&()> configuration_callback;
+ return configuration_callback;
+}
+
+namespace ctor {
+int reg(std::function<const ctor::configuration&()> cb,
+ [[maybe_unused]]const std::source_location location)
+{
+ auto& configuration_callback = getConfigurationCallback();
+ configuration_callback = cb;
+ return {};
+}
+} // ctor::
+
+const ctor::configuration& ctor::get_configuration()
+{
+ auto& configuration_callback = getConfigurationCallback();
+ if(configuration_callback)
+ {
+ return configuration_callback();
+ }
+
static ctor::configuration cfg;
static bool initialised{false};
if(!initialised)
@@ -752,7 +775,7 @@ int regenerateCache(ctor::settings& settings,
std::cout << "Generating configuration: " << configurationFile.string() << "\n"; {
std::stringstream istr;
istr << "#include <ctor.h>\n\n";
- istr << "const ctor::configuration& ctor::get_configuration()\n";
+ istr << "const ctor::configuration& stored_configuration()\n";
istr << "{\n";
istr << " static ctor::configuration cfg =\n";
istr << " {\n";
@@ -902,6 +925,7 @@ int regenerateCache(ctor::settings& settings,
istr << " };\n";
istr << " return cfg;\n";
istr << "}\n";
+ istr << "\nREG(stored_configuration);\n";
auto new_configuration = istr.str();
auto current_configuration = readFile(configurationFile.string());
diff --git a/src/ctor.h b/src/ctor.h
index 890c257..8a7c809 100644
--- a/src/ctor.h
+++ b/src/ctor.h
@@ -579,4 +579,7 @@ struct configuration
const ctor::configuration& get_configuration();
+int reg(std::function<const ctor::configuration&()> cb,
+ const std::source_location location = std::source_location::current());
+
} // ctor::
diff --git a/test/ctor.cc b/test/ctor.cc
index afec91c..d1c0188 100644
--- a/test/ctor.cc
+++ b/test/ctor.cc
@@ -31,6 +31,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)
ctor::sources{
"generated_sources_test.cc",
"testmain.cc",
+ "../configuration.cc",
},
ctor::depends({"libctor_nomain.a"}),
ctor::cxx_flags{
@@ -146,6 +147,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)
ctor::sources{
"cycle_test.cc",
"testmain.cc",
+ "../configuration.cc",
},
ctor::depends({"libctor_nomain.a"}),
ctor::cxx_flags{
@@ -163,6 +165,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)
ctor::sources{
"source_type_test.cc",
"testmain.cc",
+ "../configuration.cc",
},
ctor::depends({"libctor_nomain.a"}),
ctor::cxx_flags{
@@ -180,8 +183,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)
ctor::sources{
"tools_test.cc",
"testmain.cc",
- "../src/util.cc",
- "../src/tools.cc",
+ "../configuration.cc",
},
ctor::depends({"libctor_nomain.a"}),
ctor::cxx_flags{
@@ -212,7 +214,6 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)
"../src/tools.cc",
"../src/util.cc",
"../src/externals_manual.cc",
- "../configuration.cc",
},
ctor::cxx_flags{
"-std=c++20", "-O3", "-Wall",
diff --git a/test/source_type_test.cc b/test/source_type_test.cc
index 90e77cf..345c591 100644
--- a/test/source_type_test.cc
+++ b/test/source_type_test.cc
@@ -26,13 +26,14 @@ std::ostream& operator<<(std::ostream& stream, const ctor::language& lang)
return stream;
}
-const ctor::configuration& ctor::get_configuration()
+const ctor::configuration& test_configuration()
{
static ctor::configuration cfg{};
cfg.build_toolchain = ctor::toolchain::gcc;
cfg.build_arch = ctor::arch::unix;
return cfg;
}
+REG(test_configuration);
class TestableTaskCC
: public TaskCC
diff --git a/test/tasks_test.cc b/test/tasks_test.cc
index 32bed5a..c8e4cf8 100644
--- a/test/tasks_test.cc
+++ b/test/tasks_test.cc
@@ -38,14 +38,14 @@ namespace test_global {
ctor::toolchain toolchain{};
ctor::arch arch{};
}
-const ctor::configuration& ctor::get_configuration()
+const ctor::configuration& test_configuration()
{
static ctor::configuration cfg{};
cfg.build_toolchain = test_global::toolchain;
cfg.build_arch = test_global::arch;
return cfg;
}
-
+REG(test_configuration);
REG(ctorTestConfigs1);
REG(ctorTestConfigs2);
diff --git a/test/tools_test.cc b/test/tools_test.cc
index 5ae04c3..cfbcbce 100644
--- a/test/tools_test.cc
+++ b/test/tools_test.cc
@@ -114,29 +114,6 @@ bool operator!=(const ctor::asm_flag& a, const ctor::asm_flag& b)
#include <uunit.h>
-const ctor::configuration& ctor::get_configuration()
-{
- static ctor::configuration cfg;
- return cfg;
-}
-
-std::string ctor::configuration::get(const std::string& key, [[maybe_unused]]const std::string& default_value) const
-{
- if(key == ctor::cfg::host_cxx)
- {
- return {};
- }
-
- if(key == ctor::cfg::build_cxx)
- {
- return {};
- }
-
- assert(false); // bad key
-
- return {};
-}
-
class ToolsTest
: public uUnit
{