Skip to content

feat(chriskohlhoff.asio): import asio; — 将 Asio 1.38.1 适配为 C++23 模块 (separate compilation)#80

Merged
Sunrisepeak merged 4 commits into
mcpplibs:mainfrom
wellwei:feat/compat.asio-module
Jul 18, 2026
Merged

feat(chriskohlhoff.asio): import asio; — 将 Asio 1.38.1 适配为 C++23 模块 (separate compilation)#80
Sunrisepeak merged 4 commits into
mcpplibs:mainfrom
wellwei:feat/compat.asio-module

Conversation

@wellwei

@wellwei wellwei commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

摘要

新增 chriskohlhoff.asio@1.38.1 — 将 Asio 1.38.1 暴露为 C++23 模块 import asio;
采用 ASIO_SEPARATE_COMPILATION 模式(编译 */src/asio.cpp),是现有 header-only 版 compat.asio 的模块伴侣包。

新增文件

文件 说明
pkgs/c/chriskohlhoff.asio.lua Form B inline 描述符,含 37 个 asio 头文件 include、~55 条 using 导出、191 行中文使用文档(含限制、迁移指南)
tests/examples/asio-module/mcpp.toml 测试项目配置
tests/examples/asio-module/tests/core.cpp 核心:io_context/strand/thread_pool/cancellation_signal
tests/examples/asio-module/tests/coroutine.cpp 协程:awaitable/co_spawn/use_awaitable/this_coro
tests/examples/asio-module/tests/experimental.cpp 实验性:channel/concurrent_channel/use_promise
tests/examples/asio-module/tests/network.cpp TCP acceptor/socket + UDP 全链路
tests/examples/asio-module/tests/surface.cpp export 编译时验证 ≈ 25 条 static_assert

修改文件

文件 改动
mcpp.toml workspace.members 添加 "tests/examples/asio-module"

导出的 API 范围

  • 核心 IO: io_context, execution_context, post/dispatch/defer, make_work_guard, steady_timer/system_timer, thread_pool, make_strand, any_io_executor, system_executor/system_context
  • 取消: cancellation_signal, cancellation_type, bind_cancellation_slot, cancellation_state
  • 网络: tcp/udp(address/socket/acceptor/resolver/endpoint), socket_base, connect, async_read/async_write, read/write/read_until
  • 缓冲区: mutable_buffer, const_buffer, buffer
  • 协程: awaitable, co_spawn, use_awaitable, this_coro::*
  • 实验性: experimental::channel, concurrent_channel, use_promise
  • 完成令牌: detached/detached_t, use_future, deferred/deferred_t, redirect_error, bind_executor, bind_allocator, append/prepend/consign/as_tuple
  • 关联特质: associated_executor, associated_allocator, associated_cancellation_slot
  • 信号: signal_set
  • 错误: error_code, error::make_error_code, error::operation_aborted

不可用的组件(需额外依赖/平台相关)

SSL/TLS、Unix domain sockets、POSIX descriptors、Windows handles、serial_port、pipes、file I/O、spawn()(需 Boost.Context,已禁用)、deadline_timer(已废弃)。详见描述符注释。

验证

mcpp test -p asio-module => 5/5 passed
mcpp test -p asio        => 6/6 passed (header-only 回归)
mcpp test -p spdlog,nlohmann.json,marzer.tomlplusplus => 全部通过

mcpp add chriskohlhoff.asio@1.38.1  ✅ 

wellwei added 2 commits July 19, 2026 05:33
…ilation)

Add compat.asio-m@1.38.1 — a FORM B inline descriptor exposing standalone
asio as 'import asio;' with ASIO_SEPARATE_COMPILATION mode.

Changes:
- pkgs/c/compat.asio-m.lua: Form B descriptor with generated module wrapper
  (37 asio headers included, ~55 using declarations exported: core/io, TCP/UDP
  networking, cancellation, experimental channel/use_promise, executor
  completeness, and common token adapters)
- tests/examples/asio-module/: 5 tests (core, coroutine, experimental,
  network, surface) covering the full exported API surface
- mcpp.toml: add tests/examples/asio-module to workspace members

Tested: mcpp test -p asio-module => 5/5 passed
Regression: mcpp test -p asio => 6/6 passed
           mcpp test -p spdlog, nlohmann.json, marzer.tomlplusplus => all OK

Closes mcpplibs#73 (companion to compat.asio PR)
…dules ADL

On GCC (Linux CI), the make_error_code(channel_errors) function
declared in asio/experimental/channel_error.hpp is in the global
module fragment and NOT reachable from the importing TU via ADL.
This causes:
  error: use of deleted function 'void std::__adl_only::make_error_code()'
when the channel template destructor instantiates
channel_traits::invoke_receive_cancelled() which constructs
std::error_code from error::channel_cancelled.

Fix: add an explicit exported using declaration:
  export namespace asio::experimental::error {
    using ::asio::experimental::error::make_error_code;
  }

Clang (macOS) apparently tolerates the missing export, but GCC
requires it. Also include channel_error.hpp explicitly in the
global fragment.
@Sunrisepeak

Copy link
Copy Markdown
Member

compat.asio-m

模块化的包, 不用加compat 。namespace可以用库作者或组织的名字或缩写 不用 asio-m 具体参考

wellwei added 2 commits July 19, 2026 06:13
…view

Upstream requested package name change from compat.asio-m to
chriskohlhoff.asio (namespace chriskohlhoff). Consumers can now use:

  mcpp add chriskohlhoff.asio@1.38.1   (full qualified)
  mcpp add asio@1.38.1                  (shorthand)

This is purely a package-name and namespace rename; the C++ module
surface (import asio;) is unchanged.

Also update the test project's mcpp.toml to match the new index.
…sio@1.38.1

The shorthand 'asio' matches multiple packages in the default registry
(compat.asio, mcpplibs.asio), causing resolution conflict. Consumers
must use the fully qualified name 'chriskohlhoff.asio' instead.

  mcpp add chriskohlhoff.asio@1.38.1  (correct, unambiguous)
  mcpp add asio@1.38.1                 (ambiguous, may fail or resolve wrongly)
@wellwei wellwei changed the title feat(compat.asio-m): import asio; — 将 Asio 1.38.1 适配为 C++23 模块 (separate compilation) feat(chriskohlhoff.asio): import asio; — 将 Asio 1.38.1 适配为 C++23 模块 (separate compilation) Jul 18, 2026
@Sunrisepeak
Sunrisepeak merged commit bf79ef5 into mcpplibs:main Jul 18, 2026
5 checks passed
@wellwei
wellwei deleted the feat/compat.asio-module branch July 20, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants