Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ namespace cppwinrt
return { w, write_nothing };
}

static void write_extern_cxx_start(writer& w)
{
w.write(R"(
extern "C++"
{
)");
}

static void write_extern_cxx_end(writer& w)
{
w.write(R"(
} // extern "C++"
)");
}

static void write_parent_depends(writer& w, cache const& c, std::string_view const& type_namespace)
{
auto pos = type_namespace.rfind('.');
Expand Down Expand Up @@ -203,9 +218,20 @@ namespace cppwinrt
return { w, write_close_namespace };
}

[[nodiscard]] static finish_with wrap_impl_namespace_without_export(writer& w)
{
auto format = R"(namespace winrt::impl
{
)";

w.write(format);

return { w, write_close_namespace };
}

[[nodiscard]] static finish_with wrap_std_namespace(writer& w)
{
w.write(R"(WINRT_EXPORT namespace std
w.write(R"(namespace std
{
)");

Expand Down
87 changes: 82 additions & 5 deletions cppwinrt/file_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ namespace cppwinrt
{
auto wrap_file_guard = wrap_open_file_guard(w, "BASE");

if (settings.modules)
{
w.write("#ifndef WINRT_CONSUME_MODULE\n");
}

{
// In module builds, generated projection headers must be "module-aware":
// When `WINRT_MODULE` is defined (inside a module interface unit), suppress textual includes so the
Expand All @@ -53,6 +58,11 @@ namespace cppwinrt
w.write(strings::base_includes);
}

if (settings.modules)
{
write_extern_cxx_start(w);
}

w.write(strings::base_macros);
w.write(strings::base_types);
w.write(strings::base_extern);
Expand Down Expand Up @@ -85,8 +95,19 @@ namespace cppwinrt
w.write(strings::base_coroutine_threadpool);
w.write(strings::base_natvis);
w.write(strings::base_version);

if (settings.modules)
{
write_extern_cxx_end(w);
}

if (settings.modules)
{
w.write("#endif\n");
}
}
w.flush_to_file(settings.output_folder + "winrt/base.h");

}

static void write_module_h()
Expand Down Expand Up @@ -142,7 +163,7 @@ namespace cppwinrt
w.write_each<write_forward>(members.contracts);
}
{
auto wrap_impl = wrap_impl_namespace(w);
auto wrap_impl = wrap_impl_namespace_without_export(w);
w.write_each<write_category>(members.interfaces, "interface_category");
w.write_each<write_category>(members.classes, "class_category");
w.write_each<write_category>(members.enums, "enum_category");
Expand All @@ -165,10 +186,19 @@ namespace cppwinrt
w.write_each<write_default_interface>(members.classes);
w.write_each<write_interface_abi>(members.interfaces);
w.write_each<write_delegate_abi>(members.delegates);
w.write_each<write_consume>(members.interfaces);
w.write_each<write_struct_abi>(members.structs);
}

{
auto wrap_impl = wrap_impl_namespace(w);
w.write_each<write_consume>(members.interfaces);
}

if (settings.modules)
{
write_extern_cxx_end(w);
}

if (settings.modules)
{
get_namespace_module_imports(c, ns, w, module_imports);
Expand All @@ -192,6 +222,11 @@ namespace cppwinrt
}
}

if (settings.modules)
{
write_extern_cxx_start(w);
}

w.save_header('0');
}

Expand All @@ -217,6 +252,11 @@ namespace cppwinrt
module_imports.clear();
}

if (settings.modules)
{
write_extern_cxx_end(w);
}

write_close_file_guard(w);
w.swap();
write_preamble(w);
Expand All @@ -233,6 +273,11 @@ namespace cppwinrt
w.write_depends(w.type_namespace, '0');
}

if (settings.modules)
{
write_extern_cxx_start(w);
}

w.save_header('1');
}

Expand Down Expand Up @@ -261,6 +306,11 @@ namespace cppwinrt
module_imports.clear();
}

if (settings.modules)
{
write_extern_cxx_end(w);
}

write_close_file_guard(w);
w.swap();
write_preamble(w);
Expand All @@ -279,6 +329,11 @@ namespace cppwinrt
w.write_depends(w.type_namespace, '1');
}

if (settings.modules)
{
write_extern_cxx_start(w);
}

w.save_header('2');
}

Expand Down Expand Up @@ -353,29 +408,36 @@ export import winrt.numerics;
write_module_global_fragment(w);

w.write(R"(
// Include in advance so that all of numerics's dependencies can be in the global module fragment
#if __has_include(<directxmath.h>) && __has_include(<windowsnumerics.impl.h>)
#include <stdexcept>
#include <limits>
#include <directxmath.h>
#endif

export module winrt.numerics;

// Module dependencies:
// - (none)

#if __has_include(<windowsnumerics.impl.h>)
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 5244)
#endif
#include <directxmath.h>

