Package existing 3rd Parties in seperate C++20 modules

I’m trying to use modules to speed up our windows builds a little bit.
From my first impressions C++20 Modules are definitely faster than PCH (atleast on windows).

Currently I’m only focussed on windows with latest MSVC 17 and latest CMake. I’m also using import std which is only available on C++23.
I know that these features are cutting edge, but this is a first try and not used in any productive system. (I need to preserve backwards compatibility though with “classic” includes)
Since MSVC17 has a good working module support and CMake has added the import std in their latest version I’d like to give it a try.

Now the problems I have encountered are name clashes.
So basically since I use import std; I would like to avoid all stl includes.
Modifying our code is not a big deal, the real challenge is packaging existing 3rd Parties (like fmt and nlohmann_json) into modules since their headers include multiple std headers (which are causing name clashes with import std;)

I have watched Daniela Engert talks about C++20 modules from some CppCons and checked out her examples.
https://github.com/DanielaE/asio/tree/d212efd69aedf221475dc2434c45a6baeee10d16/asio/module
She basically included the 3rd party header within the export. However this did not work for me.

// Global module fragment where #includes can happen
module;

//inlcuded headers will not be exported to the client


// first thing after the Global module fragment must be a module command
export module nlohmann_json;

extern "C++"
{
  export
  {
#include <nlohmann/json.hpp>
  }
}


module: private;
//possbile to include headers here, but they will not be exported to the client

This is my test programm

#include <gtest/gtest.h>
TEST(CxxModuleTest, nlohman_json)
{
  nlohmann::json j = {
  {"pi", 3.141},
  {"happy", true},
  {"name", "Niels"},
  {"nothing", nullptr},
  {"answer", {
    {"everything", 42}
  }},
  {"list", {1, 0, 2}},
  {"object", {
    {"currency", "USD"},
    {"value", 42.99}
  }}
  };

  EXPECT_EQ(j["pi"], 3.141);
  EXPECT_EQ(j["happy"], true);
  EXPECT_EQ(j["name"], "Niels");
  EXPECT_EQ(j["nothing"], nullptr);
  EXPECT_EQ(j["answer"]["everything"], 42);
  EXPECT_EQ(j["list"][0], 1);
  EXPECT_EQ(j["list"][1], 0);
  EXPECT_EQ(j["list"][2], 2);
  EXPECT_EQ(j["object"]["currency"], "USD");
  EXPECT_EQ(j["object"]["value"], 42.99);
}

However this does not compile. I’m getting

'#include <filename>' in the purview of module 'module-name-1' appears erroneous. Consider moving that directive before the module declaration, or replace the textual inclusion with 'import <filename>;'.

I ended up with this

// Global module fragment where #includes can happen
module;

//inlcuded headers will not be exported to the client
#include <nlohmann/json.hpp>

// first thing after the Global module fragment must be a module command
export module nlohmann_json;

export
{
  namespace nlohmann::json_abi_v3_11_2::detail
  {
    using ::nlohmann::json_abi_v3_11_2::detail::json_sax_dom_callback_parser;
    using ::nlohmann::json_abi_v3_11_2::detail::json_sax_dom_parser;
  }

  namespace nlohmann
  {

    using ::nlohmann::basic_json;
    using ::nlohmann::json;
    using ::nlohmann::json_sax;
    using ::nlohmann::detail::json_sax_dom_parser;
    using ::nlohmann::detail::json_sax_dom_callback_parser;
  }
}


module: private;
//possbile to include headers here, but they will not be exported to the client

However this is a try and error. I need to add all types until the program compiles.

=>My question:
Is there a better (more generic) way?

thx guys for your help 🙂

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật