From 13a848da52b55fd060b20e7d31eb21f97ba07cc4 Mon Sep 17 00:00:00 2001 From: wellwei Date: Thu, 6 Aug 2026 21:55:37 +0800 Subject: [PATCH] fix(asio): keep std::println usable with import asio --- pkgs/c/chriskohlhoff.asio.lua | 8 ++++++-- tests/examples/asio-module/mcpp.toml | 3 +++ tests/examples/asio-module/tests/surface.cpp | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkgs/c/chriskohlhoff.asio.lua b/pkgs/c/chriskohlhoff.asio.lua index ebbf47a1..da8d0e29 100644 --- a/pkgs/c/chriskohlhoff.asio.lua +++ b/pkgs/c/chriskohlhoff.asio.lua @@ -8,8 +8,8 @@ -- `#include ` 和 `import asio;`,避免 inline 定义与模块 BMI -- 的 separate-compilation 定义产生 ODR 差异。 -- * 默认 feature 显式传播 ASIO_STANDALONE、ASIO_SEPARATE_COMPILATION、 --- ASIO_DISABLE_BOOST_CONTEXT_FIBER 和 ASIO_HAS_THREADS。Asio 头文件内部 --- 自动检测的其他 ASIO_HAS_* 宏不会由 `import asio;` 导出。 +-- ASIO_DISABLE_BOOST_CONTEXT_FIBER、ASIO_HAS_THREADS 和 ASIO_NO_IOSTREAM。 +-- Asio 头文件内部自动检测的其他 ASIO_HAS_* 宏不会由 `import asio;` 导出。 -- -- 与 header-only Asio 的区别/限制 -- * 上游 1.38.x 没有模块接口单元。本描述生成 `asio.cppm`,并只编译一次 @@ -35,6 +35,9 @@ -- streambuf:对应 `asio/deadline_timer.hpp`、`asio/generic/*.hpp`、 -- `asio/execution/*.hpp`、`asio/traits/*.hpp`、`asio/yield.hpp`、 -- `asio/coroutine.hpp`、`asio/streambuf.hpp`。 +-- * iostream/streambuf 适配:模块禁用 ASIO 的 iostream 表面,避免 libc++ +-- `` 同时进入 `std` 与 `asio` 两个 BMI 后破坏 `std::println`; +-- 因此基于 streambuf 的 read_at/write_at 重载也不可用。 package = { spec = "1", namespace = "chriskohlhoff", @@ -289,6 +292,7 @@ using ::asio::ssl::error::make_error_code; "ASIO_SEPARATE_COMPILATION", "ASIO_DISABLE_BOOST_CONTEXT_FIBER", "ASIO_HAS_THREADS", + "ASIO_NO_IOSTREAM", }, }, ["ssl"] = { diff --git a/tests/examples/asio-module/mcpp.toml b/tests/examples/asio-module/mcpp.toml index d1b20abf..2ce29ce5 100644 --- a/tests/examples/asio-module/mcpp.toml +++ b/tests/examples/asio-module/mcpp.toml @@ -13,3 +13,6 @@ version = "0.1.0" [dependencies.chriskohlhoff] asio = "1.38.1" + +[dependencies.fmtlib] +fmt = "12.2.0" diff --git a/tests/examples/asio-module/tests/surface.cpp b/tests/examples/asio-module/tests/surface.cpp index da5ae643..029d8dc4 100644 --- a/tests/examples/asio-module/tests/surface.cpp +++ b/tests/examples/asio-module/tests/surface.cpp @@ -1,9 +1,14 @@ // Surface/smoke coverage: exported types, completion tokens, and vocabulary // types are usable across the module boundary. import std; +import fmt; import asio; int main() { + // 回归:导入 Asio 后,libc++ 的 println 仍应保持可用。 + std::println("asio module println"); + std::println("asio module println {}", 42); + // --- buffer / address (existing) --- std::array src{'m', 'c', 'p', 'p'}; asio::const_buffer cb = asio::buffer(src);