#define _WINDOWS_NUMERICS_NAMESPACE_ winrt::Windows::Foundation::Numerics
#define _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ export extern "C++" namespace winrt::Windows::Foundation::Numerics
#define _WINDOWS_NUMERICS_END_NAMESPACE_
#if __has_include(<directxmath.h>) && __has_include(<windowsnumerics.impl.h>)
#include <windowsnumerics.impl.h>
#endif
#undef _WINDOWS_NUMERICS_NAMESPACE_
#undef _WINDOWS_NUMERICS_BEGIN_NAMESPACE_
#undef _WINDOWS_NUMERICS_END_NAMESPACE_

#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif
)");

w.flush_to_file(settings.output_folder + "winrt/winrt.numerics.ixx");
Expand Down Expand Up @@ -580,6 +642,12 @@ export import winrt.base;
writer w;
w.type_namespace = ns;


if (settings.modules)
{
write_extern_cxx_start(w);
}

{
auto wrap_impl = wrap_impl_namespace(w);
w.write_each<write_consume_definitions>(members.interfaces);
Expand Down Expand Up @@ -611,6 +679,13 @@ export import winrt.base;
}
}


if (settings.modules)
{
write_extern_cxx_end(w);
}


write_namespace_special(w, ns);

if (settings.modules)
Expand Down Expand Up @@ -641,6 +716,7 @@ export import winrt.base;
auto wrap_includes_guard = wrap_module_aware_includes_guard(w, settings.modules);

write_version_assert(w);

write_parent_depends(w, c, ns);

for (auto&& depends : w.depends)
Expand All @@ -649,6 +725,7 @@ export import winrt.base;
}

w.write_depends(w.type_namespace, '2');

}

w.save_header();
Expand Down
2 changes: 1 addition & 1 deletion strings/base_abi.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

WINRT_EXPORT namespace winrt::impl
namespace winrt::impl
{
template <> struct abi<Windows::Foundation::IUnknown>
{
Expand Down
31 changes: 26 additions & 5 deletions strings/base_activation.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

WINRT_EXPORT namespace winrt::impl
namespace winrt::impl
{
struct library_traits
{
Expand Down Expand Up @@ -103,7 +103,7 @@ WINRT_EXPORT namespace winrt::impl
}
}

WINRT_EXPORT namespace winrt
namespace winrt
{
template <typename Interface = Windows::Foundation::IActivationFactory>
impl::com_ref<Interface> get_activation_factory(param::hstring const& name)
Expand All @@ -114,7 +114,7 @@ WINRT_EXPORT namespace winrt
}
}

WINRT_EXPORT namespace winrt::impl
namespace winrt::impl
{

#ifdef __clang__
Expand Down Expand Up @@ -422,7 +422,7 @@ WINRT_EXPORT namespace winrt::impl
};
}

WINRT_EXPORT namespace winrt
namespace winrt
{
enum class apartment_type : std::int32_t
{
Expand Down Expand Up @@ -516,7 +516,7 @@ WINRT_EXPORT namespace winrt
}
}

WINRT_EXPORT namespace winrt::impl
namespace winrt::impl
{
template <typename T>
T fast_activate(Windows::Foundation::IActivationFactory const& factory)
Expand All @@ -526,3 +526,24 @@ WINRT_EXPORT namespace winrt::impl
return{ result, take_ownership_from_abi };
}
}

#ifdef WINRT_MODULE
export namespace winrt
{
using winrt::apartment_type;
using winrt::get_activation_factory;
using winrt::try_get_activation_factory;
using winrt::try_create_instance;
using winrt::create_instance;
using winrt::init_apartment;
using winrt::uninit_apartment;
using winrt::clear_factory_cache;
}

export namespace winrt::impl
{
using winrt::impl::call_factory;
using winrt::impl::call_factory_cast;
using winrt::impl::fast_activate;
}
#endif
14 changes: 11 additions & 3 deletions strings/base_agile_ref.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

WINRT_EXPORT namespace winrt
namespace winrt
{
#if defined(WINRT_NO_MODULE_LOCK)

Expand Down Expand Up @@ -47,7 +47,7 @@ WINRT_EXPORT namespace winrt
#endif
}

WINRT_EXPORT namespace winrt::impl
namespace winrt::impl
{
template<bool UseModuleLock>
struct module_lock_updater;
Expand Down Expand Up @@ -82,7 +82,7 @@ WINRT_EXPORT namespace winrt::impl
}
}

WINRT_EXPORT namespace winrt
namespace winrt
{
template <typename T>
struct agile_ref
Expand Down Expand Up @@ -127,3 +127,11 @@ WINRT_EXPORT namespace winrt
return object;
}
}

#ifdef WINRT_MODULE
export namespace winrt
{
using winrt::agile_ref;
using winrt::make_agile;
}
#endif
Loading
Loading