polyglot-rust-c

Create source files compilable as both Rust and C/C++ programs.

Updated Feb 24, 2026
One-click install
npx skills add https://github.com/Zurybr/lefarma-skills --skill polyglot-rust-c-zurybr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: polyglot-rust-c
Source: https://github.com/Zurybr/lefarma-skills/tree/main/letta/benchmarks/trajectory-only/polyglot-rust-c
Command: npx skills add https://github.com/Zurybr/lefarma-skills --skill polyglot-rust-c-zurybr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the challenge of creating single source files that can be compiled and executed as valid programs in both Rust and C/C++ environments, leveraging language-specific syntax and preprocessor directives.

Core Features & Use Cases

  • Polyglot Code Generation: Develop source files that are simultaneously compilable by Rust and C/C++ compilers.
  • Cross-Language Compatibility: Ensure code functions correctly regardless of which compiler is used.
  • Use Case: Create a single main.rs file that can be compiled by rustc to produce a Rust executable and by g++ to produce a C++ executable, both performing a similar basic task.

Quick Start

Use the polyglot-rust-c skill to create a file that compiles as both Rust and C++.

Frequently Asked Questions about polyglot-rust-c

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a polyglot source file that compiles as both Rust and C++?

To write a polyglot source file, you exploit comment syntax differences and preprocessor directives to create a single file valid for both `rustc` and `g++` compilers. This requires iterative compilation testing to ensure cross-language compatibility.

What is the mechanism behind creating cross-language compatible code for Rust and C/C++?

Creating cross-language compatible code relies on leveraging language-specific syntax and preprocessor directives. By carefully structuring comments and directives, a single file can be interpreted differently by Rust and C/C++ compilers.

Can I use a single main.rs file to build executables with both rustc and g++?

Yes, you can use a single `main.rs` file to build executables with both `rustc` and `g++`. The Skill generates polyglot code that functions correctly regardless of which compiler processes the shared source file.

How to handle language-specific syntax for functions and I/O in Rust and C++ polyglot code?

Handling language-specific syntax for functions and I/O requires careful implementation using preprocessor directives to mask incompatible code. You must iteratively test compilation with both `rustc` and `g++` to ensure valid execution.

What are the limitations of using preprocessor directives for Rust and C/C++ cross-language compilation?

The main limitation is that handling language-specific syntax for functions and I/O requires complex, iterative implementation. You must continuously test compilation with both `rustc` and `g++` to prevent syntax conflicts.

Does the polyglot-rust-c skill support generating code for C and C++ environments?

Yes, the Skill facilitates the creation of polyglot source files compilable as both Rust and C/C++ programs. It ensures cross-language compatibility by addressing syntax differences through preprocessor directives and comments.