Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

This PR implements improvements to the FFI specialization macros as requested in issue #11. The improvements focus on reducing verbosity and providing better developer experience while maintaining backward compatibility.

✨ Key Changes

  1. Made convention parameter optional in ffi::specialize_for - defaults to C# convention
  2. Added new ffi::specialize macro for embedded annotations with sensible defaults
  3. Maintained full backward compatibility - existing code continues to work unchanged
  4. Fixed compilation issues - removed deprecated box_syntax feature

🔄 Before and After

Before (Verbose):

#[ffi::specialize_for(
    types = "u8",
    types = "u16",
    types = "u32", 
    types = "u64",
    convention = "csharp",
    name = "doublets_constants_*"
)]

After (Option 1 - Simplified):

#[ffi::specialize_for(
    types = "u8",
    types = "u16",
    types = "u32",
    types = "u64", 
    name = "doublets_constants_*"
)]

After (Option 2 - Embedded Annotations):

#[ffi::specialize("doublets_constants_*")]

🧪 Test Plan

  • Compiles successfully with modern Rust
  • Backward compatibility verified - existing usage unchanged
  • New macros generate correct FFI functions
  • Examples provided demonstrating both approaches
  • No breaking changes to existing codebase

📁 Files Changed

  • doublets-ffi/ffi-attributes/src/lib.rs - Core implementation
  • examples/ffi_test.rs - Working examples
  • examples/usage_examples.md - Documentation

🎯 Implementation Details

Implemented both approaches suggested in the issue:

  1. Option 1: Improved ffi::specialize_for with optional convention (implemented)
  2. Option 2: New ffi::specialize macro for embedded annotations (implemented)

Both generate identical FFI functions with C# naming conventions for u8, u16, u32, u64 types.

Fixes #11

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #11
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 13:25
- Make convention parameter optional (defaults to csharp)
- Add new ffi::specialize macro for embedded annotations
- Maintain backward compatibility with existing usage
- Remove deprecated box_syntax feature
- Fix compilation errors for modern Rust

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Improve Improve ffi::specialize_for macro and add new ffi::specialize macro Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 10:35
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.

Improve ffi::specialize_for

2 participants