{"id":13484769,"url":"https://github.com/getditto/safer_ffi","last_synced_at":"2025-12-12T15:41:48.495Z","repository":{"id":36957200,"uuid":"267928806","full_name":"getditto/safer_ffi","owner":"getditto","description":"Write safer FFI code in Rust without polluting it with unsafe code","archived":false,"fork":false,"pushed_at":"2025-10-22T22:53:11.000Z","size":49255,"stargazers_count":1008,"open_issues_count":44,"forks_count":46,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-10-24T20:56:59.650Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://getditto.github.io/safer_ffi","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/getditto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-29T18:33:19.000Z","updated_at":"2025-10-07T09:05:17.000Z","dependencies_parsed_at":"2023-02-18T13:15:38.709Z","dependency_job_id":"f59cbbf5-e39c-442d-aa68-a6fa60b864a3","html_url":"https://github.com/getditto/safer_ffi","commit_stats":{"total_commits":300,"total_committers":18,"mean_commits":"16.666666666666668","dds":0.09999999999999998,"last_synced_commit":"257eb0bc7564a4dd91886226102a9e6977d15ceb"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"purl":"pkg:github/getditto/safer_ffi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getditto%2Fsafer_ffi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getditto%2Fsafer_ffi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getditto%2Fsafer_ffi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getditto%2Fsafer_ffi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getditto","download_url":"https://codeload.github.com/getditto/safer_ffi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getditto%2Fsafer_ffi/sbom","scorecard":{"id":424168,"data":{"date":"2025-08-11","repo":{"name":"github.com/getditto/safer_ffi","commit":"310a2c94c39e41335f5261724e733cd036a06629"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.2,"checks":[{"name":"Code-Review","score":2,"reason":"Found 2/7 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/CI.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":10,"reason":"22 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:83: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:94: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:96: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:107: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:114: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:116: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:137: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:144: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:146: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:176: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:184: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:187: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:250: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:257: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:262: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:265: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:283: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:55: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:63: update your workflow using https://app.stepsecurity.io/secureworkflow/getditto/safer_ffi/CI.yml/master?enable=pin","Info:   0 out of   7 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of  16 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":5,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'master'","Info: 'force pushes' disabled on branch 'master'","Warn: 'branch protection settings apply to administrators' is disabled on branch 'master'","Warn: 'stale review dismissal' is disabled on branch 'master'","Warn: required approving review count is 1 on branch 'master'","Warn: codeowners review is not required on branch 'master'","Warn: 'last push approval' is disabled on branch 'master'","Info: status check found to merge onto on branch 'master'","Info: PRs are required in order to make changes on branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":1,"reason":"9 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: RUSTSEC-2024-0421 / GHSA-h97m-ww89-6jmq","Warn: Project is vulnerable to: RUSTSEC-2024-0436","Warn: Project is vulnerable to: RUSTSEC-2025-0010","Warn: Project is vulnerable to: GHSA-4p46-pwfr-66x6","Warn: Project is vulnerable to: RUSTSEC-2025-0009","Warn: Project is vulnerable to: GHSA-c86p-w88r-qvqr","Warn: Project is vulnerable to: RUSTSEC-2024-0336","Warn: Project is vulnerable to: GHSA-rr8g-9fpq-6wmg","Warn: Project is vulnerable to: RUSTSEC-2025-0023"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T01:54:45.039Z","repository_id":36957200,"created_at":"2025-08-19T01:54:45.039Z","updated_at":"2025-08-19T01:54:45.039Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27685630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:33.036Z","updated_at":"2025-12-12T15:41:48.488Z","avatar_url":"https://github.com/getditto.png","language":"Rust","funding_links":[],"categories":["Rust","FFI Bindings","others"],"sub_categories":[],"readme":"\u003cspan style=\"text-align: center;\"\u003e\n\n![safer-ffi-banner](\nhttps://github.com/getditto/safer_ffi/blob/banner/guide/assets/safer_ffi.jpg?raw=true)\n\n[![CI](\nhttps://github.com/getditto/safer_ffi/workflows/CI/badge.svg?branch=master)](\nhttps://github.com/getditto/safer_ffi/actions)\n[![guide](https://img.shields.io/badge/guide-mdbook-blue)](\nhttps://getditto.github.io/safer_ffi)\n[![docs-rs](https://docs.rs/safer-ffi/badge.svg)](\nhttps://getditto.github.io/safer_ffi/rustdoc/safer_ffi)\n[![crates-io](https://img.shields.io/crates/v/safer-ffi.svg)](\nhttps://crates.io/crates/safer-ffi)\n[![repository](https://img.shields.io/badge/repository-GitHub-brightgreen.svg)](\nhttps://github.com/getditto/safer_ffi)\n\n\u003c/span\u003e\n\n# What is `safer_ffi`?\n\n`safer_ffi` is a framework that helps you write foreign function interfaces (FFI) without polluting your Rust code with `unsafe { ... }` code blocks while making functions far easier to read and maintain.\n\n\u003e \u003cstrong style=\"font-size: x-large;\"\u003e[📚 Read The User Guide 📚][user guide]\u003c/strong\u003e\n\n[user guide]: https://getditto.github.io/safer_ffi\n\n## Prerequisites\n\nMinimum Supported Rust Version: `1.66.1`\n\n# Quickstart\n\n\u003cdetails open\u003e\u003csummary\u003eClick to hide\u003c/summary\u003e\n\n#### Small self-contained demo\n\nYou may try working with the `examples/point` example embedded in the repo:\n\n```bash\ngit clone https://github.com/getditto/safer_ffi \u0026\u0026 cd safer_ffi\n(cd examples/point \u0026\u0026 make)\n```\n\nOtherwise, to start using `::safer_ffi`, follow the following steps:\n\n### Crate layout\n\n#### Step 1: `Cargo.toml`\n\nEdit your `Cargo.toml` like so:\n\n```toml\n[package]\nname = \"crate_name\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[lib]\ncrate-type = [\n    \"staticlib\",  # Ensure it gets compiled as a (static) C library\n  # \"cdylib\",     # If you want a shared/dynamic C library (advanced)\n    \"lib\",        # For `generate-headers` and other downstream rust dependents\n                  # such as integration `tests/`, doctests, and `examples/`\n]\n\n[[bin]]\nname = \"generate-headers\"\nrequired-features = [\"headers\"]  # Do not build unless generating headers.\n\n[dependencies]\n# Use `cargo add` or `cargo search` to find the latest values of x.y.z.\n# For instance:\n#   cargo add safer-ffi\nsafer-ffi.version = \"x.y.z\"\nsafer-ffi.features = [] # you may add some later on.\n\n[features]\n# If you want to generate the headers, use a feature-gate\n# to opt into doing so:\nheaders = [\"safer-ffi/headers\"]\n```\n\n  - Where `\"x.y.z\"` ought to be replaced by the last released version, which you\n    can find by running `cargo search safer-ffi`.\n\n  - See the [dedicated chapter on `Cargo.toml`][cargo-toml] for more info.\n\n#### Step 2: `src/lib.rs`\n\nThen, to export a Rust function to FFI, add the\n[`#[derive_ReprC]`][derive_ReprC] and [`#[ffi_export]`][ffi_export] attributes\nlike so:\n\n```rust ,no_run\nuse ::safer_ffi::prelude::*;\n\n/// A `struct` usable from both Rust and C\n#[derive_ReprC]\n#[repr(C)]\n#[derive(Debug, Clone, Copy)]\npub struct Point {\n    x: f64,\n    y: f64,\n}\n\n/* Export a Rust function to the C world. */\n/// Returns the middle point of `[a, b]`.\n#[ffi_export]\nfn mid_point(a: \u0026Point, b: \u0026Point) -\u003e Point {\n    Point {\n        x: (a.x + b.x) / 2.,\n        y: (a.y + b.y) / 2.,\n    }\n}\n\n/// Pretty-prints a point using Rust's formatting logic.\n#[ffi_export]\nfn print_point(point: \u0026Point) {\n    println!(\"{:?}\", point);\n}\n\n// The following function is only necessary for the header generation.\n#[cfg(feature = \"headers\")] // c.f. the `Cargo.toml` section\npub fn generate_headers() -\u003e ::std::io::Result\u003c()\u003e {\n    ::safer_ffi::headers::builder()\n        .to_file(\"rust_points.h\")?\n        .generate()\n}\n```\n\n  - See [the dedicated chapter on `src/lib.rs`][lib-rs] for more info.\n\n#### Step 3: `src/bin/generate-headers.rs`\n\n```rust ,ignore\nfn main() -\u003e ::std::io::Result\u003c()\u003e {\n    ::crate_name::generate_headers()\n}\n```\n\n### Compilation \u0026 header generation\n\n```bash\n# Compile the C library (in `target/{debug,release}/libcrate_name.ext`)\ncargo build # --release\n\n# Generate the C header\ncargo run --features headers --bin generate-headers\n```\n\n  - See [the dedicated chapter on header generation][header-generation] for\n    more info.\n\n\u003cdetails\u003e\u003csummary\u003eGenerated C header (\u003ccode\u003erust_points.h\u003c/code\u003e)\u003c/summary\u003e\n\n```C\n/*! \\file */\n/*******************************************\n *                                         *\n *  File auto-generated by `::safer_ffi`.  *\n *                                         *\n *  Do not manually edit this file.        *\n *                                         *\n *******************************************/\n\n#ifndef __RUST_CRATE_NAME__\n#define __RUST_CRATE_NAME__\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n\n#include \u003cstddef.h\u003e\n#include \u003cstdint.h\u003e\n\n/** \\brief\n *  A `struct` usable from both Rust and C\n */\ntypedef struct Point {\n    /** \u003cNo documentation available\u003e */\n    double x;\n\n    /** \u003cNo documentation available\u003e */\n    double y;\n} Point_t;\n\n/** \\brief\n *  Returns the middle point of `[a, b]`.\n */\nPoint_t\nmid_point (\n    Point_t const * a,\n    Point_t const * b);\n\n/** \\brief\n *  Pretty-prints a point using Rust's formatting logic.\n */\nvoid\nprint_point (\n    Point_t const * point);\n\n\n#ifdef __cplusplus\n} /* extern \\\"C\\\" */\n#endif\n\n#endif /* __RUST_CRATE_NAME__ */\n```\n\n___\n\n\u003c/details\u003e\n\n## Testing it from C\n\nHere is a basic example to showcase FFI calling into our exported Rust\nfunctions:\n\n### `main.c`\n\n```C\n#include \u003cstdlib.h\u003e\n\n#include \"rust_points.h\"\n\nint\nmain (int argc, char const * const argv[])\n{\n    Point_t a = { .x = 84, .y = 45 };\n    Point_t b = { .x = 0, .y = 39 };\n    Point_t m = mid_point(\u0026a, \u0026b);\n    print_point(\u0026m);\n    return EXIT_SUCCESS;\n}\n```\n\n### Compilation command\n\n```bash\ncc -o main{,.c} -L target/debug -l crate_name -l{pthread,dl,m}\n\n# Now feel free to run the compiled binary\n./main\n```\n\n  - \u003cdetails\u003e\u003csummary\u003eNote regarding the extra \u003ccode\u003e-l…\u003c/code\u003e flags.\u003c/summary\u003e\n\n    Those vary based on the version of the Rust standard library being used, and\n    the system being used to compile it. In order to reliably know which ones to\n    use, `rustc` itself ought to be queried for it.\n\n    Simple command:\n\n    ```bash\n    rustc --crate-type=staticlib --print=native-static-libs -\u003c/dev/null\n    ```\n\n    this yields, _to the stderr_, output along the lines of:\n\n    ```text\n    note: Link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms.\n\n    note: native-static-libs: -lSystem -lresolv -lc -lm -liconv\n    ```\n\n    Using something like `sed -nE 's/^note: native-static-libs: (.*)/\\1/p'` is\n    thus a convenient way to extract these flags:\n\n    ```bash\n    rustc --crate-type=staticlib --print=native-static-libs -\u003c/dev/null \\\n        2\u003e\u00261 | sed -nE 's/^note: native-static-libs: (.*)/\\1/p'\n    ```\n\n    Ideally, you would not query for this information _in a vacuum_ (_e.g._,\n    `/dev/null` file being used as input Rust code just above), and rather,\n    would apply it for your actual code being compiled:\n\n    ```bash\n    cargo rustc -q -- --print=native-static-libs \\\n        2\u003e\u00261 | sed -nE 's/^note: native-static-libs: (.*)/\\1/p'\n    ```\n\n    And if you really wanted to polish things further, you could use the\n    JSON-formatted compiler output (this, for instance, avoids having to\n    redirect `stderr`). But then you'd have to use a JSON parser, such as `jq`:\n\n    ```bash\n    RUST_STDLIB_DEPS=$(set -eo pipefail \u0026\u0026 \\\n        cargo rustc \\\n            --message-format=json \\\n            -- --print=native-static-libs \\\n        | jq -r '\n            select (.reason == \"compiler-message\")\n            | .message.message\n        ' | sed -nE 's/^native-static-libs: (.*)/\\1/p' \\\n    )\n    ```\n\n    and then use:\n\n    ```bash\n    cc -o main{,.c} -L target/debug -l crate_name ${RUST_STDLIB_DEPS}\n    ```\n\n    \u003c/details\u003e\n\nwhich does output:\n\n```text\nPoint { x: 42.0, y: 42.0 }\n```\n\n🚀🚀\n\n[callbacks]: https://getditto.github.io/safer_ffi/callbacks/_.html\n[cargo-toml]: https://getditto.github.io/safer_ffi/usage/cargo-toml.html\n[ffi_export]: https://getditto.github.io/safer_ffi/ffi-export/_.html\n[header-generation]: https://getditto.github.io/safer_ffi/usage/lib-rs.html#header-generation\n[derive_ReprC]: https://getditto.github.io/safer_ffi/derive-reprc/_.html\n[lib-rs]: https://getditto.github.io/safer_ffi/usage/lib-rs.html\n\n\u003c/details\u003e\n\n## Development\n\n\u003cdetails\u003e\u003csummary\u003eClick to see\u003c/summary\u003e\n\nTo test the code with a certain amount of FFI integration baked into the tests (since `safer-ffi`,\nalone, only _exports_ APIs to the FFI, so doesn't come with FFI callsites on its own), the\n`ffi_tests/` project directory is used to test against C, C#, and Lua callsites.\n\nYou can run these tests directly by doing:\n\n```bash\nmake -C ffi_tests\n```\n\nor by adding `--features ffi-tests` to the `cargo test` command.\n\n### Formatting\n\nCode is formatted using the \"`{MSRV}-nightly` toolchain\". That is, formatting uses some `unstable`\nfeatures of `rustfmt`, so we use a Versioned Nightly™ approach. For the sake of version consistency,\nwe stick to that of our MSRV.\n\nBut since it needs to be a genuine `nightly` toolchain, we are forced to pick an actual `nightly`\ntoolchain, only one whose date matches the birth of the corresponding `MSRV`-stable toolchain.\n\n  - See [`./scripts/formatting/rust-toolchain.toml`](./scripts/formatting/rust-toolchain.toml).\n  - See also, w.r.t. versions and dates: \u003chttps://releases.rs\u003e\n\nTo format the code, you have three options:\n\n  - `./scripts/format.sh`\n\n  - `cargo fmt-nightly` (which is defined as an alias of the previous bullet)\n\n  - `cargo fmt` but only after having run `./scripts/formatting/setup_cargo_fmt_override.sh` at\n    least once.\n\n    This does mutate a bit your `rustup` setup, but in an unobservable way (but for allowing the\n    matching stable toolchain to use `unstable` features when running `cargo fmt`, the very point\n    of this maneuver).\n\n    This is probably the preferred approach for those with IDEs or whatnot which automagically runs\n    `cargo fmt`/`rustfmt` on save.\n\n### Dependencies\n\n  - #### Lua dependencies\n\n    For running the C# FFI integration tests please install `dotnet` (v8.0) dependency:\n\n    See \u003chttps://aka.ms/dotnet-download\u003e for guidance about this.\n\n  - #### Lua dependencies\n\n    For running Lua FFI integration tests please install `luajit` dependency:\n\n    MacOS:\n    ```bash\n    brew install luajit\n    ```\n\n    Ubuntu/Debian:\n    ```bash\n    sudo apt-get install -y luajit\n    ```\n\n### Various integration test suites\n\nsafer-ffi includes three different tests suites that can be run.\n\n```bash\n# In the project root:\ncargo test\n\n# FFI tests\n\nmake -C ffi_tests\n\n# JavaScript tests\n\nmake -C js_tests\n\n# Running the JS tests also gives you instructions for running browser tests.\n# Run this command in the `js_tests` directory, open a browser and navigate to\n# http://localhost:13337/\nwasm-pack build --target web \u0026\u0026 python3 -m http.server 13337\n\n```\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetditto%2Fsafer_ffi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgetditto%2Fsafer_ffi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetditto%2Fsafer_ffi/lists"}