Skip to content

Conversation

@nilslice
Copy link
Member

@nilslice nilslice commented Feb 2, 2026

Summary

Add support for Rust 1.82+ unsafe extern blocks and safe fn declarations in the #[host_fn] macro. Functions marked with safe fn generate safe wrapper functions that can be called without unsafe blocks. The implementation parses safe fn from verbatim tokens and generates appropriate wrappers based on safety annotations.

Changes

  • Updated #[host_fn] to accept both extern "ExtismHost" and unsafe extern "ExtismHost" blocks
  • Added parsing for safe fn declarations in unsafe extern blocks
  • Safe functions generate safe wrapper functions; regular functions generate unsafe wrappers
  • Added host_function_safe.rs example demonstrating the new syntax
  • Updated CI to test both old and new syntax variants

Test Plan

  • Existing host_function.wasm test passes (backward compatibility)
  • New host_function_safe.wasm test passes (new syntax)
  • Both examples produce identical output ({"count":40})
  • Code compiles with no errors on Rust 1.92.0

🤖 Generated with Claude Code

Add support for Rust 1.82+ unsafe extern blocks with safe fn declarations in the #[host_fn] macro. Functions marked with safe fn generate safe wrapper functions that can be called without unsafe. Includes a new example and CI tests.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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