Full Code of AndrewGaspar/corrosion for AI

master f88df62d022d cached
233 files
363.2 KB
99.1k tokens
138 symbols
1 requests
Download .txt
Showing preview only (421K chars total). Download the full file or copy to clipboard to get everything.
Repository: AndrewGaspar/corrosion
Branch: master
Commit: f88df62d022d
Files: 233
Total size: 363.2 KB

Directory structure:
gitextract_hm2o3l7u/

├── .github/
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE/
│   │   └── bug_report.yml
│   ├── scripts/
│   │   ├── determine_compiler.sh
│   │   └── toolchains/
│   │       ├── aarch64-apple-darwin-clang.cmake
│   │       ├── aarch64-unknown-linux-gnu-clang.cmake
│   │       ├── aarch64-unknown-linux-gnu-gcc.cmake
│   │       ├── i686-unknown-linux-gnu-clang.cmake
│   │       ├── i686-unknown-linux-gnu-gcc.cmake
│   │       ├── x86_64-apple-darwin-clang.cmake
│   │       ├── x86_64-pc-windows-gnullvm.cmake
│   │       ├── x86_64-unknown-linux-gnu-clang.cmake
│   │       └── x86_64-unknown-linux-gnu-gcc.cmake
│   └── workflows/
│       ├── gh-pages.yaml
│       ├── linux.yaml
│       ├── test.yaml
│       └── visual_studio.yaml
├── .gitignore
├── CMakeLists.txt
├── CMakePresets.json
├── LICENSE
├── README.md
├── RELEASES.md
├── cmake/
│   ├── Corrosion.cmake
│   ├── CorrosionConfig.cmake.in
│   ├── CorrosionGenerator.cmake
│   └── FindRust.cmake
├── doc/
│   ├── .gitignore
│   ├── book.toml
│   └── src/
│       ├── SUMMARY.md
│       ├── advanced.md
│       ├── common_issues.md
│       ├── ffi_bindings.md
│       ├── introduction.md
│       ├── quick_start.md
│       ├── setup_corrosion.md
│       └── usage.md
└── test/
    ├── CMakeLists.txt
    ├── ConfigureAndBuild.cmake
    ├── README.md
    ├── TestFileExists.cmake
    ├── cargo_flags/
    │   ├── CMakeLists.txt
    │   └── cargo_flags/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── cbindgen/
    │   ├── CMakeLists.txt
    │   ├── auto/
    │   │   ├── CMakeLists.txt
    │   │   ├── main.cpp
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       ├── cbindgen.toml
    │   │       └── src/
    │   │           ├── ffi.rs
    │   │           ├── lib.rs
    │   │           └── other_mod/
    │   │               └── mod.rs
    │   ├── install_lib/
    │   │   ├── CMakeLists.txt
    │   │   └── rust_lib/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           └── lib.rs
    │   └── manual/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── cbindgen.toml
    │           └── src/
    │               ├── ffi.rs
    │               ├── lib.rs
    │               └── other_mod/
    │                   └── mod.rs
    ├── config_discovery/
    │   ├── CMakeLists.txt
    │   ├── README.md
    │   └── config_discovery/
    │       ├── .cargo/
    │       │   └── config.toml
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       └── src/
    │           └── main.rs
    ├── corrosion_install/
    │   ├── CMakeLists.txt
    │   ├── install_lib/
    │   │   ├── CMakeLists.txt
    │   │   ├── main.cpp
    │   │   └── rust_lib/
    │   │       ├── CMakeLists.txt
    │   │       ├── Cargo.toml
    │   │       ├── include/
    │   │       │   └── rust_lib/
    │   │       │       └── rust_lib.hpp
    │   │       └── src/
    │   │           └── lib.rs
    │   └── install_rust_bin/
    │       ├── CMakeLists.txt
    │       └── rust_bin/
    │           ├── CMakeLists.txt
    │           ├── Cargo.toml
    │           └── src/
    │               └── main.rs
    ├── cpp2rust/
    │   ├── CMakeLists.txt
    │   └── cpp2rust/
    │       ├── CMakeLists.txt
    │       ├── lib.cpp
    │       ├── lib2.cpp
    │       ├── path with space/
    │       │   └── lib3.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── build.rs
    │           ├── rust_dependency/
    │           │   ├── Cargo.toml
    │           │   └── src/
    │           │       └── lib.rs
    │           └── src/
    │               └── bin/
    │                   └── rust-exe.rs
    ├── crate_type/
    │   ├── CMakeLists.txt
    │   └── crate_type/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       ├── proj1/
    │       │   ├── Cargo.toml
    │       │   └── src/
    │       │       └── lib.rs
    │       └── proj2/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── custom_profiles/
    │   ├── CMakeLists.txt
    │   ├── basic_profiles/
    │   │   ├── CMakeLists.txt
    │   │   ├── main.cpp
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           └── lib.rs
    │   └── custom_profiles/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── custom_target/
    │   ├── CMakeLists.txt
    │   └── custom_target/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── build.rs
    │           ├── c_lib.c
    │           └── src/
    │               ├── bin.rs
    │               └── lib.rs
    ├── cxxbridge/
    │   ├── CMakeLists.txt
    │   ├── cxxbridge_circular/
    │   │   ├── CMakeLists.txt
    │   │   ├── cpplib.cpp
    │   │   ├── include/
    │   │   │   └── cpplib.h
    │   │   ├── main.cpp
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           └── lib.rs
    │   ├── cxxbridge_cpp2rust/
    │   │   ├── CMakeLists.txt
    │   │   ├── cpplib.cpp
    │   │   ├── include/
    │   │   │   └── cpplib.h
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           ├── lib.rs
    │   │           └── main.rs
    │   ├── cxxbridge_exported_impls/
    │   │   ├── CMakeLists.txt
    │   │   ├── main.cpp
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           ├── bridge_a.rs
    │   │           ├── bridge_b.rs
    │   │           └── lib.rs
    │   └── cxxbridge_rust2cpp/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               ├── foo/
    │               │   └── mod.rs
    │               └── lib.rs
    ├── envvar/
    │   ├── CMakeLists.txt
    │   └── envvar/
    │       ├── .cargo/
    │       │   └── config.toml
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       ├── build.rs
    │       ├── main.cpp
    │       └── src/
    │           └── lib.rs
    ├── features/
    │   ├── CMakeLists.txt
    │   └── features/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── find_rust/
    │   ├── CMakeLists.txt
    │   ├── find_rust/
    │   │   └── CMakeLists.txt
    │   └── rustup_proxy/
    │       └── CMakeLists.txt
    ├── gensource/
    │   ├── CMakeLists.txt
    │   └── gensource/
    │       ├── .gitignore
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       ├── generator/
    │       │   ├── CMakeLists.txt
    │       │   ├── Cargo.toml
    │       │   └── src/
    │       │       └── main.rs
    │       └── src/
    │           └── lib.rs
    ├── hostbuild/
    │   ├── CMakeLists.txt
    │   └── hostbuild/
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       ├── build.rs
    │       └── src/
    │           ├── lib.c
    │           └── main.rs
    ├── multitarget/
    │   ├── CMakeLists.txt
    │   └── multitarget/
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       ├── lib.cpp
    │       └── src/
    │           ├── bin/
    │           │   ├── bin1.rs
    │           │   ├── bin2.rs
    │           │   └── bin3.rs
    │           └── lib.rs
    ├── nostd/
    │   ├── CMakeLists.txt
    │   └── nostd/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── output directory/
    │   ├── CMakeLists.txt
    │   ├── output directory/
    │   │   ├── CMakeLists.txt
    │   │   ├── consumer.cpp
    │   │   ├── proj1/
    │   │   │   ├── Cargo.toml
    │   │   │   └── src/
    │   │   │       ├── bin/
    │   │   │       │   └── rust_bin1.rs
    │   │   │       └── lib.rs
    │   │   ├── proj2/
    │   │   │   ├── Cargo.toml
    │   │   │   └── src/
    │   │   │       ├── bin/
    │   │   │       │   └── rust_bin2.rs
    │   │   │       └── lib.rs
    │   │   └── proj3/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           ├── bin/
    │   │           │   └── rust_bin3.rs
    │   │           └── lib.rs
    │   └── output_directory_config/
    │       ├── CMakeLists.txt
    │       ├── consumer.cpp
    │       └── proj1/
    │           ├── Cargo.toml
    │           └── src/
    │               ├── bin/
    │               │   └── rust_bin1.rs
    │               └── lib.rs
    ├── override_crate_type/
    │   ├── CMakeLists.txt
    │   └── override_crate_type/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── build.rs
    │           └── src/
    │               └── lib.rs
    ├── parse_target_triple/
    │   ├── CMakeLists.txt
    │   ├── parse_target_triple/
    │   │   └── CMakeLists.txt
    │   └── parse_target_triple_should_fail/
    │       └── CMakeLists.txt
    ├── rust2cpp/
    │   ├── CMakeLists.txt
    │   └── rust2cpp/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── build.rs
    │           └── src/
    │               └── lib.rs
    ├── rustflags/
    │   ├── CMakeLists.txt
    │   ├── cargo_config_rustflags/
    │   │   ├── .cargo/
    │   │   │   └── config.toml
    │   │   ├── CMakeLists.txt
    │   │   ├── Cargo.toml
    │   │   └── src/
    │   │       └── main.rs
    │   └── rustflags/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── some_dependency/
    │           │   ├── Cargo.toml
    │           │   └── src/
    │           │       └── lib.rs
    │           └── src/
    │               └── lib.rs
    └── workspace/
        ├── CMakeLists.txt
        └── workspace/
            ├── CMakeLists.txt
            ├── Cargo.toml
            ├── main.cpp
            ├── member1/
            │   ├── Cargo.toml
            │   └── src/
            │       └── lib.rs
            ├── member2/
            │   ├── Cargo.toml
            │   └── src/
            │       └── lib.rs
            └── member3/
                ├── Cargo.toml
                └── src/
                    └── main.rs

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/FUNDING.yml
================================================
github: ["jschwe"]


================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.yml
================================================
name: Bug Report
description: File a bug report
title: "[Bug]: "
labels: ["bug", "triage"]
assignees:
  - jschwe
body:
  - type: markdown
    attributes:
      value: |
        Thanks for taking the time to fill out this bug report!
  - type: textarea
    attributes:
      label: Current Behavior
      description: A concise description of what you're experiencing.
    validations:
      required: false
  - type: textarea
    attributes:
      label: Expected Behavior
      description: A concise description of what you expected to happen.
    validations:
      required: false
  - type: textarea
    attributes:
      label: Steps To Reproduce
      description: Steps to reproduce the behavior.
      placeholder: |
        1. In this environment...
        2. With this config...
        3. Run '...'
        4. See error...
    validations:
      required: false
  - type: textarea
    attributes:
      label: Environment
      description: |
        examples:
          - **OS**: Ubuntu 22.04
          - **CMake**: 3.22.0
          - **CMake Generator**: Ninja 1.11
      value: |
        - OS:
        - CMake:
        - CMake Generator:
      render: markdown
    validations:
      required: false
  - type: textarea
    attributes:
      label: CMake configure log with Debug log-level
      description: |
        Output when configuring with `cmake -S<source_dir> -B<build_dir> --log-level=DEBUG <your_other_options>`:
        <details><summary>CMake configure log</summary>
        <p>
        
        ```
        <log>
        ```
        
        </p>
        </details>
    validations:
      required: false
  - type: textarea
    attributes:
      label: CMake Build step log
      description: |
        Output when building with `cmake --build <build_dir> --verbose`:
        <details><summary>CMake build log</summary>
        <p>

        ```
        <log>
        ```

        </p>
        </details>
    validations:
      required: false


================================================
FILE: .github/scripts/determine_compiler.sh
================================================
#!/usr/bin/env bash

compiler_kind="$1"
runner_os="$2"
target_abi="$3"
target_system_name="$4"
target_arch="$5"

set -e

if [[ -z "$GITHUB_OUTPUT" ]]; then
  echo "Error: This script should only be run in github actions environment"
  exit 1
fi
if [[ -z "${runner_os}" || -z "${target_abi}" || -z  "${target_arch}" ]]; then
  echo "Error: Not all required parameters where set"
  exit 1
fi
if [[ -z "${compiler_kind}" || "${compiler_kind}" == "default" ]]; then
  echo "compiler option was not set. Determining default compiler."
  if [[ "${runner_os}" == "Windows" ]]; then
    if [[ "${target_abi}" == "msvc" ]]; then
      compiler_kind=msvc
    elif [[ "${target_abi}" == "gnu" ]]; then
      compiler_kind=gcc
    else
      echo "Unknown abi for Windows: ${target_abi}"
      exit 1
    fi
  elif [[ "${runner_os}" == "macOS" ]]; then
    compiler_kind="clang"
  elif [[ "${runner_os}" == "Linux" ]]; then
    compiler_kind="gcc"
  else
    echo "Unknown Runner OS: ${runner_os}"
    exit 1
  fi
fi
echo "Compiler Family: '${compiler_kind}'"

if [[ "${compiler_kind}" == "clang" ]]; then
  c_compiler="clang"
  cxx_compiler="clang++"
elif [[ "${compiler_kind}" == "msvc" ]]; then
  c_compiler="cl"
  cxx_compiler="cl"
elif [[ "${compiler_kind}" == "gcc" ]]; then
  if [[ -z "${target_system_name}" ]]; then
    c_compiler="gcc"
    cxx_compiler="g++"
  else
    c_compiler="${target_arch}-linux-gnu-gcc"
    cxx_compiler="${target_arch}-linux-gnu-g++"
  fi
fi
echo "Chose C compiler: '${c_compiler}'"
echo "Chose C++ compiler: '${cxx_compiler}'"
echo "c_compiler=-DCMAKE_C_COMPILER=${c_compiler}" >> $GITHUB_OUTPUT
echo "cxx_compiler=-DCMAKE_CXX_COMPILER=${cxx_compiler}" >> $GITHUB_OUTPUT


================================================
FILE: .github/scripts/toolchains/aarch64-apple-darwin-clang.cmake
================================================
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_C_COMPILER_TARGET "aarch64-apple-darwin")
set(CMAKE_CXX_COMPILER_TARGET "aarch64-apple-darwin")
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "")


================================================
FILE: .github/scripts/toolchains/aarch64-unknown-linux-gnu-clang.cmake
================================================
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_C_COMPILER_TARGET "aarch64-linux-gnu")
set(CMAKE_CXX_COMPILER_TARGET "aarch64-linux-gnu")


================================================
FILE: .github/scripts/toolchains/aarch64-unknown-linux-gnu-gcc.cmake
================================================
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")
set(CMAKE_SYSTEM_NAME "Linux")


================================================
FILE: .github/scripts/toolchains/i686-unknown-linux-gnu-clang.cmake
================================================
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_C_COMPILER_TARGET "i686-pc-linux-gnu")
set(CMAKE_CXX_COMPILER_TARGET "i686-pc-linux-gnu")


================================================
FILE: .github/scripts/toolchains/i686-unknown-linux-gnu-gcc.cmake
================================================
set(CMAKE_C_COMPILER "i686-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "i686-linux-gnu-g++")
set(CMAKE_SYSTEM_NAME "Linux")


================================================
FILE: .github/scripts/toolchains/x86_64-apple-darwin-clang.cmake
================================================
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_C_COMPILER_TARGET "x86_64-apple-darwin")
set(CMAKE_CXX_COMPILER_TARGET "x86_64-apple-darwin")
set(CMAKE_SYSTEM_NAME "Darwin")
set(CMAKE_SYSTEM_VERSION ${CMAKE_HOST_SYSTEM_VERSION})
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "")


================================================
FILE: .github/scripts/toolchains/x86_64-pc-windows-gnullvm.cmake
================================================
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_C_COMPILER_TARGET "x86_64-pc-windows-gnu")
set(CMAKE_CXX_COMPILER_TARGET "x86_64-pc-windows-gnu")


================================================
FILE: .github/scripts/toolchains/x86_64-unknown-linux-gnu-clang.cmake
================================================
# Assumption: This is the native host target.
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")


================================================
FILE: .github/scripts/toolchains/x86_64-unknown-linux-gnu-gcc.cmake
================================================
# Assumption: This is the native host target.
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")


================================================
FILE: .github/workflows/gh-pages.yaml
================================================
name: Deploy GH pages
on:
  push:
    branches:
      - master
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow one concurrent deployment
concurrency:
  group: "pages"
  cancel-in-progress: true

jobs:
  # Build and deploy the documentation of master and the stable/v0.5 branch
  deploy:
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Install mdbook
        env:
          MDBOOK_VERSION: 'v0.4.27'
        run: |
          mkdir mdbook
          curl -sSL https://github.com/rust-lang/mdBook/releases/download/${MDBOOK_VERSION}/mdbook-${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
          echo `pwd`/mdbook >> $GITHUB_PATH
      - name: Checkout master
        uses: actions/checkout@v4
        with:
          path: main
      - name: Checkout stable/v0.5
        uses: actions/checkout@v4
        with:
          path: stable-v0.5
          ref: 'stable/v0.5'
      - name: Setup Pages
        uses: actions/configure-pages@v5
      - name: Build mdbook for main branch
        working-directory: 'main/doc'
        run: mdbook build
      - name: Build mdbook for stable/v0.5 branch
        working-directory: 'stable-v0.5/doc'
        run: mdbook build
      # Override mdbooks default highlight.js with a custom version containing CMake support.
      - uses: actions/checkout@v4
        with:
          repository: 'highlightjs/highlight.js'
          # mdbook currently (as of v0.4.27) does not support v11 yet.
          ref: '10.7.3'
          path: highlightjs
      - name: Build custom highlight.js
        run: |
          npm install
          node tools/build.js :common cmake yaml
        working-directory: highlightjs
      - name: Override highlightjs
        run: |
          cp highlightjs/build/highlight.min.js main/doc/book/highlight.js
          cp highlightjs/build/highlight.min.js stable-v0.5/doc/book/highlight.js
      - name: Copy stable doc into main
        run: mkdir main/doc/book/v0.5 && cp -a stable-v0.5/doc/book/. main/doc/book/v0.5/
      - name: Debug print
        run: ls -la main/doc/book/v0.5
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: 'main/doc/book'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4


================================================
FILE: .github/workflows/linux.yaml
================================================
# Workflow file for Linux hosts
name: Corrosion on Linux
on:
  workflow_call:
    inputs:
      ubuntu_version:
        required: false
        type: string
        default: "latest"
      cmake:
        required: false
        type: string
        default: "3.22.6"
      generator:
        required: true
        type: string
      c_compiler:
        required: true
        type: string
      rust:
        required: false
        type: string
        default: 1.46.0
      target_arch:
        required: false
        type: string
        default: x86_64

jobs:
  linux:
    name: Test Linux
    runs-on: ubuntu-${{ inputs.ubuntu_version }}
    steps:
      - uses: actions/checkout@v4
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "${{ inputs.cmake }}"
          ninjaVersion: "~1.10.0"
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{inputs.rust}}
          targets: ${{inputs.target_arch}}-unknown-linux-gnu
          components: rust-src
      - name: Install Cross Compiler
        shell: bash
        run: |
          echo "::group::apt-install"
          sudo apt-get update
          sudo apt-get install -y "g++-${{inputs.target_arch}}-linux-gnu"
          echo "::endgroup::"
        if: ${{ 'Linux' == runner.os && inputs.target_arch != 'x86_64' }}
      - name: Configure Corrosion
        run: cmake -S. -Bbuild -G "${{ inputs.generator }}" "-DRust_TOOLCHAIN=${{steps.install_rust.outputs.name}}" --preset "${{ inputs.target_arch }}-unknown-linux-gnu-${{ inputs.c_compiler }}"
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -j 3


================================================
FILE: .github/workflows/test.yaml
================================================
name: Tests
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - 'master'
      - 'stable/**'
jobs:

  visual_studio_base:
    name: Test Visual Studio (base)
    uses: ./.github/workflows/visual_studio.yaml
    with:
      vs_version: "2022"
      rust: 1.46.0

  visual_studio_stage2:
    name: Test Visual Studio
    uses: ./.github/workflows/visual_studio.yaml
    needs:
      - visual_studio_base
    strategy:
      matrix:
        vs_version:
          - "2022"
        arch:
          - x86_64
          - i686
          - aarch64
        rust:
          - "1.54.0"
        include:
          - arch: x86_64
            vs_version: 2022
            rust: stable
          - arch: x86_64
            vs_version: 2022
            rust: nightly
    with:
      vs_version: "${{ matrix.vs_version}}"
      rust: 1.54.0
      target_arch: "${{ matrix.arch}}"

  windows_ninja_cl:
    name: Test Windows Ninja MSVC
    runs-on: ${{ matrix.os }}
    needs:
      - visual_studio_base
    strategy:
      fail-fast: false
      matrix:
        os:
          - windows-2022
        arch:
          - x86_64
          - i686
          - aarch64
        compiler:
          - cl
          - clang-cl
          - clang
        include:
          - os: windows-2022
            vs_version: vs-2022
            cmake: 3.22.6
          - rust: 1.54.0
          # Add variable mapping for ilammy/msvc-dev-cmd action
          - arch: x86_64
            msvc_dev_arch: amd64
          - arch: i686
            msvc_dev_arch: amd64_x86
          - arch: aarch64
            msvc_dev_arch: amd64_arm64
        exclude:
          # Not sure what parameters CMake needs when cross-compiling with clang-cl, so exclude for now
          - compiler: clang-cl
            arch: i686
          - compiler: clang-cl
            arch: aarch64
          - compiler: clang
            arch: i686
          - compiler: clang
            arch: aarch64

    steps:
      - uses: actions/checkout@v4
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "${{ matrix.cmake }}"
          ninjaVersion: "~1.10.0"
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{matrix.rust}}
          targets: ${{matrix.arch}}-pc-windows-msvc
          components: rust-src
      - name: Setup MSVC Development Environment
        uses: ilammy/msvc-dev-cmd@v1
        with:
          arch: ${{ matrix.msvc_dev_arch }}
      - name: Configure
        run: cmake -S. -Bbuild "-DRust_TOOLCHAIN=${{steps.install_rust.outputs.name}}" --preset "ninja-${{ matrix.arch }}-pc-windows-msvc-${{ matrix.compiler }}"
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -j 3

  windows_gnu:
    name: Test Windows GNU
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - windows-2022
        arch:
          - x86_64
          # - i686
          # - aarch64
        compiler:
          - gcc # Clang only has experimental support for Cygwin / MinGW, so we don't test it
        generator:
          - ninja
          - make
        include:
          - cmake: 3.22.6
          - rust: 1.54.0

    steps:
      - uses: actions/checkout@v4
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "${{ matrix.cmake }}"
          ninjaVersion: "~1.10.0"
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{matrix.rust}}
          targets: ${{matrix.arch}}-pc-windows-gnu
          components: rust-src
      - name: Configure
        run: cmake -S. -Bbuild "-DRust_TOOLCHAIN=${{steps.install_rust.outputs.name}}" --preset "${{ matrix.generator }}-${{ matrix.arch }}-pc-windows-gnu-${{ matrix.compiler }}"
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -j 3

  windows_gnullvm_msys2:
    name: Test Windows gnullvm on msys2
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - windows-2022
        arch:
          - x86_64
          # - i686
          # - aarch64
        generator:
          - Ninja
          - MSYS Makefiles
        include:
          - arch: x86_64
            msystem: CLANG64
#          - arch: i686
#            msystem: CLANG32
#          - arch: aarch64
#            msystem: CLANGARM64
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - uses: actions/checkout@v4
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          targets: ${{matrix.arch}}-pc-windows-gnullvm
          components: rust-src
      - uses: msys2/setup-msys2@v2
        with:
          msystem: ${{matrix.msystem}}
          path-type: inherit
          install: >-
            git
            make
          pacboy: >-
            toolchain:p
            cmake:p
            ninja:p
      - name: Configure
        run: cmake -S. -Bbuild -G "${{matrix.generator}}" --toolchain=.github/scripts/toolchains/${{matrix.arch}}-pc-windows-gnullvm.cmake
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -j 3

# For now just test if hostbuild works when cross-compiling on windows.
# For testing everything we would also need to install a cross-compiler first.
  windows_cross_hostbuild:
    name: Test Windows Cross
    runs-on: windows-2022
    steps:
      - uses: actions/checkout@v4
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "~3.22.0"
          ninjaVersion: "~1.10.0"
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          targets: aarch64-unknown-linux-gnu
          components: rust-src
      - name: Configure
        run: cmake -S. -Bbuild "-DRust_TOOLCHAIN=${{steps.install_rust.outputs.name}}" -DRust_CARGO_TARGET=aarch64-unknown-linux-gnu
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -R hostbuild

  linux_base:
    name: Test Linux (base)
    uses: ./.github/workflows/linux.yaml
    with:
      c_compiler: "gcc"
      generator: "Ninja"

  linux_stage2:
    name: Test Linux
    needs:
      - linux_base
    uses: ./.github/workflows/linux.yaml
    with:
      target_arch: "${{ matrix.arch }}"
      c_compiler: "${{ matrix.compiler }}"
      generator: "${{ matrix.generator }}"
    strategy:
      fail-fast: false
      matrix:
        arch:
          - x86_64
          - i686
          - aarch64
        compiler:
          - gcc
        generator:
          - "Ninja"
          - "Unix Makefiles"
        include:
          # rustc doesn't support cross-compiling with clang out of the box, since
          # clang requires a --target parameter. Corrosion currently can only pass
          # this for the top-level crate, so linking of cdylibs that are built as
          # dependencies of this crate will fail if they exist.
          # Solutions would be to make cross-compiling with clang work out-of-the-box
          # in rustc, or working around it in corrosion by adding a linker-wrapper.
          # For this reason we only test clang with the host target for now.
          - arch: x86_64
            compiler: clang
            generator: "Ninja"
          - arch: x86_64
            generator: "Ninja Multi-Config"
            compiler: gcc

  darwin:
    name: Test MacOS
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        arch:
          - x86_64
          - aarch64
        compiler:
          - clang
        generator:
          - "Ninja"
          - "Xcode"
        include:
          - os: macos-latest
          - cmake: 3.22.6
          - rust: 1.54.0

    steps:
      - uses: actions/checkout@v4
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "${{ matrix.cmake }}"
          ninjaVersion: "~1.10.0"
      # Install cbindgen before Rust to use recent default Rust version.
      - name: Install cbindgen
        run: cargo install cbindgen
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{matrix.rust}}
          targets: ${{matrix.arch}}-apple-darwin
          components: rust-src
      - name: Configure
        run: cmake -S. -Bbuild --log-level=DEBUG -G "${{ matrix.generator }}" "-DRust_TOOLCHAIN=${{steps.install_rust.outputs.name}}" --preset "${{ matrix.arch }}-apple-darwin-${{ matrix.compiler }}"
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -j 3

  iOS:
    name: Test iOS (simulator)
    runs-on: macos-latest
    strategy:
      fail-fast: false
      matrix:
        generator:
          - "Ninja"
          - "Xcode"
        include:
          - os: macos-latest
          - cmake: 3.24.0
          - rust: stable

    steps:
      - uses: actions/checkout@v4
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "${{ matrix.cmake }}"
          ninjaVersion: "~1.11.0"
      # Install cbindgen before Rust to use recent default Rust version.
      - name: Install cbindgen
        run: cargo install cbindgen
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{matrix.rust}}
          targets: aarch64-apple-ios-sim
          components: rust-src
      - name: Configure
        run: cmake -S. -Bbuild --log-level=DEBUG -G "${{ matrix.generator }}" -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=arm64 -DRust_TOOLCHAIN=${{steps.install_rust.outputs.name}} -DRust_CARGO_TARGET=aarch64-apple-ios-sim
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -j 3


  test_cxxbridge:
    name: Test cxxbridge integration
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - windows-2022
          - ubuntu-latest
          - macos-15
        include:
          # Should be in sync with the `cxx` version the Carg.lock of the cxxbridge tests,
          # otherwise the caching will not work and the cmd will be built from source.
          - cxxbridge_version: "1.0.86"
    steps:
      - uses: actions/checkout@v4
      - uses: actions/cache@v4
        id: cache_cxxbridge
        with:
          path: "~/.cargo/bin/cxxbridge*"
          key: ${{ runner.os }}-cxxbridge_${{ matrix.cxxbridge_version }}
      - name: Install cxxbridge
        if: steps.cache_cxxbridge.outputs.cache-hit != 'true'
        run: cargo install cxxbridge-cmd@${{ matrix.cxxbridge_version }}
      - name: Install lld
        run: sudo apt update && sudo apt install -y lld
        if: ${{ 'Linux' == runner.os }}
      - name: Setup MSVC Development Environment
        uses: ilammy/msvc-dev-cmd@v1
        if: runner.os == 'Windows'
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "~3.24.0"
          ninjaVersion: "~1.10.0"
      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable minus 2 releases
          components: rust-src
      - name: Configure
        run: >
          cmake
          -S.
          -Bbuild
          -GNinja
          -DCORROSION_VERBOSE_OUTPUT=ON
          -DCORROSION_TESTS_CXXBRIDGE=ON
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -j 3 -R "^cxxbridge"

  autoinstall_cargo_target:
    name: Test Auto-installing Cargo target via rustup
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@stable
      - name: Install Cross Compiler
        shell: bash
        run: |
          echo "::group::apt-install"
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu
          echo "::endgroup::"
      - name: Assert rustup target is not installed
        run: rustup show | ( ! grep aarch64)
      - name: Configure Corrosion
        run: cmake -S. -Bbuild -GNinja -DRust_RUSTUP_INSTALL_MISSING_TARGET=ON --preset "aarch64-unknown-linux-gnu-gcc"
      - name: Check rustup target is installed after configuring
        run: rustup show | grep aarch64

  install:
    name: Test Corrosion as a Library
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - windows-2022
          - ubuntu-latest
          - macos-15
        include:
          - rust: 1.54.0

    steps:
      - uses: actions/checkout@v4
      - name: Setup MSVC Development Environment
        uses: ilammy/msvc-dev-cmd@v1
        if: runner.os == 'Windows'
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "~3.22.0"
          ninjaVersion: "~1.10.0"
      # Install cbindgen before Rust to use recent default Rust version.
      - name: Install cbindgen
        run: cargo install cbindgen
      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{matrix.rust}}
          components: rust-src
      - name: Test Corrosion as installed module
        run: >
          cmake
          -S.
          -Bbuild
          -GNinja
          -DCORROSION_VERBOSE_OUTPUT=ON
          -DCMAKE_BUILD_TYPE=Release
          -DCORROSION_TESTS_INSTALL_CORROSION=ON
          &&
          cd build
          &&
          ctest --output-on-failure -C Release -j 3

  # We want an "accumulation" job here because it is easier to specify required
  # jobs here via needs, then in the github UI, since we use matrix jobs.
  ci-success:
    name: bors-ci-status
    if: ${{ always() }}
    needs:
      - visual_studio_stage2
      - windows_ninja_cl
      - windows_gnu
      - windows_gnullvm_msys2
      - linux_stage2
      - darwin
      - iOS
      - test_cxxbridge
      - autoinstall_cargo_target
      - install
    runs-on: ubuntu-latest
    # Step copied from: https://github.com/cross-rs/cross/blob/80c9f9109a719ffb0f694060ddc6e371d5b3a540/.github/workflows/ci.yml#L361
    steps:
      - name: Result
        run: |
          jq -C <<< "${needs}"
          # Check if all needs were successful or skipped.
          "$(jq -r 'all(.result as $result | (["success", "skipped"] | contains([$result])))' <<< "${needs}")"
        env:
          needs: ${{ toJson(needs) }}



================================================
FILE: .github/workflows/visual_studio.yaml
================================================
name: Corrosion with Visual Studio

on:
  workflow_call:
    inputs:
      vs_version:
        required: true
        type: string
        default: 2022
      cmake:
        required: false
        type: string
        default: "3.22.6"
      rust:
        required: false
        type: string
        default: 1.46.0
      target_arch:
        required: false
        type: string
        default: x86_64

jobs:
  visual_studio:
    name: Test Visual Studio ${{ inputs.vs_version }}
    runs-on: "windows-${{ inputs.vs_version }}"
    steps:
      - uses: actions/checkout@v4
      - name: Install CMake
        uses: lukka/get-cmake@519de0c7b4812477d74976b2523a9417f552d126
        with:
          cmakeVersion: "${{ inputs.cmake }}"
          ninjaVersion: "~1.10.0"
      - name: Install Rust
        id: install_rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{inputs.rust}}
          targets: ${{inputs.target_arch}}-pc-windows-msvc
          components: rust-src
      # The initial configure for MSVC is quite slow, so we cache the build directory
      # (including the build directories of the tests) since reconfiguring is
      # significantly faster.
      # - name: Cache MSVC build directory
      #   id: cache-msvc-builddir
      #   uses: actions/cache@v4
      #   with:
      #     path: build
      #     key: ${{ inputs.os }}-${{ inputs.target_arch }}-${{ inputs.rust }}-msvc-${{ inputs.vs_version}}-build
      - name: Configure
        run: cmake -S. -Bbuild -DCORROSION_TESTS_KEEP_BUILDDIRS=ON "-DRust_TOOLCHAIN=${{steps.install_rust.outputs.name}}" --preset "vs-${{ inputs.vs_version }}-${{ inputs.target_arch }}"
      - name: Run Tests
        working-directory: build
        run: ctest --output-on-failure --build-config Debug -j 3


================================================
FILE: .gitignore
================================================

**/target/
**/*.rs.bk
build*/
.vscode
.idea
cmake-build-*
test/test_header.cmake


================================================
FILE: CMakeLists.txt
================================================
cmake_minimum_required(VERSION 3.22)
project(Corrosion
    VERSION 0.6.1
    LANGUAGES NONE
    HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/"
)

# ==== Corrosion Configuration ====

option(
    CORROSION_BUILD_TESTS
    "Build Corrosion test project"
    ${PROJECT_IS_TOP_LEVEL}
)

if (PROJECT_IS_TOP_LEVEL)
    # We need to enable a language for corrosions test to work.
    # For projects using corrosion this is not needed
    enable_language(C)
endif()

# This little bit self-hosts the Corrosion toolchain to build the generator
# tool.
#
# It is strongly encouraged to install Corrosion separately and use
# `find_package(Corrosion REQUIRED)` instead if that works with your workflow.
option(CORROSION_INSTALL_ONLY "Only add rules for installing Corrosion itself." OFF)
if (NOT CORROSION_INSTALL_ONLY)
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
    include(Corrosion)
endif()

# Testing
if (CORROSION_BUILD_TESTS)
    include(CTest)
    add_subdirectory(test)
endif()

# If Corrosion is a subdirectory, do not enable its install code
if (NOT PROJECT_IS_TOP_LEVEL)
    return()
endif()

# Installation

include(GNUInstallDirs)

# Generate the Config file
include(CMakePackageConfigHelpers)

configure_package_config_file(
    cmake/CorrosionConfig.cmake.in CorrosionConfig.cmake
    INSTALL_DESTINATION
        "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
)

write_basic_package_version_file(
    "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY
        SameMajorVersion
    ARCH_INDEPENDENT
)

install(
    FILES
        "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfig.cmake"
        "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
    DESTINATION
        "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
)

# These CMake scripts are needed both for the install and as a subdirectory
install(
    FILES
        cmake/Corrosion.cmake
        cmake/CorrosionGenerator.cmake
        cmake/FindRust.cmake
    DESTINATION
        "${CMAKE_INSTALL_FULL_DATADIR}/cmake"
)


================================================
FILE: CMakePresets.json
================================================
{
    "version": 3,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 22,
        "patch": 0
    },
    "configurePresets": [
        {
            "name": "ninja",
            "hidden": true,
            "generator": "Ninja"
        },
        {
            "name": "ninja-mc",
            "hidden": true,
            "generator": "Ninja Multi-Config"
        },
        {
            "name": "make",
            "hidden": true,
            "generator": "Unix Makefiles"
        },
        {
            "name": "vs-2019",
            "hidden": true,
            "generator": "Visual Studio 16 2019"
        },
        {
            "name": "vs-2022",
            "hidden": true,
            "generator": "Visual Studio 17 2022"
        },
        {
            "name": "windows-only",
            "hidden": true,
            "condition": {
                "type": "equals",
                "lhs": "${hostSystemName}",
                "rhs": "Windows"
            }
        },
        {
            "name": "windows-10-cross",
            "hidden": true,
            "cacheVariables": {
                "CMAKE_SYSTEM_NAME": "Windows",
                "CMAKE_SYSTEM_VERSION": "10.0"
            },
            "condition": {
                "type": "equals",
                "lhs": "${hostSystemName}",
                "rhs": "Windows"
            }
        },
        {
            "name": "x86_64-pc-windows-msvc",
            "hidden": true,
            "inherits": ["windows-only"],
            "cacheVariables": {
                "Rust_CARGO_TARGET": "x86_64-pc-windows-msvc"
            }
        },
        {
            "name": "i686-pc-windows-msvc",
            "hidden": true,
            "cacheVariables": {
                "Rust_CARGO_TARGET": "i686-pc-windows-msvc"
            }
        },
        {
            "name": "aarch64-pc-windows-msvc",
            "hidden": true,
            "cacheVariables": {
                "Rust_CARGO_TARGET": "aarch64-pc-windows-msvc"
            }
        },
        {
            "name": "x86_64-unknown-linux-gnu",
            "hidden": true,
            "cacheVariables": {
                "Rust_CARGO_TARGET": "x86_64-unknown-linux-gnu"
            }
        },
        {
            "name": "i686-unknown-linux-gnu",
            "hidden": true,
            "cacheVariables": {
                "Rust_CARGO_TARGET": "i686-unknown-linux-gnu"
            }
        },
        {
            "name": "aarch64-unknown-linux-gnu",
            "hidden": true,
            "cacheVariables": {
                "Rust_CARGO_TARGET": "aarch64-unknown-linux-gnu"
            }
        },
        {
            "name": "x86_64-apple-darwin",
            "hidden": true,
            "cacheVariables": {
                "Rust_CARGO_TARGET": "x86_64-apple-darwin"
            }
        },
        {
            "name": "aarch64-apple-darwin",
            "hidden": true,
            "cacheVariables": {
                "Rust_CARGO_TARGET": "aarch64-apple-darwin"
            }
        },
        {
            "name": "vs-platform-arm64",
            "hidden": true,
            "inherits": ["aarch64-pc-windows-msvc","windows-10-cross"],
            "architecture": {
                "value": "ARM64"
            }
        },
        {
            "name": "vs-platform-x64",
            "hidden": true,
            "inherits": ["x86_64-pc-windows-msvc"],
            "architecture": {
                "value": "x64"
            }
        },
        {
            "name": "vs-platform-i686",
            "hidden": true,
            "inherits": ["i686-pc-windows-msvc", "windows-10-cross"],
            "architecture": {
                "value": "Win32"
            }
        },
        {
            "name": "vs-2019-x86_64",
            "inherits": ["vs-platform-x64", "vs-2019"]
        },
        {
            "name": "vs-2022-x86_64",
            "inherits": ["vs-platform-x64", "vs-2022"]
        },
        {
            "name": "vs-2019-i686",
            "inherits": ["vs-platform-i686", "vs-2019"]
        },
        {
            "name": "vs-2022-i686",
            "inherits": ["vs-platform-i686", "vs-2022"]
        },
        {
            "name": "vs-2019-aarch64",
            "inherits": ["vs-platform-arm64", "vs-2019"]
        },
        {
            "name": "vs-2022-aarch64",
            "inherits": ["vs-platform-arm64", "vs-2022"]
        },
        {
            "name": "clang",
            "hidden": true,
            "cacheVariables": {
                "CMAKE_C_COMPILER": "clang",
                "CMAKE_CXX_COMPILER": "clang++"
            }
        },
        {
            "name": "host-gcc",
            "hidden": true,
            "cacheVariables": {
                "CMAKE_C_COMPILER": "gcc",
                "CMAKE_CXX_COMPILER": "g++"
            }
        },
        {
            "name": "clang-cl",
            "hidden": true,
            "inherits": ["windows-only"],
            "cacheVariables": {
                "CMAKE_C_COMPILER": "clang-cl",
                "CMAKE_CXX_COMPILER": "clang-cl"
            }
        },
        {
            "name": "cl",
            "hidden": true,
            "inherits": ["windows-only"],
            "cacheVariables": {
                "CMAKE_C_COMPILER": "cl",
                "CMAKE_CXX_COMPILER": "cl"
            }
        },
        {
            "name": "ninja-x86_64-pc-windows-msvc-cl",
            "inherits": ["ninja", "x86_64-pc-windows-msvc", "cl"]
        },
        {
            "name": "ninja-x86_64-pc-windows-msvc-clang-cl",
            "inherits": ["ninja", "x86_64-pc-windows-msvc", "clang-cl"]
        },
        {
            "name": "ninja-x86_64-pc-windows-msvc-clang",
            "inherits": ["ninja", "x86_64-pc-windows-msvc", "clang"]
        },
        {
            "name": "ninja-i686-pc-windows-msvc-cl",
            "inherits": ["ninja", "i686-pc-windows-msvc", "cl", "windows-10-cross"]
        },
        {
            "name": "ninja-i686-pc-windows-msvc-clang-cl",
            "inherits": ["ninja", "i686-pc-windows-msvc", "clang-cl", "windows-10-cross"]
        },
        {
            "name": "ninja-i686-pc-windows-msvc-clang",
            "inherits": ["ninja", "i686-pc-windows-msvc", "clang", "windows-10-cross"]
        },
        {
            "name": "ninja-aarch64-pc-windows-msvc-cl",
            "inherits": ["ninja", "aarch64-pc-windows-msvc", "cl", "windows-10-cross"]
        },
        {
            "name": "ninja-aarch64-pc-windows-msvc-clang-cl",
            "inherits": ["ninja", "aarch64-pc-windows-msvc", "clang-cl", "windows-10-cross"]
        },
        {
            "name": "ninja-aarch64-pc-windows-msvc-clang",
            "inherits": ["ninja", "aarch64-pc-windows-msvc", "clang", "windows-10-cross"]
        },
        {
            "name": "ninja-x86_64-pc-windows-gnullvm",
            "inherits": ["ninja", "windows-only", "clang"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/x86_64-pc-windows-gnullvm.cmake"
        },
        {
            "name": "make-x86_64-pc-windows-gnullvm",
            "inherits": ["make", "windows-only", "clang"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/x86_64-pc-windows-gnullvm.cmake"
        },
        {
            "name": "ninja-x86_64-pc-windows-gnu-gcc",
            "inherits": ["ninja", "host-gcc", "windows-only"]
        },
        {
            "name": "make-x86_64-pc-windows-gnu-gcc",
            "inherits": ["make", "host-gcc", "windows-only"]
        },
        {
            "name": "x86_64-unknown-linux-gnu-clang",
            "inherits": ["x86_64-unknown-linux-gnu"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/${presetName}.cmake"
        },
        {
            "name": "x86_64-unknown-linux-gnu-gcc",
            "inherits": ["x86_64-unknown-linux-gnu"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/${presetName}.cmake"
        },
        {
            "name": "i686-unknown-linux-gnu-clang",
            "inherits": ["i686-unknown-linux-gnu"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/${presetName}.cmake"
        },
        {
            "name": "i686-unknown-linux-gnu-gcc",
            "inherits": ["i686-unknown-linux-gnu"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/${presetName}.cmake"
        },
        {
            "name": "aarch64-unknown-linux-gnu-clang",
            "inherits": ["aarch64-unknown-linux-gnu"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/${presetName}.cmake"
        },
        {
            "name": "aarch64-unknown-linux-gnu-gcc",
            "inherits": ["aarch64-unknown-linux-gnu"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/${presetName}.cmake"
        },
        {
            "name": "x86_64-apple-darwin-clang",
            "inherits": ["x86_64-apple-darwin", "clang"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/${presetName}.cmake"
        },
        {
            "name": "aarch64-apple-darwin-clang",
            "inherits": ["aarch64-apple-darwin"],
            "toolchainFile": "${sourceDir}/.github/scripts/toolchains/${presetName}.cmake"
        }
    ]
}


================================================
FILE: LICENSE
================================================
MIT License

Copyright (c) 2018 Andrew Gaspar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: README.md
================================================
# Corrosion
[![Build Status](https://github.com/corrosion-rs/corrosion/actions/workflows/test.yaml/badge.svg)](https://github.com/corrosion-rs/corrosion/actions?query=branch%3Amaster)
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://corrosion-rs.github.io/corrosion/)
![License](https://img.shields.io/badge/license-MIT-blue)

Corrosion, formerly known as cmake-cargo, is a tool for integrating Rust into an existing CMake
project. Corrosion can automatically import executables, static libraries, and dynamic libraries
from a workspace or package manifest (`Cargo.toml` file).

## Features
- Automatic Import of Executable, Static, and Shared Libraries from Rust Crate
- Easy Installation of Rust Executables
- Trivially Link Rust Executables to C/C++ Libraries in Tree
- Multi-Config Generator Support
- Simple Cross-Compilation

## Sample Usage with FetchContent

Using the CMake `FetchContent` module allows you to easily integrate corrosion into your build.
Other methods including installing corrosion or adding it as a subdirectory are covered in the
[setup chapter](https://corrosion-rs.github.io/corrosion/setup_corrosion.html) of the 
corrosion [documentation](https://corrosion-rs.github.io/corrosion/).

```cmake
include(FetchContent)

FetchContent_Declare(
    Corrosion
    GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
    GIT_TAG v0.6 # Optionally specify a commit hash, version tag or branch here
)
FetchContent_MakeAvailable(Corrosion)

# Import targets defined in a package or workspace manifest `Cargo.toml` file
corrosion_import_crate(MANIFEST_PATH rust-lib/Cargo.toml)

add_executable(your_cpp_bin main.cpp)
target_link_libraries(your_cpp_bin PUBLIC rust-lib)
```

## Requirements

### v0.6 Release

- CMake 3.22 or newer

### v0.5 Release (Critical backports only)

- CMake 3.15 or newer. Some features may only be available on more recent CMake versions
- Rust 1.46 or newer. Some platforms / features may require more recent Rust versions


================================================
FILE: RELEASES.md
================================================
# v0.6.1 (2025-01-17)

## Fixes

- Fix building shared libraries for iOS.
- Fix host linker detection for iOS and add the `CORROSION_HOST_TARGET_LINKER` cache variable,
  to allow users to override the linker used for the host build (required for build-scripts and proc-macros).

# v0.6.0 (2025-11-23)

### Breaking Changes

- Corrosion now requires CMake 3.22. See also the 
  [v0.4.0 Release notes](#040-lts-2023-06-01) for more details.
- Removed native tooling and the corresponding option `CORROSION_NATIVE_TOOLING`.
  Corrosion now always uses pure CMake.
- Fix Corrosion placing artifacts into the wrong directory when:
  1. using a Multi-Config Generator (e.g Visual Studio or XCode) AND
  2. `OUTPUT_DIRECTORY_<CONFIG>` is not set AND 
  3. `OUTPUT_DIRECTORY` is set AND
  4. `OUTPUT_DIRECTORY` does not contain a generator expression

  Corrosion now places artifacts into a `$<CONFIG>` subdirectory of the
  specified `OUTPUT_DIRECTORY`. This matches the [documented behavior][doc-cmake-rt-output-dir]
  of CMake for regular CMake targets. ([#568]).

### New features

- Support using the `$<CONFIG>` generator expression in `OUTPUT_DIRECTORY`. [#459]
- Add `OVERRIDE_CRATE_TYPE` option to corrosion_import_crate, allowing users to override
  the crate-types of Rust libraries (e.g. force building as a staticlib instead of an rlib).
- Support *-windows-gnullvm targets. 
- experimental support in corrosion_install for installing libraries and header files
- Add `CORROSION_TOOLS_RUST_TOOLCHAIN` cache variable which allows users to select a different
  rust toolchain for compiling build-tools used by corrosion (currently cbindgen and cxxbridge).
  This mainly allows using a newer toolchain for such build-tools then for the actual project.
- Initial support for iOS targets [#636](https://github.com/corrosion-rs/corrosion/pull/636)

[doc-cmake-rt-output-dir]: https://cmake.org/cmake/help/latest/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html
[#459]: https://github.com/corrosion-rs/corrosion/pull/459
[#568]: https://github.com/corrosion-rs/corrosion/pull/568

# v0.5.1 (2024-12-29)

### Fixes

- Update FindRust to support `rustup` v1.28.0. Support for older rustup versions is retained,
  so updating corrosion quickly is recommended to all rustup users.


# v0.5.0 (2024-05-11)

### Breaking Changes

- Dashes (`-`) in names of imported CMake **library** targets are now replaced with underscores (`_`).
  See [issue #501] for details. Users on older Corrosion versions will experience the same
  change when using Rust 1.79 or newer. `bin` targets are not affected by this change.

[issue #501]: https://github.com/corrosion-rs/corrosion/issues/501

# v0.4.10 (2024-05-11)

### New features

- `corrosion_experimental_cbindgen()` can now be called multiple times on the same Rust target,
  as long as the output header name differs. This may be useful to generate separate C and C++
  bindings. [#507]
- If `corrosion_link_libraries()` is called on a Rust static library target, then
  `target_link_libraries()` is called to propagate the dependencies to C/C++ consumers.
  Previously a warning was emitted in this case and the arguments ignored. [#506]

### Fixes

- Combine `-framework` flags on macos to avoid linker deduplication errors [#455]
- `corrosion_experimental_cbindgen()` will now correctly use the package name, instead of assuming that
  the package and crate name are identical. ([11e27c])
- Set the `AR_<triple>` variable for `cc-rs` (except for msvc targets) [#456]
- Fix hostbuild when cross-compiling to windows [#477]
- Consider vworks executable suffix [#504]
- `corrosion_experimental_cbindgen()` now forwards the Rust target-triple (e.g. `aarch64-unknown-linux-gnu`)
  to cbindgen via the `TARGET` environment variable. The `hostbuild` property is considered. [#507]
- Fix linking errors with Rust >= 1.79 and `-msvc` targets.` [#511]


[#455]: https://github.com/corrosion-rs/corrosion/pull/455
[#456]: https://github.com/corrosion-rs/corrosion/pull/456
[#477]: https://github.com/corrosion-rs/corrosion/pull/477
[#504]: https://github.com/corrosion-rs/corrosion/pull/504
[#506]: https://github.com/corrosion-rs/corrosion/pull/506
[#507]: https://github.com/corrosion-rs/corrosion/pull/507
[#511]: https://github.com/corrosion-rs/corrosion/pull/511
[11e27c]: https://github.com/corrosion-rs/corrosion/pull/514/commits/11e27cde2cf32c7ed539c96eb03c2f10035de538

# v0.4.9 (2024-05-01)

### New Features 

- Automatically detect Rust target for OpenHarmony ([#510]).

### Fixes

- Make find_package portable ([#509]).

[#510]: https://github.com/corrosion-rs/corrosion/pull/510
[#509]: https://github.com/corrosion-rs/corrosion/pull/509

# v0.4.8 (2024-04-03)

### Fixes

- Fix an internal error when passing both the `PROFILE` and `CRATES` option to
  `corrosion_import_crate()` ([#496]).

[#496]: https://github.com/corrosion-rs/corrosion/pull/496

# v0.4.7 (2024-01-19)

### Fixes

- The C/C++ compiler passed from corrosion to `cc-rs` can now be overridden by users setting
  `CC_<target>` (e.g. `CC_x86_64-unknown-linux-gnu=/path/to/my-compiler`) environment variables ([#475]).

[#475]: https://github.com/corrosion-rs/corrosion/pull/475

# v0.4.6 (2024-01-17)

### Fixes

- Fix hostbuild executables when cross-compiling from non-windows to windows targets.
  (Only with CMake >= 3.19).

# v0.4.5 (2023-11-30)

### Fixes

- Fix hostbuild executables when cross-compiling on windows to non-windows targets
  (Only with CMake >= 3.19).

# v0.4.4 (2023-10-06)

### Fixes

- Add `chimera` ([#445]) and `unikraft` ([#446]) to the list of known vendors

[#445]: https://github.com/corrosion-rs/corrosion/pull/445
[#446]: https://github.com/corrosion-rs/corrosion/pull/446

# v0.4.3 (2023-09-09)

### Fixes

- Fix the PROFILE option with CMake < 3.19 [#427]
- Relax vendor parsing for espressif targets (removes warnings)
- Fix an issue detecting required link libraries with Rust >= 1.71
  when the cmake build directory is located in a Cargo workspace.

# 0.4.2 (2023-07-16)

### Fixes

- Fix an issue when cross-compiling with clang
- Fix detecting required libraries with cargo 1.71 

### New features

- Users can now set `Rust_RESOLVE_RUSTUP_TOOLCHAINS` to `OFF`, which will result in Corrosion
  not attempting to resolve rustc/cargo.

# 0.4.1 (2023-06-03)

This is a bugfix release.

### Fixes

- Fixes a regression on multi-config Generators

# 0.4.0 LTS (2023-06-01)

No changes compared to v0.4.0-beta2.

## Announcements

The `v0.4.x` LTS series will be the last release to support older CMake and Rust versions.
If necessary, fixes will be backported to the v0.4 branch. New features will not be
actively backported after the next major release, but community contributions are possible.
The `v0.4.x` series is currently planned to be maintained until the end of 2024.

The following major release will increase the minimum required CMake version to 3.22. The 
minimum supported Rust version will also be increased to make use of newly added flags, but 
the exact version is not fixed yet. 


## Changes compared to v0.3.5:

### Breaking Changes

- The Visual Studio Generators now require at least CMake 3.20.
  This was previously announced in the 0.3.0 release notes and is the same
  requirement as for the other Multi-Config Generators.
- The previously deprecated function `corrosion_set_linker_language()`
  will now raise an error when called and may be removed without further
  notice in future stable releases. Use `corrosion_set_linker()` instead.
- Improved the FindRust target triple detection, which may cause different behavior in some cases.
  The detection does not require an enabled language anymore and will always fall back
  to the default host target triple. A warning is issued if target triple detection failed.

### Potentially Breaking Changes

- Corrosion now sets the `IMPORTED_NO_SONAME` property for shared rust libraries, since by
  default they won't have an `soname` field.
  If you add a rustflag like `-Clink-arg=-Wl,-soname,libmycrate.so` in your project,
  you should set this property to false on the shared rust library.
- Corrosion now uses a mechanism to determine which native libraries need to be linked with
  Rust `staticlib` targets into C/C++ targets. The previous mechanism contained a hardcoded list.
  The new mechanism asks `rustc` which libraries are needed at minimum for a given
  target triple (with `std` support). This should not be a breaking change, but if you
  do encounter a new linking issue when upgrading with `staticlib` targets, please open an
  issue.

### New features

- `corrosion_import_crate()` has two new options `LOCKED` and `FROZEN` which pass the 
  `--locked` and `--frozen` flags to all invocations of cargo.
- `FindRust` now provides cache variables containing information on the default host
  target triple:
  - `Rust_CARGO_HOST_ARCH`
  - `Rust_CARGO_HOST_VENDOR`
  - `Rust_CARGO_HOST_OS`
  - `Rust_CARGO_HOST_ENV`

### Other changes

- When installing Corrosion with CMake >= 3.19, the legacy Generator tool is
  no longer built and installed by default.
- Corrosion now issues a warning when setting the linker or setting linker
  options for a Rust static library.
- Corrosion no longer enables the `C` language when CMake is in crosscompiling mode and
  no languages where previously enabled. This is not considered a breaking change.
- `corrosion_import_crate()` now warns about unexpected arguments.

### Fixes

- Fix building when the `dev` profile is explicitly set by the user.

## Experimental features (may be changed or removed without a major version bump)

- Experimental cxxbridge and cbindgen integration.
- Add a helper function to parse the package version from a Cargo.toml file
- Expose rustup toolchains discovered by `FindRust` in the following cache variables
  which contain a list.
  - `Rust_RUSTUP_TOOLCHAINS`: List of toolchains names
  - `Rust_RUSTUP_TOOLCHAINS_VERSION`: List of `rustc` version of the toolchains
  - `Rust_RUSTUP_TOOLCHAINS_RUSTC_PATH`: List of the path to `rustc`
  - `Rust_RUSTUP_TOOLCHAINS_CARGO_PATH`: List of the path to `cargo`. Entries may be `NOTFOUND` if cargo
    is not available for that toolchain.
- Add target properties `INTERFACE_CORROSION_RUSTC` and `INTERFACE_CORROSION_CARGO`, which may
  be set to paths to `rustc` and `cargo` respectively to override the toolchain for a specific
  target.

# 0.3.5 (2023-03-19)

- Fix building the Legacy Generator on Rust toolchains < 1.56 ([#365])

[#365]: https://github.com/corrosion-rs/corrosion/pull/365

# 0.3.4 (2023-03-02)

## Fixes

- Fix hostbuild (when CMake/Cargo is configured for cross-compiling) if clang is used ([#338]).

## Other

- Pass `--no-deps` to cargo metadata ([#334]).
- Bump the legacy generator dependencies

[#334]: https://github.com/corrosion-rs/corrosion/pull/334
[#338]: https://github.com/corrosion-rs/corrosion/pull/338


# 0.3.3 (2023-02-17)

## New features (Only available on CMake >= 3.19)

- Add new `IMPORTED_CRATES` flag to `corrosion_import_crate()` to retrieve the list of imported crates in the current
  scope ([#312](https://github.com/corrosion-rs/corrosion/pull/312)).

## Fixes

- Fix imported location target property when the rust target name contains dashes
  and a custom OUTPUT_DIRECTORY was specified by the user ([#322](https://github.com/corrosion-rs/corrosion/pull/322)).
- Fix building for custom rust target-triples ([#316](https://github.com/corrosion-rs/corrosion/pull/316))

# 0.3.2 (2023-01-11)

## New features (Only available on CMake >= 3.19)

- Add new `CRATE_TYPES` flag to `corrosion_import_crate()` to restrict which
  crate types should be imported ([#269](https://github.com/corrosion-rs/corrosion/pull/269)).
- Add `NO_LINKER_OVERRIDE` flag to let Rust choose the default linker for the target
  instead of what Corrosion thinks is the appropriate linker driver ([#272](https://github.com/corrosion-rs/corrosion/pull/272)).

## Fixes

- Fix clean target when cross-compiling ([#291](https://github.com/corrosion-rs/corrosion/pull/291)).
- Don't set the linker for Rust static libraries ([#275](https://github.com/corrosion-rs/corrosion/pull/275)).
- Minor fixes in FindRust [#297](https://github.com/corrosion-rs/corrosion/pull/297): 
  - fix a logic error in the version detection
  - fix a logic error in `QUIET` mode when rustup is not found.

# 0.3.1 (2022-12-13)

### Fixes

- Fix a regression in detecting the MSVC abi ([#256])
- Fix an issue on macOS 13 which affected rust crates compiling C++ code in build scripts ([#254]).
- Fix corrosion not respecting `CMAKE_<XYZ>_OUTPUT_DIRECTORY` values ([#268]).
- Don't override rusts linker choice for the msvc abi (previously this was only skipped for msvc generators) ([#271])

[#254]: https://github.com/corrosion-rs/corrosion/pull/254
[#256]: https://github.com/corrosion-rs/corrosion/pull/256
[#268]: https://github.com/corrosion-rs/corrosion/pull/268
[#271]: https://github.com/corrosion-rs/corrosion/pull/271

# 0.3.0 (2022-10-31)

## Breaking

- The minimum supported rust version (MSRV) was increased to 1.46, due to a cargo issue that recently
  surfaced on CI when using crates.io. On MacOS 12 and Windows-2022 at least Rust 1.54 is required.
- MacOS 10 and 11 are no longer officially supported and untested in CI.
- The minimum required CMake version is now 3.15.
- Adding a `PRE_BUILD` custom command on a `cargo-build_<target_name>` CMake target will no 
  longer work as expected. To support executing user defined commands before cargo build is
  invoked users should use the newly added targets `cargo-prebuild` (before all cargo build invocations)
  or `cargo-prebuild_<target_name>` as a dependency target. 
  Example: `add_dependencies(cargo-prebuild code_generator_target)`

### Breaking: Removed previously deprecated functionality
- Removed `add_crate()` function. Use `corrosio_import_crate()` instead.
- Removed `cargo_link_libraries()` function. Use `corrosion_link_libraries()` instead.
- Removed experimental CMake option `CORROSION_EXPERIMENTAL_PARSER`.
  The corresponding stable option is `CORROSION_NATIVE_TOOLING` albeit with inverted semantics.
- Previously Corrosion would set the `HOST_CC` and `HOST_CXX` environment variables when invoking 
  cargo build, if the environment variables `CC` and `CXX` outside of CMake where set.
  However this did not work as expected in all cases and sometimes the `HOST_CC` variable would be set
  to a cross-compiler for unknown reasons. For this reason `HOST_CC` and `HOST_CXX` are not set by
  corrosion anymore, but users can still set them manually if required via `corrosion_set_env_vars()`.
- The `CARGO_RUST_FLAGS` family of cache variables were removed. Corrosion does not internally use them
  anymore.

## Potentially breaking

- The working directory when invoking `cargo build` was changed to the directory of the Manifest
  file. This now allows cargo to pick up `.cargo/config.toml` files located in the source tree.
  ([205](https://github.com/corrosion-rs/corrosion/pull/205))
- Corrosion internally invokes `cargo build`. When passing arguments to `cargo build`, Corrosion
  now uses the CMake `VERBATIM` option. In rare cases this may require you to change how you quote
  parameters passed to corrosion (e.g. via `corrosion_add_target_rustflags()`).
  For example setting a `cfg` option previously required double escaping the rustflag like this
  `"--cfg=something=\\\"value\\\""`, but now it can be passed to corrosion without any escapes:
  `--cfg=something="value"`.
- Corrosion now respects the CMake `OUTPUT_DIRECTORY` target properties. More details in the "New features" section.

## New features

- Support setting rustflags for only the main target and none of its dependencies ([215](https://github.com/corrosion-rs/corrosion/pull/215)).
  A new function `corrosion_add_target_local_rustflags(target_name rustc_flag [more_flags ...])`
  is added for this purpose.
  This is useful in cases where you only need rustflags on the main-crate, but need to set different
  flags for different targets. Without "local" Rustflags this would require rebuilds of the
  dependencies when switching targets.
- Support explicitly selecting a linker ([208](https://github.com/corrosion-rs/corrosion/pull/208)).
  The linker can be selected via `corrosion_set_linker(target_name linker)`.
  Please note that this only has an effect for targets, where the final linker invocation is done
  by cargo, i.e. targets where foreign code is linked into rust code and not the other way around.
- Corrosion now respects the CMake `OUTPUT_DIRECTORY` target properties and copies build artifacts to the expected
  locations ([217](https://github.com/corrosion-rs/corrosion/pull/217)), if the properties are set.
  This feature requires at least CMake 3.19 and is enabled by default if supported. Please note that the `OUTPUT_NAME`
  target properties are currently not supported.
  Specifically, the following target properties are now respected:
  -   [ARCHIVE_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY.html)
  -   [LIBRARY_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.html)
  -   [RUNTIME_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html)
  -   [PDB_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/PDB_OUTPUT_DIRECTORY.html)
- Corrosion now supports packages with potentially multiple binaries (bins) and a library (lib) at the
  same time. The only requirement is that the names of all `bin`s and `lib`s in the whole project must be unique.
  Users can set the names in the `Cargo.toml` by adding `name = <unique_name>` in the `[[bin]]` and `[lib]` tables.
- FindRust now has improved support for the `VERSION` option of `find_package` and will now attempt to find a matching
  toolchain version. Previously it was only checked if the default toolchain matched to required version.
- For rustup managed toolchains a CMake error is issued with a helpful message if the required target for
  the selected toolchain is not installed.

## Fixes

- Fix a CMake developer Warning when a Multi-Config Generator and Rust executable targets
  ([#213](https://github.com/corrosion-rs/corrosion/pull/213)).
- FindRust now respects the `QUIET` option to `find_package()` in most cases.

## Deprecation notice

- Support for the MSVC Generators with CMake toolchains before 3.20 is deprecated and will be removed in the next
  release (v0.4). All other Multi-config Generators already require CMake 3.20.

## Internal Changes

- The CMake Generator written in Rust and `CorrosionGenerator.cmake` which are responsible for parsing 
  `cargo metadata` output to create corresponding CMake targets for all Rust targets now share most code.
  This greatly simplified the CMake generator written in Rust and makes it much easier maintaining and adding
  new features regardless of how `cargo metadata` is parsed.

# 0.2.2 (2022-09-01)

## Fixes

- Do not use C++17 in the tests (makes tests work with older C++ compilers) ([184](https://github.com/corrosion-rs/corrosion/pull/184))
- Fix finding cargo on NixOS ([192](https://github.com/corrosion-rs/corrosion/pull/192))
- Fix issue with Rustflags test when using a Build type other than Debug and Release ([203](https://github.com/corrosion-rs/corrosion/pull/203)).

# 0.2.1 (2022-05-07)

## Fixes

- Fix missing variables provided by corrosion, when corrosion is used as a subdirectory ([181](https://github.com/corrosion-rs/corrosion/pull/181)):
  Public [Variables](https://github.com/corrosion-rs/corrosion#information-provided-by-corrosion) set
  by Corrosion were not visible when using Corrosion as a subdirectory, due to the wrong scope of
  the variables. This was fixed by promoting the respective variables to Cache variables.

# 0.2.0 (2022-05-05)

## Breaking changes

- Removed the integrator build script ([#156](https://github.com/corrosion-rs/corrosion/pull/156)).
  The build script provided by corrosion (for rust code that links in foreign code) is no longer necessary,
  so users can just remove the dependency.

## Deprecations

- Direct usage of the following target properties has been deprecated. The names of the custom properties are
  no longer considered part of the public API and may change in the future. Instead, please use the functions
  provided by corrosion. Internally different property names are used depending on the CMake version.
  - `CORROSION_FEATURES`, `CORROSION_ALL_FEATURES`, `CORROSION_NO_DEFAULT_FEATURES`. Instead please use
    `corrosion_set_features()`. See the updated Readme for details.
  - `CORROSION_ENVIRONMENT_VARIABLES`. Please use `corrosion_set_env_vars()` instead.
  - `CORROSION_USE_HOST_BUILD`. Please use `corrosion_set_hostbuild()` instead.
- The Minimum CMake version will likely be increased for the next major release. At the very least we want to drop
  support for CMake 3.12, but requiring CMake 3.16 or even 3.18 is also on the table. If you are using a CMake version
  that would be no longer supported by corrosion, please comment on issue
  [#168](https://github.com/corrosion-rs/corrosion/issues/168), so that we can gauge the number of affected users.

## New features

- Add `NO_STD` option to `corrosion_import_crate` ([#154](https://github.com/corrosion-rs/corrosion/pull/154)).
- Remove the requirement of building the Rust based generator crate for CMake >= 3.19. This makes using corrosion as
  a subdirectory as fast as the installed version (since everything is done in CMake).
  ([#131](https://github.com/corrosion-rs/corrosion/pull/131), [#161](https://github.com/corrosion-rs/corrosion/pull/161))
  If you do choose to install Corrosion, then by default the old Generator is still compiled and installed, so you can
  fall back to using it in case you use multiple cmake versions on the same machine for different projects.

## Fixes

- Fix Corrosion on MacOS 11 and 12 ([#167](https://github.com/corrosion-rs/corrosion/pull/167) and
  [#164](https://github.com/corrosion-rs/corrosion/pull/164)).
- Improve robustness of parsing the LLVM version (exported in `Rust_LLVM_VERSION`). It now also works for
  Rust versions, where the LLVM version is reported as `MAJOR.MINOR`. ([#148](https://github.com/corrosion-rs/corrosion/pull/148))
- Fix a bug which occurred when Corrosion was added multiple times via `add_subdirectory()`
  ([#143](https://github.com/corrosion-rs/corrosion/pull/143)).
- Set `CC_<target_triple_undercore>` and `CXX_<target_triple_undercore>` environment variables for the invocation of
  `cargo build` to the compilers selected by CMake  (if any)
  ([#138](https://github.com/corrosion-rs/corrosion/pull/138) and [#161](https://github.com/corrosion-rs/corrosion/pull/161)).
  This should ensure that C dependencies built in cargo buildscripts via [cc-rs](https://github.com/alexcrichton/cc-rs)
  use the same compiler as CMake built dependencies. Users can override the compiler by specifying the higher
  priority environment variable variants with dashes instead of underscores (See cc-rs documentation for details).
- Fix Ninja-Multiconfig Generator support for CMake versions >= 3.20. Previous CMake versions are missing a feature,
  which prevents us from supporting the Ninja-Multiconfig generator. ([#137](https://github.com/corrosion-rs/corrosion/pull/137))


# 0.1.0 (2022-02-01)

This is the first release of corrosion after it was moved to the new corrosion-rs organization.
Since there are no previous releases, this is not a complete changelog but only lists changes since
September 2021.

## New features
- [Add --profile support for rust >= 1.57](https://github.com/corrosion-rs/corrosion/pull/130):
  Allows users to specify a custom cargo profile with
  `corrosion_import_crate(... PROFILE <profilename>)`.
- [Add support for specifying per-target Rustflags](https://github.com/corrosion-rs/corrosion/pull/127):
  Rustflags can be added via `corrosion_add_target_rustflags(<target_name> [rustflags1...])`
- [Add `Rust_IS_NIGHTLY` and `Rust_LLVM_VERSION` variables](https://github.com/corrosion-rs/corrosion/pull/123):
  This may be useful if you want to conditionally enabled features when using a nightly toolchain
  or a specific LLVM Version.
- [Let `FindRust` fail gracefully if rustc is not found](https://github.com/corrosion-rs/corrosion/pull/111):
  This allows using `FindRust` in a more general setting (without corrosion).
- [Add support for cargo feature selection](https://github.com/corrosion-rs/corrosion/pull/108):
  See the [README](https://github.com/corrosion-rs/corrosion#cargo-feature-selection) for details on
  how to select features.


## Fixes
- [Fix the cargo-clean target](https://github.com/corrosion-rs/corrosion/pull/129)
- [Fix #84: CorrosionConfig.cmake looks in wrong place for Corrosion::Generator when CMAKE_INSTALL_LIBEXEC is an absolute path](https://github.com/corrosion-rs/corrosion/pull/122/commits/6f29af3ac53917ca2e0638378371e715a18a532d)
- [Fix #116: (Option CORROSION_INSTALL_EXECUTABLE not working)](https://github.com/corrosion-rs/corrosion/commit/97d44018fac1b1a2a7c095288c628f5bbd9b3184)
- [Fix building on Windows with rust >= 1.57](https://github.com/corrosion-rs/corrosion/pull/120)

## Known issues:
- Corrosion is currently not working on macos-11 and newer. See issue [#104](https://github.com/corrosion-rs/corrosion/issues/104).
  Contributions are welcome.


================================================
FILE: cmake/Corrosion.cmake
================================================
cmake_minimum_required(VERSION 3.22)

list(APPEND CMAKE_MESSAGE_CONTEXT "Corrosion")

message(DEBUG "Using Corrosion ${Corrosion_VERSION} with CMake ${CMAKE_VERSION} "
        "and the `${CMAKE_GENERATOR}` Generator"
)

get_cmake_property(COR_IS_MULTI_CONFIG GENERATOR_IS_MULTI_CONFIG)
set(COR_IS_MULTI_CONFIG "${COR_IS_MULTI_CONFIG}" CACHE BOOL "Do not change this" FORCE)
mark_as_advanced(FORCE COR_IS_MULTI_CONFIG)


if(NOT COR_IS_MULTI_CONFIG AND DEFINED CMAKE_CONFIGURATION_TYPES)
    message(WARNING "The Generator is ${CMAKE_GENERATOR}, which is not a multi-config "
        "Generator, but CMAKE_CONFIGURATION_TYPES is set. Please don't set "
        "CMAKE_CONFIGURATION_TYPES unless you are using a multi-config Generator."
    )
endif()

option(CORROSION_VERBOSE_OUTPUT "Enables verbose output from Corrosion and Cargo" OFF)

if(DEFINED CORROSION_RESPECT_OUTPUT_DIRECTORY AND NOT CORROSION_RESPECT_OUTPUT_DIRECTORY)
    message(WARNING "The option CORROSION_RESPECT_OUTPUT_DIRECTORY was removed."
    " Corrosion now always attempts to respect the output directory.")
endif()

option(
    CORROSION_NO_WARN_PARSE_TARGET_TRIPLE_FAILED
    "Surpresses a warning if the parsing the target triple failed."
    OFF
)

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_NAME STREQUAL "iOS")
    if(DEFINED CORROSION_HOST_TARGET_LINKER)
        set(_corrosion_host_linker "${CORROSION_HOST_TARGET_LINKER}")
        message(DEBUG "Using user provided CORROSION_HOST_TARGET_LINKER: ${CORROSION_HOST_TARGET_LINKER}")
    else()
        set(_corrosion_host_linker "/usr/bin/cc")
    endif()
    set(CORROSION_HOST_TARGET_LINKER "${_corrosion_host_linker}"
        CACHE STRING
        "The linker-driver corrosion will use to compile host-targets. Currently only used when cross-compiling for iOS."
        FORCE)
endif()

find_package(Rust REQUIRED)

if(CMAKE_GENERATOR MATCHES "Visual Studio"
        AND (NOT CMAKE_VS_PLATFORM_NAME STREQUAL CMAKE_VS_PLATFORM_NAME_DEFAULT)
        AND Rust_VERSION VERSION_LESS "1.54")
    message(FATAL_ERROR "Due to a cargo issue, cross-compiling with a Visual Studio generator and rust versions"
            " before 1.54 is not supported. Rust build scripts would be linked with the cross-compiler linker, which"
            " causes the build to fail. Please upgrade your Rust version to 1.54 or newer.")
endif()

#    message(STATUS "Using Corrosion as a subdirectory")

get_property(
    RUSTC_EXECUTABLE
    TARGET Rust::Rustc PROPERTY IMPORTED_LOCATION
)

get_property(
    CARGO_EXECUTABLE
    TARGET Rust::Cargo PROPERTY IMPORTED_LOCATION
)

if(Rust_TOOLCHAIN_IS_RUSTUP_MANAGED AND DEFINED Rust_RUSTUP_TOOLCHAINS)
    set(corrosion_tools_rust_toolchain_docstring "Rust toolchain to use for building helper tools such as cbindgen or cxx-bridge")
    if(DEFINED CORROSION_TOOLS_RUST_TOOLCHAIN)
        set(cor_default_tools_toolchain "${CORROSION_TOOLS_RUST_TOOLCHAIN}")
    else()
        set(cor_default_tools_toolchain "${Rust_TOOLCHAIN}")
    endif()
    set(CORROSION_TOOLS_RUST_TOOLCHAIN "${cor_default_tools_toolchain}" CACHE STRING
        "${corrosion_tools_rust_toolchain_docstring}" FORCE)
    set_property(CACHE CORROSION_TOOLS_RUST_TOOLCHAIN PROPERTY STRINGS "${Rust_RUSTUP_TOOLCHAINS}")
    if(NOT "$CACHE{CORROSION_TOOLS_RUST_TOOLCHAIN}" IN_LIST Rust_RUSTUP_TOOLCHAINS)
        if("$CACHE{CORROSION_TOOLS_RUST_TOOLCHAIN}-${Rust_CARGO_HOST_TARGET}" IN_LIST Rust_RUSTUP_TOOLCHAINS)
            set(CORROSION_TOOLS_RUST_TOOLCHAIN "$CACHE{CORROSION_TOOLS_RUST_TOOLCHAIN}-${Rust_CARGO_HOST_TARGET}"
                CACHE PATH "${corrosion_tools_rust_toolchain_docstring}" FORCE)
        else()
            message(FATAL_ERROR "CORROSION_TOOLS_RUST_TOOLCHAIN must be set to a valid rustup managed toolchain path."
                    "Rust_RUSTUP_TOOLCHAINS contains a list of valid installed toolchains."
            )
        endif()
    endif()
    foreach(toolchain tc_rustc tc_cargo IN ZIP_LISTS Rust_RUSTUP_TOOLCHAINS Rust_RUSTUP_TOOLCHAINS_RUSTC_PATH Rust_RUSTUP_TOOLCHAINS_CARGO_PATH)
        if("${toolchain}" STREQUAL $CACHE{CORROSION_TOOLS_RUST_TOOLCHAIN})
            # Minimum CMake version 3.29 for `IS_EXECUTABLE`.
            if(NOT (tc_cargo AND tc_rustc ))
                message(FATAL_ERROR "Failed to find executable rustc or cargo for toolchain `$CACHE{CORROSION_TOOLS_RUST_TOOLCHAIN}`")
            endif()
            set(CORROSION_TOOLS_RUSTC "${tc_rustc}" CACHE INTERNAL "" FORCE)
            set(CORROSION_TOOLS_CARGO "${tc_cargo}" CACHE INTERNAL "" FORCE)
            break()
        endif()
    endforeach()
    if(NOT DEFINED CACHE{CORROSION_TOOLS_CARGO})
        message(FATAL_ERROR "Internal error: Failed to find toolchain $CACHE{CORROSION_TOOLS_RUST_TOOLCHAIN} in "
                "list of rustup managed toolchains: ${Rust_RUSTUP_TOOLCHAINS}"
        )
    endif()
else()
    # Fallback to the default project toolchain if rust is not rustup managed.
    if(DEFINED CORROSION_TOOLS_RUST_TOOLCHAIN)
        message(DEBUG "Ignoring `CORROSION_TOOLS_RUST_TOOLCHAIN=${CORROSION_TOOLS_RUST_TOOLCHAIN}` "
            "since the toolchains are not rustup managed. Falling back to the default rust toolchain"
            " for this project."
        )
    endif()
    set(CORROSION_TOOLS_RUSTC "${RUSTC_EXECUTABLE}" CACHE INTERNAL "" FORCE)
    set(CORROSION_TOOLS_CARGO "${CARGO_EXECUTABLE}" CACHE INTERNAL "" FORCE)
endif()

function(_corrosion_bin_target_suffix target_name out_var_suffix)
    get_target_property(hostbuild "${target_name}" ${_CORR_PROP_HOST_BUILD})
    if((hostbuild AND CMAKE_HOST_WIN32)
       OR ((NOT hostbuild) AND (Rust_CARGO_TARGET_OS STREQUAL "windows")))
        set(_suffix ".exe")
    elseif(Rust_CARGO_TARGET_OS STREQUAL "vxworks")
        set(_suffix ".vxe")
    else()
        set(_suffix "")
    endif()
    set(${out_var_suffix} "${_suffix}" PARENT_SCOPE)
endfunction()

function(_handle_output_directory_genex input_path config_type output_path)
    if("${config_type}" STREQUAL "")
        # Prevent new path from being `dir//file`, since that causes issues with the
        # file dependency.
        string(REPLACE "/\$<CONFIG>" "${config_type}" curr_out_dir "${input_path}")
        string(REPLACE "\$<CONFIG>" "${config_type}" curr_out_dir "${curr_out_dir}")
    else()
        string(REPLACE "\$<CONFIG>" "${config_type}" curr_out_dir "${input_path}")
    endif()
    string(GENEX_STRIP "${curr_out_dir}" stripped_out_dir)
    if("${stripped_out_dir}" STREQUAL "${curr_out_dir}")
        set("${output_path}" "${curr_out_dir}" PARENT_SCOPE)
    else()
        unset("${output_path}" PARENT_SCOPE)
        message(WARNING "Encountered output directory path with unsupported genex. "
                "Output dir: `${curr_out_dir}`"
                "Note: Corrosion only supports the `\$<CONFIG>` generator expression for output directories.")
    endif()
endfunction()

# Do not call this function directly!
#
# This function should be called deferred to evaluate target properties late in the configure stage.
# IMPORTED_LOCATION does not support Generator expressions, so we must evaluate the output
# directory target property value at configure time. This function must be deferred to the end of
# the configure stage, so we can be sure that the output directory is not modified afterwards.
function(_corrosion_set_imported_location_deferred target_name base_property output_directory_property filename)
    # The output directory property is expected to be set on the exposed target (without postfix),
    # but we need to set the imported location on the actual library target with postfix.
    if("${target_name}" MATCHES "^(.+)-(static|shared)$")
        set(output_dir_prop_target_name "${CMAKE_MATCH_1}")
    else()
        set(output_dir_prop_target_name "${target_name}")
    endif()

    # Append .exe suffix for executable by-products if the target is windows or if it's a host
    # build and the host is Windows.
    get_target_property(target_type ${target_name} TYPE)
    if(${target_type} STREQUAL "EXECUTABLE" AND (NOT "${filename}" MATCHES "\.pdb$"))
        _corrosion_bin_target_suffix(${target_name} "suffix")
        string(APPEND filename "${suffix}")
    endif()

    get_target_property(output_directory "${output_dir_prop_target_name}" "${output_directory_property}")
    message(DEBUG "Output directory property (target ${output_dir_prop_target_name}): ${output_directory_property} dir: ${output_directory}")

    foreach(config_type ${CMAKE_CONFIGURATION_TYPES})
        string(TOUPPER "${config_type}" config_type_upper)
        get_target_property(output_dir_curr_config ${output_dir_prop_target_name}
            "${output_directory_property}_${config_type_upper}"
        )
        if(output_dir_curr_config)
            set(curr_out_dir "${output_dir_curr_config}")
        elseif(output_directory)
            string(GENEX_STRIP "${output_directory}" output_dir_no_genex)
            # Only add config dir if there is no genex in here. See
            # https://cmake.org/cmake/help/latest/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html
            if(output_directory STREQUAL output_dir_no_genex)
                set(curr_out_dir "${output_directory}/${config_type}")
            else()
                set(curr_out_dir "${output_directory}")
            endif()
        else()
            set(curr_out_dir "${CMAKE_CURRENT_BINARY_DIR}")
        endif()
        _handle_output_directory_genex("${curr_out_dir}" "${config_type}" sanitized_out_dir)
        if(NOT DEFINED sanitized_out_dir)
            message(FATAL_ERROR "${output_directory_property} for target ${output_dir_prop_target_name} "
                    "contained an unexpected Generator expression. Output dir: `${curr_out_dir}`"
                "Note: Corrosion only supports the `\$<CONFIG>` generator expression for output directories.")
        endif()

        # For Multiconfig we want to specify the correct location for each configuration
        set_property(
            TARGET ${target_name}
            PROPERTY "${base_property}_${config_type_upper}"
                "${sanitized_out_dir}/${filename}"
        )
        set(base_output_directory "${sanitized_out_dir}")
    endforeach()

    if(NOT COR_IS_MULTI_CONFIG)
        if(output_directory)
            set(base_output_directory "${output_directory}")
        else()
            set(base_output_directory "${CMAKE_CURRENT_BINARY_DIR}")
        endif()
        _handle_output_directory_genex("${base_output_directory}" "${CMAKE_BUILD_TYPE}" sanitized_output_directory)
        if(NOT DEFINED sanitized_output_directory)
            message(FATAL_ERROR "${output_dir_prop_target_name} for target ${output_dir_prop_target_name} "
                    "contained an unexpected Generator expression. Output dir: `${base_output_directory}`."
                    "Note: Corrosion only supports the `\$<CONFIG>` generator expression for output directories.")
        endif()
        set(base_output_directory "${sanitized_output_directory}")
    endif()

    message(DEBUG "Setting ${base_property} for target ${target_name}"
                " to `${base_output_directory}/${filename}`.")

    # IMPORTED_LOCATION must be set regardless of possible overrides. In the multiconfig case,
    # the last configuration "wins" (IMPORTED_LOCATION is not documented to have Genex support).
    set_property(
            TARGET ${target_name}
            PROPERTY "${base_property}" "${base_output_directory}/${filename}"
        )
endfunction()

# Set the imported location of a Rust target.
#
# Rust targets are built via custom targets / custom commands. The actual artifacts are exposed
# to CMake as imported libraries / executables that depend on the cargo_build command. For CMake
# to find the built artifact we need to set the IMPORTED location to the actual location on disk.
# Corrosion tries to copy the artifacts built by cargo to standard locations. The IMPORTED_LOCATION
# is set to point to the copy, and not the original from the cargo build directory.
#
# Parameters:
# - target_name: Name of the Rust target
# - base_property: Name of the base property - i.e. `IMPORTED_LOCATION` or `IMPORTED_IMPLIB`.
# - output_directory_property: Target property name that determines the standard location for the
#    artifact.
# - filename of the artifact.
function(_corrosion_set_imported_location target_name base_property output_directory_property filename)
        cmake_language(EVAL CODE "
            cmake_language(DEFER
                CALL
                _corrosion_set_imported_location_deferred
                [[${target_name}]]
                [[${base_property}]]
                [[${output_directory_property}]]
                [[${filename}]]
            )
        ")
endfunction()

function(_corrosion_copy_byproduct_deferred target_name output_dir_prop_names cargo_build_dir file_names)
    if(ARGN)
        message(FATAL_ERROR "Unexpected additional arguments")
    endif()

    foreach(output_dir_prop_name ${output_dir_prop_names})
        get_target_property(output_dir ${target_name} "${output_dir_prop_name}")
        if(output_dir)
            break()
        endif()
    endforeach()

    # A Genex expanding to the output directory depending on the configuration.
    set(multiconfig_out_dir_genex "")

    foreach(config_type ${CMAKE_CONFIGURATION_TYPES})
        string(TOUPPER "${config_type}" config_type_upper)
        foreach(output_dir_prop_name ${output_dir_prop_names})
            get_target_property(output_dir_curr_config ${target_name} "${output_dir_prop_name}_${config_type_upper}")
            if(output_dir_curr_config)
                break()
            endif()
        endforeach()

        if(output_dir_curr_config)
            set(curr_out_dir "${output_dir_curr_config}")
        elseif(output_dir)
            string(GENEX_STRIP "${output_dir}" output_dir_no_genex)
            # Only add config dir if there is no genex in here. See
            # https://cmake.org/cmake/help/latest/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html
            # Logic duplicated from _corrosion_set_imported_location_deferred
            if(output_dir STREQUAL output_dir_no_genex)
                set(curr_out_dir "${output_dir}/${config_type}")
            else()
                set(curr_out_dir "${output_dir}")
            endif()
        else()
            # Fallback to the default directory. We do not append the configuration directory here
            # and instead let CMake do this, since otherwise the resolving of dynamic library
            # imported paths may fail.
            set(curr_out_dir "${CMAKE_CURRENT_BINARY_DIR}")
        endif()
        set(multiconfig_out_dir_genex "${multiconfig_out_dir_genex}$<$<CONFIG:${config_type}>:${curr_out_dir}>")
    endforeach()

    if(COR_IS_MULTI_CONFIG)
        set(output_dir "${multiconfig_out_dir_genex}")
    else()
        if(NOT output_dir)
            # Fallback to default directory.
            set(output_dir "${CMAKE_CURRENT_BINARY_DIR}")
        endif()
    endif()

    # Append .exe suffix for executable by-products if the target is windows or if it's a host
    # build and the host is Windows.
    get_target_property(target_type "${target_name}" TYPE)
    if (target_type STREQUAL "EXECUTABLE")
        list(LENGTH file_names list_len)
        if(NOT list_len EQUAL "1")
            message(FATAL_ERROR
                    "Internal error: Exactly one filename should be passed for executable types.")
        endif()
        _corrosion_bin_target_suffix(${target_name} "suffix")
        if(suffix AND (NOT "${file_names}" MATCHES "\.pdb$"))
            # For executable targets we know / checked that only one file will be passed.
            string(APPEND file_names "${suffix}")
        endif()
    endif()
    set(src_file_names "${file_names}")
    if(Rust_CARGO_TARGET_ENV STREQUAL "gnullvm")
        # Workaround for cargo not exposing implibs yet.
        list(TRANSFORM src_file_names PREPEND "deps/" REGEX "\.dll\.a$")
    endif()
    list(TRANSFORM src_file_names PREPEND "${cargo_build_dir}/")
    list(TRANSFORM file_names PREPEND "${output_dir}/" OUTPUT_VARIABLE dst_file_names)
    message(DEBUG "Adding command to copy byproducts `${file_names}` to ${dst_file_names}")
    add_custom_command(TARGET _cargo-build_${target_name}
                        POST_BUILD
                        # output_dir may contain a Generator expression.
                        COMMAND  ${CMAKE_COMMAND} -E make_directory "${output_dir}"
                        COMMAND
                        ${CMAKE_COMMAND} -E copy_if_different
                            # tested to work with both multiple files and paths with spaces
                            ${src_file_names}
                            "${output_dir}"
                        BYPRODUCTS ${dst_file_names}
                        COMMENT "Copying byproducts `${file_names}` to ${output_dir}"
                        VERBATIM
                        COMMAND_EXPAND_LISTS
    )
endfunction()

# Copy the artifacts generated by cargo to the appropriate destination.
#
# Parameters:
# - target_name: The name of the Rust target
# - output_dir_prop_names: The property name(s) controlling the destination (e.g.
#   `LIBRARY_OUTPUT_DIRECTORY` or `PDB_OUTPUT_DIRECTORY;RUNTIME_OUTPUT_DIRECTORY`)
# - cargo_build_dir: the directory cargo build places it's output artifacts in.
# - filenames: the file names of any output artifacts as a list.
function(_corrosion_copy_byproducts target_name output_dir_prop_names cargo_build_dir file_names)
        cmake_language(EVAL CODE "
            cmake_language(DEFER
                CALL
                _corrosion_copy_byproduct_deferred
                [[${target_name}]]
                [[${output_dir_prop_names}]]
                [[${cargo_build_dir}]]
                [[${file_names}]]
            )
        ")
endfunction()


# Add targets for the static and/or shared libraries of the rust target.
# The generated byproduct names are returned via the `OUT_<type>_BYPRODUCTS` arguments.
function(_corrosion_add_library_target)
    set(OPTIONS "")
    set(ONE_VALUE_KEYWORDS
        WORKSPACE_MANIFEST_PATH
        TARGET_NAME
        OUT_ARCHIVE_OUTPUT_BYPRODUCTS
        OUT_SHARED_LIB_BYPRODUCTS
        OUT_PDB_BYPRODUCT
    )
    set(MULTI_VALUE_KEYWORDS LIB_KINDS)
    cmake_parse_arguments(PARSE_ARGV 0 CALT "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")

    if(DEFINED CALT_UNPARSED_ARGUMENTS)
        message(FATAL_ERROR "Internal error - unexpected arguments: ${CALT_UNPARSED_ARGUMENTS}")
    elseif(DEFINED CALT_KEYWORDS_MISSING_VALUES)
        message(FATAL_ERROR "Internal error - the following keywords had no associated value(s):"
            "${CALT_KEYWORDS_MISSING_VALUES}")
    endif()
    list(TRANSFORM ONE_VALUE_KEYWORDS PREPEND CALT_ OUTPUT_VARIABLE required_arguments)
    foreach(required_argument ${required_arguments} )
        if(NOT DEFINED "${required_argument}")
            message(FATAL_ERROR "Internal error: Missing required argument ${required_argument}."
                "Complete argument list: ${ARGN}"
            )
        endif()
    endforeach()
    if("staticlib" IN_LIST CALT_LIB_KINDS)
        set(has_staticlib TRUE)
    endif()
    if("cdylib" IN_LIST CALT_LIB_KINDS)
        set(has_cdylib TRUE)
    endif()

    if(NOT (has_staticlib OR has_cdylib))
        message(FATAL_ERROR "Unknown library type(s): ${CALT_LIB_KINDS}")
    endif()
    set(workspace_manifest_path "${CALT_WORKSPACE_MANIFEST_PATH}")
    set(target_name "${CALT_TARGET_NAME}")

    set(is_windows "")
    set(is_windows_gnu "")
    set(is_windows_msvc "")
    set(is_macos "")
    set(is_ios "")
    if(Rust_CARGO_TARGET_OS STREQUAL "windows")
        set(is_windows TRUE)
        if(Rust_CARGO_TARGET_ENV STREQUAL "msvc")
            set(is_windows_msvc TRUE)
        elseif(Rust_CARGO_TARGET_ENV STREQUAL "gnu" OR Rust_CARGO_TARGET_ENV STREQUAL "gnullvm")
            set(is_windows_gnu TRUE)
        endif()
    elseif(Rust_CARGO_TARGET_OS STREQUAL "darwin")
        set(is_macos TRUE)
    elseif(Rust_CARGO_TARGET_OS STREQUAL "ios")
        set(is_ios true)
    endif()

    # target file names
    string(REPLACE "-" "_" lib_name "${target_name}")

    if(is_windows_msvc)
        set(static_lib_name "${lib_name}.lib")
    else()
        set(static_lib_name "lib${lib_name}.a")
    endif()

    if(is_windows)
        set(dynamic_lib_name "${lib_name}.dll")
    elseif(is_macos OR is_ios)
        set(dynamic_lib_name "lib${lib_name}.dylib")
    else()
        set(dynamic_lib_name "lib${lib_name}.so")
    endif()

    if(is_windows_msvc)
        set(implib_name "${lib_name}.dll.lib")
    elseif(is_windows_gnu)
        set(implib_name "lib${lib_name}.dll.a")
    elseif(is_windows)
        message(FATAL_ERROR "Unknown windows environment - Can't determine implib name")
    endif()


    set(pdb_name "${lib_name}.pdb")

    set(archive_output_byproducts "")
    if(has_staticlib)
        list(APPEND archive_output_byproducts ${static_lib_name})
    endif()

    if(has_cdylib)
        set("${CALT_OUT_SHARED_LIB_BYPRODUCTS}" "${dynamic_lib_name}" PARENT_SCOPE)
        if(is_windows)
            list(APPEND archive_output_byproducts ${implib_name})
        endif()
        if(is_windows_msvc)
            set("${CALT_OUT_PDB_BYPRODUCT}" "${pdb_name}" PARENT_SCOPE)
        endif()
    endif()
    set("${CALT_OUT_ARCHIVE_OUTPUT_BYPRODUCTS}" "${archive_output_byproducts}" PARENT_SCOPE)

    if(has_staticlib)
        add_library(${target_name}-static STATIC IMPORTED GLOBAL)
        add_dependencies(${target_name}-static cargo-build_${target_name})
        set_target_properties(${target_name}-static PROPERTIES COR_FILE_NAME ${static_lib_name})

        _corrosion_set_imported_location("${target_name}-static" "IMPORTED_LOCATION"
                "ARCHIVE_OUTPUT_DIRECTORY"
                "${static_lib_name}")

        # Todo: NO_STD target property?
        if(NOT COR_NO_STD)
            set_property(
                    TARGET ${target_name}-static
                    PROPERTY INTERFACE_LINK_LIBRARIES ${Rust_CARGO_TARGET_LINK_NATIVE_LIBS}
            )
            set_property(
                    TARGET ${target_name}-static
                    PROPERTY INTERFACE_LINK_OPTIONS ${Rust_CARGO_TARGET_LINK_OPTIONS}
            )
            if(is_macos)
                set_property(TARGET ${target_name}-static
                        PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
                        )
            endif()
        endif()
    endif()

    if(has_cdylib)
        add_library(${target_name}-shared SHARED IMPORTED GLOBAL)
        add_dependencies(${target_name}-shared cargo-build_${target_name})
        set_target_properties(${target_name}-shared PROPERTIES COR_FILE_NAME ${dynamic_lib_name})

        # Todo: (Not new issue): What about IMPORTED_SONAME and IMPORTED_NO_SYSTEM?
        _corrosion_set_imported_location("${target_name}-shared" "IMPORTED_LOCATION"
                "LIBRARY_OUTPUT_DIRECTORY"
                "${dynamic_lib_name}"
        )
        # In the future we would probably prefer to let Rust set the soname for packages >= 1.0.
        # This is tracked in issue #333.
        set_target_properties(${target_name}-shared PROPERTIES IMPORTED_NO_SONAME TRUE)

        if(is_windows)
            _corrosion_set_imported_location("${target_name}-shared" "IMPORTED_IMPLIB"
                    "ARCHIVE_OUTPUT_DIRECTORY"
                    "${implib_name}"
            )
            set_target_properties(${target_name}-shared PROPERTIES COR_IMPLIB_FILE_NAME ${implib_name})
        endif()

        if(is_macos)
            set_property(TARGET ${target_name}-shared
                    PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
                    )
        endif()
    endif()

    if(has_cdylib AND has_staticlib)
        if(BUILD_SHARED_LIBS)
            target_link_libraries(${target_name} INTERFACE ${target_name}-shared)
        else()
            target_link_libraries(${target_name} INTERFACE ${target_name}-static)
        endif()
    elseif(has_cdylib)
        target_link_libraries(${target_name} INTERFACE ${target_name}-shared)
    else()
        target_link_libraries(${target_name} INTERFACE ${target_name}-static)
    endif()
endfunction()

function(_corrosion_add_bin_target workspace_manifest_path bin_name out_bin_byproduct out_pdb_byproduct)
    if(NOT bin_name)
        message(FATAL_ERROR "No bin_name in _corrosion_add_bin_target for target ${target_name}")
    endif()

    string(REPLACE "-" "_" bin_name_underscore "${bin_name}")

    set(pdb_name "${bin_name_underscore}.pdb")

    if(Rust_CARGO_TARGET_ENV STREQUAL "msvc")
        set(${out_pdb_byproduct} "${pdb_name}" PARENT_SCOPE)
    endif()

    # Potential .exe suffix will be added later, also depending on possible hostbuild
    # target property
    set(bin_filename "${bin_name}")
    set(${out_bin_byproduct} "${bin_filename}" PARENT_SCOPE)
    add_dependencies(${bin_name} cargo-build_${bin_name})

    if(Rust_CARGO_TARGET_OS STREQUAL "darwin")
        set_property(TARGET ${bin_name}
                PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
                )
    endif()

    _corrosion_set_imported_location("${bin_name}" "IMPORTED_LOCATION"
                        "RUNTIME_OUTPUT_DIRECTORY"
                        "${bin_filename}"
    )

endfunction()


include(CorrosionGenerator)

# Note: `cmake_language(GET_MESSAGE_LOG_LEVEL <output_variable>)` requires CMake 3.25,
# so we offer our own option to control verbosity of downstream commands (e.g. cargo build)
if (CORROSION_VERBOSE_OUTPUT)
    set(_CORROSION_VERBOSE_OUTPUT_FLAG --verbose CACHE INTERNAL "")
else()
    # We want to silence some less important commands by default.
    set(_CORROSION_QUIET_OUTPUT_FLAG --quiet CACHE INTERNAL "")
endif()

set(_CORROSION_CARGO_VERSION ${Rust_CARGO_VERSION} CACHE INTERNAL "cargo version used by corrosion")
set(_CORROSION_RUST_CARGO_TARGET ${Rust_CARGO_TARGET} CACHE INTERNAL "target triple used by corrosion")
set(_CORROSION_RUST_CARGO_HOST_TARGET ${Rust_CARGO_HOST_TARGET} CACHE INTERNAL "host triple used by corrosion")
set(_CORROSION_RUSTC "${RUSTC_EXECUTABLE}" CACHE INTERNAL  "Path to rustc used by corrosion")
set(_CORROSION_CARGO "${CARGO_EXECUTABLE}" CACHE INTERNAL "Path to cargo used by corrosion")

string(REPLACE "-" "_" _CORROSION_RUST_CARGO_TARGET_UNDERSCORE "${Rust_CARGO_TARGET}")
set(_CORROSION_RUST_CARGO_TARGET_UNDERSCORE "${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}" CACHE INTERNAL "lowercase target triple with underscores")
string(TOUPPER "${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}" _CORROSION_TARGET_TRIPLE_UPPER)
set(_CORROSION_RUST_CARGO_TARGET_UPPER
        "${_CORROSION_TARGET_TRIPLE_UPPER}"
        CACHE INTERNAL
        "target triple in uppercase with underscore"
)

# We previously specified some Custom properties as part of our public API, however the chosen names prevented us from
# supporting CMake versions before 3.19. In order to both support older CMake versions and not break existing code
# immediately, we are using a different property name depending on the CMake version. However users avoid using
# any of the properties directly, as they are no longer part of the public API and are to be considered deprecated.
# Instead use the corrosion_set_... functions as documented in the Readme.
set(_CORR_PROP_FEATURES CORROSION_FEATURES CACHE INTERNAL "")
set(_CORR_PROP_ALL_FEATURES CORROSION_ALL_FEATURES CACHE INTERNAL "")
set(_CORR_PROP_NO_DEFAULT_FEATURES CORROSION_NO_DEFAULT_FEATURES CACHE INTERNAL "")
set(_CORR_PROP_ENV_VARS CORROSION_ENVIRONMENT_VARIABLES CACHE INTERNAL "")
set(_CORR_PROP_HOST_BUILD CORROSION_USE_HOST_BUILD CACHE INTERNAL "")

# Add custom command to build one target in a package (crate)
#
# A target may be either a specific bin
function(_add_cargo_build out_cargo_build_out_dir)
    set(options NO_LINKER_OVERRIDE)
    set(one_value_args PACKAGE TARGET MANIFEST_PATH WORKSPACE_MANIFEST_PATH)
    set(multi_value_args BYPRODUCTS TARGET_KINDS)
    cmake_parse_arguments(
        ACB
        "${options}"
        "${one_value_args}"
        "${multi_value_args}"
        ${ARGN}
    )

    if(DEFINED ACB_UNPARSED_ARGUMENTS)
        message(FATAL_ERROR "Internal error - unexpected arguments: "
            ${ACB_UNPARSED_ARGUMENTS})
    elseif(DEFINED ACB_KEYWORDS_MISSING_VALUES)
        message(FATAL_ERROR "Internal error - missing values for the following arguments: "
                ${ACB_KEYWORDS_MISSING_VALUES})
    endif()

    set(package_name "${ACB_PACKAGE}")
    set(target_name "${ACB_TARGET}")
    set(path_to_toml "${ACB_MANIFEST_PATH}")
    set(target_kinds "${ACB_TARGET_KINDS}")
    set(workspace_manifest_path "${ACB_WORKSPACE_MANIFEST_PATH}")
    set(build_byproducts "${ACB_BYPRODUCTS}")

    unset(cargo_rustc_crate_types)
    if(NOT target_kinds)
        message(FATAL_ERROR "TARGET_KINDS not specified")
    elseif("staticlib" IN_LIST target_kinds OR "cdylib" IN_LIST target_kinds)
        set(cargo_rustc_filter "--lib")
        if("${Rust_VERSION}" VERSION_GREATER_EQUAL "1.64")
            # https://doc.rust-lang.org/1.64.0/cargo/commands/cargo-rustc.html
            # `--crate-type` is documented since Rust 1.64 for `cargo rustc`.
            # We just unconditionally set it when available, to support overriding the crate type.
            # Due to https://github.com/rust-lang/cargo/issues/14498 we can't use one argument and pass a
            # comma seperated list. Instead we use multiple arguments.
            set(cargo_rustc_crate_types "${target_kinds}")
            list(TRANSFORM cargo_rustc_crate_types PREPEND "--crate-type=")
        endif()
    elseif("bin" IN_LIST target_kinds)
        set(cargo_rustc_filter "--bin=${target_name}")
    else()
        message(FATAL_ERROR "TARGET_KINDS contained unknown kind `${target_kind}`")
    endif()

    if (NOT IS_ABSOLUTE "${path_to_toml}")
        set(path_to_toml "${CMAKE_SOURCE_DIR}/${path_to_toml}")
    endif()
    get_filename_component(workspace_toml_dir ${path_to_toml} DIRECTORY )

    if (CMAKE_VS_PLATFORM_NAME)
        set(build_dir "${CMAKE_VS_PLATFORM_NAME}/$<CONFIG>")
    elseif(COR_IS_MULTI_CONFIG)
        set(build_dir "$<CONFIG>")
    else()
        unset(build_dir)
    endif()

    # If a CMake sysroot is specified, forward it to the linker rustc invokes, too. CMAKE_SYSROOT is documented
    # to be passed via --sysroot, so we assume that when it's set, the linker supports this option in that style.
    if(CMAKE_CROSSCOMPILING AND CMAKE_SYSROOT)
        set(corrosion_link_args "--sysroot=${CMAKE_SYSROOT}")
    endif()

    if(COR_ALL_FEATURES)
        set(all_features_arg --all-features)
    endif()
    if(COR_NO_DEFAULT_FEATURES)
        set(no_default_features_arg --no-default-features)
    endif()
    if(COR_NO_USES_TERMINAL)
        unset(cor_uses_terminal)
    else()
        set(cor_uses_terminal USES_TERMINAL)
    endif()

    set(global_rustflags_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_RUSTFLAGS>>")
    set(local_rustflags_target_property  "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_LOCAL_RUSTFLAGS>>")

    # todo: this probably should be TARGET_GENEX_EVAL
    set(features_target_property "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_FEATURES}>>")
    set(features_genex "$<$<BOOL:${features_target_property}>:--features=$<JOIN:${features_target_property},$<COMMA>>>")

    # target property overrides corrosion_import_crate argument
    set(all_features_target_property "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_ALL_FEATURES}>>")
    set(all_features_arg "$<$<BOOL:${all_features_target_property}>:--all-features>")

    set(no_default_features_target_property "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_NO_DEFAULT_FEATURES}>>")
    set(no_default_features_arg "$<$<BOOL:${no_default_features_target_property}>:--no-default-features>")

    set(build_env_variable_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_ENV_VARS}>>")
    set(hostbuild_override "$<BOOL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_HOST_BUILD}>>")
    set(if_not_host_build_condition "$<NOT:${hostbuild_override}>")

    set(corrosion_link_args "$<${if_not_host_build_condition}:${corrosion_link_args}>")
    # We always set `--target`, so that cargo always places artifacts into a directory with the
    # target triple.
    set(cargo_target_option "--target=$<IF:${hostbuild_override},${_CORROSION_RUST_CARGO_HOST_TARGET},${_CORROSION_RUST_CARGO_TARGET}>")

    # The target may be a filepath to custom target json file. For host targets we assume that they are built-in targets.
    _corrosion_strip_target_triple("${_CORROSION_RUST_CARGO_TARGET}" stripped_target_triple)
    _corrosion_strip_target_triple("${_CORROSION_RUST_CARGO_TARGET_UPPER}" stripped_target_triple_upper)
    set(target_artifact_dir "$<IF:${hostbuild_override},${_CORROSION_RUST_CARGO_HOST_TARGET},${stripped_target_triple}>")

    set(flags_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_CARGO_FLAGS>>")

    set(explicit_linker_property "$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_LINKER>")
    set(explicit_linker_defined "$<BOOL:${explicit_linker_property}>")

    set(cargo_profile_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_CARGO_PROFILE>>")

    # Option to override the rustc/cargo binary to something other than the global default
    set(rustc_override "$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_RUSTC>")
    set(cargo_override "$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_CARGO>")
    set(rustc_bin "$<IF:$<BOOL:${rustc_override}>,${rustc_override},${_CORROSION_RUSTC}>")
    set(cargo_bin "$<IF:$<BOOL:${cargo_override}>,${cargo_override},${_CORROSION_CARGO}>")


    # Rust will add `-lSystem` as a flag for the linker on macOS. Adding the -L flag via RUSTFLAGS only fixes the
    # problem partially - buildscripts still break, since they won't receive the RUSTFLAGS. This seems to only be a
    # problem if we specify the linker ourselves (which we do, since this is necessary for e.g. linking C++ code).
    # We can however set `LIBRARY_PATH`, which is propagated to the build-script-build properly.
    if(NOT CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Darwin")
        # not needed anymore on macos 13 (and causes issues)
        if(${CMAKE_SYSTEM_VERSION} VERSION_LESS 22)
        set(cargo_library_path "LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib")
        endif()
    elseif(CMAKE_CROSSCOMPILING AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
        if(${CMAKE_HOST_SYSTEM_VERSION} VERSION_LESS 22)
            set(cargo_library_path "$<${hostbuild_override}:LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib>")
        endif()
    endif()

    set(cargo_profile_set "$<BOOL:${cargo_profile_target_property}>")
    # In the default case just specify --release or nothing to stay compatible with
    # older rust versions.
    set(default_profile_option "$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:>>>:--release>")
    # evaluates to either `--profile=<custom_profile>`, `--release` or nothing (for debug).
    set(cargo_profile "$<IF:${cargo_profile_set},--profile=${cargo_profile_target_property},${default_profile_option}>")

    # If the profile name is `dev` change the dir name to `debug`.
    set(is_dev_profile "$<STREQUAL:${cargo_profile_target_property},dev>")
    set(profile_dir_override "$<${is_dev_profile}:debug>")
    set(profile_dir_is_overridden "$<BOOL:${profile_dir_override}>")
    set(custom_profile_build_type_dir "$<IF:${profile_dir_is_overridden},${profile_dir_override},${cargo_profile_target_property}>")

    set(default_build_type_dir "$<IF:$<OR:$<CONFIG:Debug>,$<CONFIG:>>,debug,release>")
    set(build_type_dir "$<IF:${cargo_profile_set},${custom_profile_build_type_dir},${default_build_type_dir}>")

    # We set a target folder based on the manifest path so if you build multiple workspaces (or standalone projects
    # without workspace) they won't collide if they use a common dependency. This would confuse cargo and trigger
    # unnecessary rebuilds
    cmake_path(GET workspace_manifest_path PARENT_PATH parent_path)
    cmake_path(GET parent_path PARENT_PATH grandparent_path)
    string(REPLACE "${grandparent_path}/" "" cargo_folder_name "${parent_path}")
    string(SHA1 cargo_path_hash ${workspace_manifest_path})
    # Include a hash of the full path in case there are multiple projects with the same folder name
    string(SUBSTRING "${cargo_path_hash}" 0 5 cargo_path_hash)
    cmake_path(APPEND CMAKE_BINARY_DIR ${build_dir} cargo "${cargo_folder_name}_${cargo_path_hash}"
               OUTPUT_VARIABLE cargo_target_dir)
    set(cargo_build_dir "${cargo_target_dir}/${target_artifact_dir}/${build_type_dir}")
    set("${out_cargo_build_out_dir}" "${cargo_build_dir}" PARENT_SCOPE)

    set(corrosion_cc_rs_flags)

    if(CMAKE_C_COMPILER)
        # This variable is read by cc-rs (often used in build scripts) to determine the c-compiler.
        # It can still be overridden if the user sets the non underscore variant via the environment variables
        # on the target.
        list(APPEND corrosion_cc_rs_flags "CC_${stripped_target_triple}=${CMAKE_C_COMPILER}")
    endif()
    if(CMAKE_CXX_COMPILER)
        list(APPEND corrosion_cc_rs_flags "CXX_${stripped_target_triple}=${CMAKE_CXX_COMPILER}")
    endif()
    # cc-rs doesn't seem to support `llvm-ar` (commandline syntax), wo we might as well just use
    # the default AR.
    if(CMAKE_AR AND NOT (Rust_CARGO_TARGET_ENV STREQUAL "msvc"))
        list(APPEND corrosion_cc_rs_flags "AR_${stripped_target_triple}=${CMAKE_AR}")
    endif()

    # When using XCode to target iOS / iOSSimulator, `cc` will be a compiler that targets iOS.
    # (Presumably this is because XCode modifies PATH).
    # This causes linker errors, because Rust compiles build-scripts and proc-macros for the host-platform, and
    # assumes `cc` is a valid linker driver for the host platform (but in this case `cc` targets iOS).
    # To work around this we explicitly set the linker for the host platform.
    unset(cargo_host_target_linker)
    if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_NAME STREQUAL "iOS")
        string(TOUPPER "${Rust_CARGO_HOST_TARGET_CACHED}" host_target_upper)
        string(REPLACE "-" "_" host_target_upper_underscore "${host_target_upper}")
        set(cargo_host_target_linker "CARGO_TARGET_${host_target_upper_underscore}_LINKER=$CACHE{CORROSION_HOST_TARGET_LINKER}")
        message(DEBUG "Setting `${cargo_host_target_linker}` for target ${target_name} to workaround a hostbuild"
            " issue when building targets for iOS."
        )
    endif()

    # Since we instruct cc-rs to use the compiler found by CMake, it is likely one that requires also
    # specifying the target sysroot to use. CMake's generator makes sure to pass --sysroot with
    # CMAKE_OSX_SYSROOT. Fortunately the compilers Apple ships also respect the SDKROOT environment
    # variable, which we can set for use when cc-rs invokes the compiler.
    if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_SYSROOT)
        list(APPEND corrosion_cc_rs_flags "SDKROOT=${CMAKE_OSX_SYSROOT}")
    endif()

    # Ensure that cc-rs targets same Apple platform version as the CMake build
    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_DEPLOYMENT_TARGET)
        list(APPEND corrosion_cc_rs_flags "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
    endif()

    corrosion_add_target_local_rustflags("${target_name}" "$<$<BOOL:${corrosion_link_args}>:-Clink-args=${corrosion_link_args}>")

    # todo: this should probably also be guarded by if_not_host_build_condition.
    if(COR_NO_STD)
        corrosion_add_target_local_rustflags("${target_name}" "-Cdefault-linker-libraries=no")
    else()
        corrosion_add_target_local_rustflags("${target_name}" "-Cdefault-linker-libraries=yes")
    endif()

    set(global_joined_rustflags "$<JOIN:${global_rustflags_target_property}, >")
    set(global_rustflags_genex "$<$<BOOL:${global_rustflags_target_property}>:RUSTFLAGS=${global_joined_rustflags}>")
    set(local_rustflags_delimiter "$<$<BOOL:${local_rustflags_target_property}>:-->")
    set(local_rustflags_genex "$<$<BOOL:${local_rustflags_target_property}>:${local_rustflags_target_property}>")

    set(deps_link_languages_prop "$<TARGET_PROPERTY:_cargo-build_${target_name},CARGO_DEPS_LINKER_LANGUAGES>")
    set(deps_link_languages "$<TARGET_GENEX_EVAL:_cargo-build_${target_name},${deps_link_languages_prop}>")
    set(target_uses_cxx  "$<IN_LIST:CXX,${deps_link_languages}>")
    unset(default_linker)
    # With the MSVC ABI rustc only supports directly invoking the linker - Invoking cl as the linker driver is not supported.
    if(NOT (Rust_CARGO_TARGET_ENV STREQUAL "msvc" OR COR_NO_LINKER_OVERRIDE))
        set(default_linker "$<IF:$<BOOL:${target_uses_cxx}>,${CMAKE_CXX_COMPILER},${CMAKE_C_COMPILER}>")
    endif()
    # Used to set a linker for a specific target-triple.
    set(cargo_target_linker_var "CARGO_TARGET_${stripped_target_triple_upper}_LINKER")
    set(linker "$<IF:${explicit_linker_defined},${explicit_linker_property},${default_linker}>")
    set(cargo_target_linker $<$<BOOL:${linker}>:${cargo_target_linker_var}=${linker}>)

    if(Rust_CROSSCOMPILING AND (CMAKE_C_COMPILER_TARGET OR CMAKE_CXX_COMPILER_TARGET))
        set(linker_target_triple "$<IF:$<BOOL:${target_uses_cxx}>,${CMAKE_CXX_COMPILER_TARGET},${CMAKE_C_COMPILER_TARGET}>")
        set(rustflag_linker_arg "-Clink-args=--target=${linker_target_triple}")
        set(rustflag_linker_arg "$<${if_not_host_build_condition}:${rustflag_linker_arg}>")
        # Skip adding the linker argument, if the linker is explicitly set, since the
        # explicit_linker_property will not be set when this function runs.
        # Passing this rustflag is necessary for clang.
        corrosion_add_target_local_rustflags("${target_name}" "$<$<NOT:${explicit_linker_defined}>:${rustflag_linker_arg}>")
    endif()

    message(DEBUG "TARGET ${target_name} produces byproducts ${build_byproducts}")
    message(DEBUG "corrosion_cc_rs_flags: ${corrosion_cc_rs_flags}")

    add_custom_target(
        _cargo-build_${target_name}
        # Build crate
        COMMAND
            ${CMAKE_COMMAND} -E env
                "${build_env_variable_genex}"
                "${global_rustflags_genex}"
                "${cargo_target_linker}"
                "${cargo_host_target_linker}"
                "${corrosion_cc_rs_flags}"
                "${cargo_library_path}"
                "CORROSION_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}"
                "CARGO_BUILD_RUSTC=${rustc_bin}"
            "${cargo_bin}"
                rustc
                ${cargo_rustc_filter}
                ${cargo_target_option}
                ${_CORROSION_VERBOSE_OUTPUT_FLAG}
                ${all_features_arg}
                ${no_default_features_arg}
                ${features_genex}
                --package ${package_name}
                ${cargo_rustc_crate_types}
                --manifest-path "${path_to_toml}"
                --target-dir "${cargo_target_dir}"
                ${cargo_profile}
                ${flags_genex}
                # Any arguments to cargo must be placed before this line
                ${local_rustflags_delimiter}
                ${local_rustflags_genex}

        # Note: `BYPRODUCTS` may not contain **target specific** generator expressions.
        # This means we cannot use `${cargo_build_dir}`, since it currently uses `$<TARGET_PROPERTY>`
        # to determine the correct target directory, depending on if the hostbuild target property is
        # set or not.
        # BYPRODUCTS  "${cargo_build_dir}/${build_byproducts}"
        
        # Set WORKING_DIRECTORY to the directory containing the manifest, so that configuration files
        # such as `.cargo/config.toml` or `toolchain.toml` are applied as expected. Cargo searches for
        # configuration files by walking upward from the current directory.
        WORKING_DIRECTORY "${workspace_toml_dir}"
        ${cor_uses_terminal}
        COMMAND_EXPAND_LISTS
        VERBATIM
    )

    # User exposed custom target, that depends on the internal target.
    # Corrosion post build steps are added on the internal target, which
    # ensures that they run before any user defined post build steps on this
    # target.
    add_custom_target(
        cargo-build_${target_name}
        ALL
    )
    add_dependencies(cargo-build_${target_name} _cargo-build_${target_name})

    # Add custom target before actual build that user defined custom commands (e.g. code generators) can
    # use as a hook to do something before the build. This mainly exists to not expose the `_cargo-build` targets.
    add_custom_target(cargo-prebuild_${target_name})
    add_dependencies(_cargo-build_${target_name} cargo-prebuild_${target_name})
    if(NOT TARGET cargo-prebuild)
        add_custom_target(cargo-prebuild)
    endif()
    add_dependencies(cargo-prebuild cargo-prebuild_${target_name})

    add_custom_target(
        cargo-clean_${target_name}
        COMMAND
            "${cargo_bin}" clean ${cargo_target_option}
            -p ${package_name} --manifest-path "${path_to_toml}"
        # Set WORKING_DIRECTORY to the directory containing the manifest, so that configuration files
        # such as `.cargo/config.toml` or `toolchain.toml` are applied as expected. Cargo searches for
        # configuration files by walking upward from the current directory.
        WORKING_DIRECTORY "${workspace_toml_dir}"
        ${cor_uses_terminal}
    )

    if (NOT TARGET cargo-clean)
        add_custom_target(cargo-clean)
    endif()
    add_dependencies(cargo-clean cargo-clean_${target_name})
endfunction()

#[=======================================================================[.md:
ANCHOR: corrosion-import-crate
```cmake
corrosion_import_crate(
        MANIFEST_PATH <path/to/cargo.toml>
        [ALL_FEATURES]
        [NO_DEFAULT_FEATURES]
        [NO_STD]
        [NO_LINKER_OVERRIDE]
        [NO_USES_TERMINAL]
        [LOCKED]
        [FROZEN]
        [PROFILE <cargo-profile>]
        [IMPORTED_CRATES <variable-name>]
        [CRATE_TYPES <crate_type1> ... <crate_typeN>]
        [OVERRIDE_CRATE_TYPE <crate_name>=<crate_type1,crate_type2,...> ...]
        [CRATES <crate1> ... <crateN>]
        [FEATURES <feature1> ... <featureN>]
        [FLAGS <flag1> ... <flagN>]
)
```
* **MANIFEST_PATH**: Path to a [Cargo.toml Manifest] file.
* **ALL_FEATURES**: Equivalent to [--all-features] passed to cargo build
* **NO_DEFAULT_FEATURES**: Equivalent to [--no-default-features] passed to cargo build
* **NO_STD**:  Disable linking of standard libraries (required for no_std crates).
* **NO_LINKER_OVERRIDE**: Will let Rust/Cargo determine which linker to use instead of corrosion (when linking is invoked by Rust)
* **NO_USES_TERMINAL**: Don't pass the `USES_TERMINAL` flag when creating the custom CMake targets.
* **LOCKED**: Pass [`--locked`] to cargo build and cargo metadata.
* **FROZEN**: Pass [`--frozen`] to cargo build and cargo metadata.
* **PROFILE**: Specify cargo build profile (`dev`/`release` or a [custom profile]; `bench` and `test` are not supported)
* **IMPORTED_CRATES**: Save the list of imported crates into the variable with the provided name in the current scope.
* **CRATE_TYPES**: Only import the specified crate types. Valid values: `staticlib`, `cdylib`, `bin`.
* **OVERRIDE_CRATE_TYPE**: Override the crate-types of a cargo crate with the given comma-separated values.
                           Internally uses the `rustc` flag [`--crate-type`] to override the crate-type.
                           Valid values for the crate types are the library types `staticlib` and `cdylib`.
* **CRATES**: Only import the specified crates from a workspace. Values: Crate names.
* **FEATURES**: Enable the specified features. Equivalent to [--features] passed to `cargo build`.
* **FLAGS**:  Arbitrary flags to `cargo build`.

[custom profile]: https://doc.rust-lang.org/cargo/reference/profiles.html#custom-profiles
[--all-features]: https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options
[--no-default-features]: https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options
[--features]: https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options
[`--locked`]: https://doc.rust-lang.org/cargo/commands/cargo.html#manifest-options
[`--frozen`]: https://doc.rust-lang.org/cargo/commands/cargo.html#manifest-options
[`--crate-type`]: https://doc.rust-lang.org/rustc/command-line-arguments.html#--crate-type-a-list-of-types-of-crates-for-the-compiler-to-emit
[Cargo.toml Manifest]: https://doc.rust-lang.org/cargo/appendix/glossary.html#manifest

ANCHOR_END: corrosion-import-crate
#]=======================================================================]
function(corrosion_import_crate)
    set(OPTIONS
        ALL_FEATURES
        NO_DEFAULT_FEATURES
        NO_STD
        NO_LINKER_OVERRIDE
        NO_USES_TERMINAL
        LOCKED
        FROZEN)
    set(ONE_VALUE_KEYWORDS MANIFEST_PATH PROFILE IMPORTED_CRATES)
    set(MULTI_VALUE_KEYWORDS CRATE_TYPES CRATES FEATURES FLAGS OVERRIDE_CRATE_TYPE)
    cmake_parse_arguments(COR "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}" ${ARGN})
    list(APPEND CMAKE_MESSAGE_CONTEXT "corrosion_import_crate")

    if(DEFINED COR_UNPARSED_ARGUMENTS)
        message(AUTHOR_WARNING "Unexpected arguments: " ${COR_UNPARSED_ARGUMENTS}
            "\nCorrosion will ignore these unexpected arguments."
            )
    endif()
    if(DEFINED COR_KEYWORDS_MISSING_VALUES)
        message(DEBUG "Note: the following keywords passed to corrosion_import_crate had no associated value(s): "
            ${COR_KEYWORDS_MISSING_VALUES}
        )
    endif()
    if (NOT DEFINED COR_MANIFEST_PATH)
        message(FATAL_ERROR "MANIFEST_PATH is a required keyword to corrosion_add_crate")
    endif()
    _corrosion_option_passthrough_helper(NO_LINKER_OVERRIDE COR no_linker_override)
    _corrosion_option_passthrough_helper(LOCKED COR locked)
    _corrosion_option_passthrough_helper(FROZEN COR frozen)
    _corrosion_arg_passthrough_helper(CRATES COR crate_allowlist)
    _corrosion_arg_passthrough_helper(CRATE_TYPES COR crate_types)

    if(COR_PROFILE)
        if(Rust_VERSION VERSION_LESS 1.57.0)
            message(FATAL_ERROR "Selecting custom profiles via `PROFILE` requires at least rust 1.57.0, but you "
                        "have ${Rust_VERSION}."
        )
        # The profile name could be part of a Generator expression, so this won't catch all occurences.
        # Since it is hard to add an error message for genex, we don't do that here.
        elseif("${COR_PROFILE}" STREQUAL "test" OR "${COR_PROFILE}" STREQUAL "bench")
            message(FATAL_ERROR "Corrosion does not support building Rust crates with the cargo profiles"
                    " `test` or `bench`. These profiles add a hash to the output artifact name that we"
                    " cannot predict. Please consider using a custom cargo profile which inherits from the"
                    " built-in profile instead."
            )
        endif()
    endif()

    # intended to be used with foreach(... ZIP_LISTS ...), meaning
    # that the crate_types at index i of `override_crate_type_types_list` are
    # for the package_name at index i of `override_crate_type_package_name_list`.
    # It would really be nice if CMake had structs or dicts.
    unset(override_crate_type_package_name_list)
    unset(override_crate_type_types_list)
    unset(OVERRIDE_CRATE_TYPE_ARGS)
    if(DEFINED COR_OVERRIDE_CRATE_TYPE)
        string(JOIN " " usage_help
               "Each argument to OVERRIDE_CRATE_TYPE must be of the form `<package_name>=<crate_type(s)>."
               "The package_name must be a valid cargo package name and the crate_type must be "
               "a comma-seperated list with valid values being `staticlib`, `cdylib` and `bin`"
        )
        foreach(entry IN LISTS COR_OVERRIDE_CRATE_TYPE)
            string(REPLACE "=" ";" key_val_list ${entry})
            list(LENGTH key_val_list key_val_list_len)
            if(NOT key_val_list_len EQUAL "2")
                message(FATAL_ERROR "Invalid argument: `${entry}` for parameter OVERRIDE_CRATE_TYPE!\n"
                    "${usage_help}"
                )
            endif()
            list(GET key_val_list "0" package_name)
            list(GET key_val_list "1" crate_types)
            list(APPEND override_crate_type_package_name_list "${package_name}")
            list(APPEND override_crate_type_types_list "${crate_types}")
        endforeach()
        list(LENGTH override_crate_type_package_name_list num_override_packages)
        list(LENGTH override_crate_type_types_list num_override_packages2)
        if("${Rust_VERSION}" VERSION_LESS "1.64")
            message(WARNING "OVERRIDE_CRATE_TYPE requires at Rust 1.64 or newer. Ignoring the option")
        elseif(NOT num_override_packages EQUAL num_override_packages2)
            message(WARNING "Internal error while parsing OVERRIDE_CRATE_TYPE arguments.\n"
                    "Corrosion will ignore this argument and continue."
            )
        else()
            # Pass by ref: we intentionally pass the list names here!
            set(override_crate_types_arg "OVERRIDE_CRATE_TYPE_ARGS" "override_crate_type_package_name_list" "override_crate_type_types_list")
        endif()
    endif()

    if (NOT IS_ABSOLUTE "${COR_MANIFEST_PATH}")
        set(COR_MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${COR_MANIFEST_PATH})
    endif()

    set(additional_cargo_flags ${COR_FLAGS})

    if(COR_LOCKED AND NOT "--locked" IN_LIST additional_cargo_flags)
        list(APPEND additional_cargo_flags  "--locked")
    endif()
    if(COR_FROZEN AND NOT "--frozen" IN_LIST additional_cargo_flags)
        list(APPEND additional_cargo_flags  "--frozen")
    endif()

    set(imported_crates "")

    _generator_add_cargo_targets(
        MANIFEST_PATH
            "${COR_MANIFEST_PATH}"
        IMPORTED_CRATES
            imported_crates
        ${crate_allowlist}
        ${crate_types}
        ${no_linker_override}
        ${override_crate_types_arg}
    )

    # Not target props yet:
    # NO_STD
    # NO_LINKER_OVERRIDE # We could simply zero INTERFACE_CORROSION_LINKER if this is set.
    # LOCKED / FROZEN get merged into FLAGS after cargo metadata.

    # Initialize the target properties with the arguments to corrosion_import_crate.
    set_target_properties(
            ${imported_crates}
            PROPERTIES
                "${_CORR_PROP_ALL_FEATURES}" "${COR_ALL_FEATURES}"
                "${_CORR_PROP_NO_DEFAULT_FEATURES}" "${COR_NO_DEFAULT_FEATURES}"
                "${_CORR_PROP_FEATURES}" "${COR_FEATURES}"
                INTERFACE_CORROSION_CARGO_PROFILE "${COR_PROFILE}"
                INTERFACE_CORROSION_CARGO_FLAGS "${additional_cargo_flags}"
    )

    # _CORR_PROP_ENV_VARS
    if(DEFINED COR_IMPORTED_CRATES)
        set(${COR_IMPORTED_CRATES} ${imported_crates} PARENT_SCOPE)
    endif()
endfunction()

function(corrosion_set_linker target_name linker)
    if(NOT linker)
        message(FATAL_ERROR "The linker passed to `corrosion_set_linker` may not be empty")
    elseif(NOT TARGET "${target_name}")
        message(FATAL_ERROR "The target `${target_name}` does not exist.")
    endif()
    if(MSVC)
        message(WARNING "Explicitly setting the linker with the MSVC toolchain is currently not supported and ignored")
    endif()

    if(TARGET "${target_name}-static" AND NOT TARGET "${target_name}-shared")
        message(WARNING "The target ${target_name} builds a static library."
            "The linker is never invoked for a static library so specifying a linker has no effect."
        )
    endif()

    set_property(
        TARGET ${target_name}
        PROPERTY INTERFACE_CORROSION_LINKER "${linker}"
    )
endfunction()

function(corrosion_set_hostbuild target_name)
    # Configure the target to be compiled for the Host target and ignore any cross-compile configuration.
    set_property(
            TARGET ${target_name}
            PROPERTY ${_CORR_PROP_HOST_BUILD} 1
    )
endfunction()

# Add flags for rustc (RUSTFLAGS) which affect the target and all of it's Rust dependencies
#
# Additional rustflags may be passed as optional parameters after rustflag.
# Please note, that if you import multiple targets from a package or workspace, but set different
# Rustflags via this function, the Rust dependencies will have to be rebuilt when changing targets.
# Consider `corrosion_add_target_local_rustflags()` as an alternative to avoid this.
function(corrosion_add_target_rustflags target_name rustflag)
    # Additional rustflags may be passed as optional parameters after rustflag.
    set_property(
            TARGET ${target_name}
            APPEND
            PROPERTY INTERFACE_CORROSION_RUSTFLAGS ${rustflag} ${ARGN}
    )
endfunction()

# Add flags for rustc (RUSTFLAGS) which only affect the target, but none of it's (Rust) dependencies
#
# Additional rustflags may be passed as optional parameters after rustc_flag.
function(corrosion_add_target_local_rustflags target_name rustc_flag)
    # Set Rustflags via `cargo rustc` which only affect the current crate, but not dependencies.
    set_property(
            TARGET ${target_name}
            APPEND
            PROPERTY INTERFACE_CORROSION_LOCAL_RUSTFLAGS ${rustc_flag} ${ARGN}
    )
endfunction()

function(corrosion_set_env_vars target_name env_var)
    # Additional environment variables may be passed as optional parameters after env_var.
    set_property(
        TARGET ${target_name}
        APPEND
        PROPERTY ${_CORR_PROP_ENV_VARS} ${env_var} ${ARGN}
    )
endfunction()

function(corrosion_set_cargo_flags target_name)
    # corrosion_set_cargo_flags(<target_name> [<flag1> ... ])

    set_property(
            TARGET ${target_name}
            APPEND
            PROPERTY INTERFACE_CORROSION_CARGO_FLAGS ${ARGN}
    )
endfunction()

function(corrosion_set_features target_name)
    # corrosion_set_features(<target_name> [ALL_FEATURES=Bool] [NO_DEFAULT_FEATURES] [FEATURES <feature1> ... ])
    set(options NO_DEFAULT_FEATURES)
    set(one_value_args ALL_FEATURES)
    set(multi_value_args FEATURES)
    cmake_parse_arguments(
            PARSE_ARGV 1
            SET
            "${options}"
            "${one_value_args}"
            "${multi_value_args}"
    )

    if(DEFINED SET_ALL_FEATURES)
        set_property(
                TARGET ${target_name}
                PROPERTY ${_CORR_PROP_ALL_FEATURES} ${SET_ALL_FEATURES}
        )
    endif()
    if(SET_NO_DEFAULT_FEATURES)
        set_property(
                TARGET ${target_name}
                PROPERTY ${_CORR_PROP_NO_DEFAULT_FEATURES} 1
        )
    endif()
    if(SET_FEATURES)
        set_property(
                TARGET ${target_name}
                APPEND
                PROPERTY ${_CORR_PROP_FEATURES} ${SET_FEATURES}
        )
    endif()
endfunction()

function(corrosion_link_libraries target_name)
    if(TARGET "${target_name}-static")
        message(DEBUG "The target ${target_name} builds a static Rust library."
                "Calling `target_link_libraries()` instead."
        )
        target_link_libraries("${target_name}-static" INTERFACE ${ARGN})
        if(NOT TARGET "${target_name}-shared")
            # Early return, since Rust won't invoke the linker for static libraries
            return()
        endif()
    endif()
    foreach(library ${ARGN})
        set_property(
            TARGET _cargo-build_${target_name}
            APPEND
            PROPERTY CARGO_DEPS_LINKER_LANGUAGES
            $<TARGET_PROPERTY:${library},LINKER_LANGUAGE>
        )

        if (TARGET "${library}")
            # This works fine, except when compiling for ios. See https://cmake.org/pipermail/cmake/2016-March/063050.html
            # XCODE_EMIT_EFFECTIVE_PLATFORM_NAME=OFF is supposed to prevent emitting EFFECTIVE_PLATFORM_NAME, but even
            # with CMake 4.1 and the variable set to off EFFECTIVE_PLATFORM_NAME still leaks into generator expressions,
            # and is not correctly replaced at build time
            set(linker_dir "$<TARGET_LINKER_FILE_DIR:${library}>")
            # Probably should also affect other apple OSs with a simulator
            if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
                unset(platform_name)
                message(CHECK_START "corrosion_link_libraries: Attempting to replace EFFECTIVE_PLATFORM_NAME")
                if(CMAKE_OSX_SYSROOT MATCHES "iphoneos")
                    set(platform_name "-iphoneos")
                elseif(CMAKE_OSX_SYSROOT MATCHES "iphonesimulator")
                    set(platform_name "-iphonesimulator")
                else()
                    # Todo: CMAKE_OSX_SYSROOT can be not set - how do we handle that?
                    message(CHECK_FAIL "Failed to determine platform name for iOS target from sysroot ${CMAKE_OSX_SYSROOT}")
                endif()
                if(DEFINED platform_name)
                    # This is a hack to fix $EFFECTIVE_PLATFORM_NAME not expanding in TARGET_LINKER_FILE_DIR
                    set(linker_dir "$<PATH:REPLACE_FILENAME,${linker_dir},$<CONFIG>${platform_name}>")
                    message(CHECK_PASS "done")
                endif()
            endif()
            corrosion_add_target_local_rustflags(${target_name}
                "-L${linker_dir}"
                "-l$<TARGET_LINKER_FILE_BASE_NAME:${library}>"
            )
            add_dependencies(_cargo-build_${target_name} ${library})
        elseif(IS_ABSOLUTE "${library}")
            # Linking via full path (See https://doc.rust-lang.org/rustc/command-line-arguments.html#linking-modifiers-verbatim)
            corrosion_add_target_local_rustflags(${target_name} "-Clink-arg=${library}")
        else()
            # We have to assume ${library} is a non-CMake library name
            corrosion_add_target_local_rustflags(${target_name} "-l${library}")
        endif()
    endforeach()
endfunction()

#[=======================================================================[.md:
ANCHOR: corrosion-install
** EXPERIMENTAL **: This function is currently still considered experimental
  and is not officially released yet. Feedback and Suggestions are welcome.

```cmake
corrosion_install(TARGETS <target1> ... <targetN> [EXPORT <export-name>]
                  [[ARCHIVE|LIBRARY|RUNTIME|PUBLIC_HEADER]
                   [DESTINATION <dir>]
                   [PERMISSIONS <permissions...>]
                   [CONFIGURATIONS [Debug|Release|<other-configuration>]]
                  ] [...])
```
* **TARGETS**: Target or targets to install.
* **EXPORT**: Creates an export that can be installed with `install(EXPORT)`. <export-name> must be globally unique.
             Also creates a file at ${CMAKE_BINARY_DIR}/corrosion/<export-name>Corrosion.cmake that must be included in the installed config file.
* **ARCHIVE**/**LIBRARY**/**RUNTIME**/PUBLIC_HEADER: Designates that the following settings only apply to that specific type of object.
* **DESTINATION**: The subdirectory within the CMAKE_INSTALL_PREFIX that a specific object should be placed. Defaults to values from GNUInstallDirs.
* **PERMISSIONS**: The permissions of files copied into the install prefix.

Any `PUBLIC` or `INTERFACE` [file sets] will be installed.

[file sets]: https://cmake.org/cmake/help/latest/command/target_sources.html#file-sets

ANCHOR_END: corrosion-install
#]=======================================================================]
function(corrosion_install)
    # Default install dirs
    include(GNUInstallDirs)

    # Parse arguments to corrosion_install
    list(GET ARGN 0 INSTALL_TYPE)
    list(REMOVE_AT ARGN 0)

    # The different install types that are supported. Some targets may have more than one of these
    # types. For example, on Windows, a shared library will have both an ARCHIVE component and a
    # RUNTIME component.
    set(INSTALL_TARGET_TYPES ARCHIVE LIBRARY RUNTIME PRIVATE_HEADER PUBLIC_HEADER)

    # Arguments to each install target type
    set(OPTIONS)
    set(ONE_VALUE_ARGS DESTINATION)
    set(MULTI_VALUE_ARGS PERMISSIONS CONFIGURATIONS)
    set(TARGET_ARGS ${OPTIONS} ${ONE_VALUE_ARGS} ${MULTI_VALUE_ARGS})

    if (INSTALL_TYPE STREQUAL "TARGETS")
        # Extract targets
        set(INSTALL_TARGETS)
        list(LENGTH ARGN ARGN_LENGTH)
        set(DELIMITERS EXPORT ${INSTALL_TARGET_TYPES} ${TARGET_ARGS})
        while(ARGN_LENGTH)
            # If we hit another keyword, stop - we've found all the targets
            list(GET ARGN 0 FRONT)
            if (FRONT IN_LIST DELIMITERS)
                break()
            endif()

            list(APPEND INSTALL_TARGETS ${FRONT})
            list(REMOVE_AT ARGN 0)

            # Update ARGN_LENGTH
            list(LENGTH ARGN ARGN_LENGTH)
        endwhile()

        # Check if there are any args left before proceeding
        list(LENGTH ARGN ARGN_LENGTH)
        if (ARGN_LENGTH)
            list(GET ARGN 0 FRONT)
            if (FRONT STREQUAL "EXPORT")
                list(REMOVE_AT ARGN 0) # Pop "EXPORT"

                list(GET ARGN 0 EXPORT_NAME)
                list(REMOVE_AT ARGN 0) # Pop <export-name>
                set(EXTRA_TARGETS_EXPORT_NAME ${EXPORT_NAME}Corrosion.cmake)
                set(EXPORT_NAME EXPORT ${EXPORT_NAME})
                set(EXPORT_FILE_PATH "${CMAKE_BINARY_DIR}/corrosion/${EXTRA_TARGETS_EXPORT_NAME}")
                # Remove first, since otherwise we will append to the file on every reconfigure.
                # Assumes that the corrosion_install will only be called once for a given EXPORT_NAME.
                file(REMOVE "${EXPORT_FILE_PATH}")
            endif()
        else()
            # Prevent variable set in user code from interfering
            set(EXPORT_NAME)
        endif()

        # Loop over all arguments and get options for each install target type
        list(LENGTH ARGN ARGN_LENGTH)
        while(ARGN_LENGTH)
            # Check if we're dealing with arguments for a specific install target type, or with
            # default options for all target types.
            list(GET ARGN 0 FRONT)
            if (FRONT IN_LIST INSTALL_TARGET_TYPES)
                set(INSTALL_TARGET_TYPE ${FRONT})
                list(REMOVE_AT ARGN 0)
            else()
                set(INSTALL_TARGET_TYPE DEFAULT)
            endif()

            # Gather the arguments to this install type
            set(ARGS)
            list(LENGTH ARGN ARGN_LENGTH)
            while(ARGN_LENGTH)
                # If the next keyword is an install target type, then break - arguments have been
                # gathered.
                list(GET ARGN 0 FRONT)
                if (FRONT IN_LIST INSTALL_TARGET_TYPES)
                    break()
                endif()

                list(APPEND ARGS ${FRONT})
                list(REMOVE_AT ARGN 0)

                list(LENGTH ARGN ARGN_LENGTH)
            endwhile()

            # Parse the arguments and register the file install
            cmake_parse_arguments(
                COR "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGS})

            if (COR_DESTINATION)
                set(COR_INSTALL_${INSTALL_TARGET_TYPE}_DESTINATION ${COR_DESTINATION})
            endif()

            if (COR_PERMISSIONS)
                set(COR_INSTALL_${INSTALL_TARGET_TYPE}_PERMISSIONS ${COR_PERMISSIONS})
            endif()

            if (COR_CONFIGURATIONS)
                set(COR_INSTALL_${INSTALL_TARGET_TYPE}_CONFIGURATIONS ${COR_CONFIGURATIONS})
            endif()

            # Update ARG_LENGTH
            list(LENGTH ARGN ARGN_LENGTH)
        endwhile()

        # Default permissions for all files
        set(DEFAULT_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)

        # Loop through each install target and register file installations
        foreach(INSTALL_TARGET ${INSTALL_TARGETS})
            if(NOT TARGET ${INSTALL_TARGET})
                message(FATAL_ERROR "Install target ${INSTALL_TARGET} is not a valid target")
            endif()
            # Don't both implementing target type differentiation using generator expressions since
            # TYPE cannot change after target creation
            get_property(
                TARGET_TYPE
                TARGET ${INSTALL_TARGET} PROPERTY TYPE
            )

            # Install executable files first
            if (TARGET_TYPE STREQUAL "EXECUTABLE")
                if (DEFINED COR_INSTALL_RUNTIME_DESTINATION)
                    set(DESTINATION ${COR_INSTALL_RUNTIME_DESTINATION})
                elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION)
                    set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION})
                else()
                    set(DESTINATION ${CMAKE_INSTALL_BINDIR})
                endif()

                if (DEFINED COR_INSTALL_RUNTIME_PERMISSIONS)
                    set(PERMISSIONS ${COR_INSTALL_RUNTIME_PERMISSIONS})
                elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
                    set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
                else()
                    set(
                        PERMISSIONS
                        ${DEFAULT_PERMISSIONS} OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
                endif()

                if (DEFINED COR_INSTALL_RUNTIME_CONFIGURATIONS)
                    set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_RUNTIME_CONFIGURATIONS})
                elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
                    set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
                else()
                    set(CONFIGURATIONS)
                endif()

                install(
                    FILES $<TARGET_FILE:${INSTALL_TARGET}>
                    DESTINATION ${DESTINATION}
                    PERMISSIONS ${PERMISSIONS}
                    ${CONFIGURATIONS}
                )
            elseif(TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
                if(TARGET ${INSTALL_TARGET}-static)
                    if (DEFINED COR_INSTALL_ARCHIVE_DESTINATION)
                        set(DESTINATION ${COR_INSTALL_ARCHIVE_DESTINATION})
                    elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION)
                        set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION})
                    else()
                        set(DESTINATION ${CMAKE_INSTALL_LIBDIR})
                    endif()

                    if (DEFINED COR_INSTALL_ARCHIVE_PERMISSIONS)
                        set(PERMISSIONS ${COR_INSTALL_ARCHIVE_PERMISSIONS})
                    elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
                        set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
                    else()
                        set(PERMISSIONS ${DEFAULT_PERMISSIONS})
                    endif()

                    if (DEFINED COR_INSTALL_ARCHIVE_CONFIGURATIONS)
                        set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_ARCHIVE_CONFIGURATIONS})
                    elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
                        set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
                    else()
                        set(CONFIGURATIONS)
                    endif()

                    install(
                            FILES $<TARGET_PROPERTY:${INSTALL_TARGET}-static,IMPORTED_LOCATION>
                            DESTINATION ${DESTINATION}
                            PERMISSIONS ${PERMISSIONS}
                            ${CONFIGURATIONS}
                    )

                    if(EXPORT_NAME)
                        get_target_property(COR_FILE_NAME ${INSTALL_TARGET}-static COR_FILE_NAME)
                        file(APPEND "${EXPORT_FILE_PATH}"
"
add_library(${INSTALL_TARGET}-static STATIC IMPORTED)
set_target_properties(${INSTALL_TARGET}-static
    PROPERTIES
    IMPORTED_LOCATION \"\${PACKAGE_PREFIX_DIR}/${DESTINATION}/${COR_FILE_NAME}\"
)
"
                        )
                    endif()
                endif()

                if(TARGET ${INSTALL_TARGET}-shared)
                    if (DEFINED COR_INSTALL_LIBRARY_DESTINATION)
                        set(DESTINATION ${COR_INSTALL_LIBRARY_DESTINATION})
                    elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION)
                        set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION})
                    else()
                        set(DESTINATION ${CMAKE_INSTALL_LIBDIR})
                    endif()

                    if (DEFINED COR_INSTALL_LIBRARY_PERMISSIONS)
                        set(PERMISSIONS ${COR_INSTALL_LIBRARY_PERMISSIONS})
                    elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
                        set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
                    else()
                        set(
                            PERMISSIONS
                            ${DEFAULT_PERMISSIONS} OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE
                        )
                    endif()

                    if (DEFINED COR_INSTALL_LIBRARY_CONFIGURATIONS)
                        set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_LIBRARY_CONFIGURATIONS})
                    elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
                        set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
                    else()
                        set(CONFIGURATIONS)
                    endif()

                    install(
                            IMPORTED_RUNTIME_ARTIFACTS ${INSTALL_TARGET}-shared
                            PERMISSIONS ${PERMISSIONS}
                            DESTINATION ${DESTINATION}
                            ${CONFIGURATIONS}
                    )

                    if(EXPORT_NAME)
                        get_target_property(COR_FILE_NAME ${INSTALL_TARGET}-shared COR_FILE_NAME)
                        file(APPEND "${EXPORT_FILE_PATH}"
"
add_library(${INSTALL_TARGET}-shared SHARED IMPORTED)
set_target_properties(${INSTALL_TARGET}-shared
    PROPERTIES
    IMPORTED_LOCATION \"\${PACKAGE_PREFIX_DIR}/${DESTINATION}/${COR_FILE_NAME}\"
)
"
                            )

                            get_target_property(COR_IMPLIB_FILE_NAME ${INSTALL_TARGET}-shared COR_IMPLIB_FILE_NAME)
                            if (NOT COR_IMPLIB_FILE_NAME MATCHES .*-NOTFOUND)
                                file(APPEND "${EXPORT_FILE_PATH}"
"
set_target_properties(${INSTALL_TARGET}-shared
    PROPERTIES
    IMPORTED_IMPLIB \"\${PACKAGE_PREFIX_DIR}/${DESTINATION}/${COR_IMPLIB_FILE_NAME}\"
)"
                                )
                            endif()
                    endif()
                endif()
            else()
                message(FATAL_ERROR "Unknown target type ${TARGET_TYPE} for install target ${INSTALL_TARGET}")
            endif()

            # Executables can also have export tables, so they _might_ also need header files
            if (DEFINED COR_INSTALL_PUBLIC_HEADER_DESTINATION)
                set(DESTINATION ${COR_INSTALL_PUBLIC_HEADER_DESTINATION})
            elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION)
                set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION})
            else()
                set(DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
            endif()

            if (DEFINED COR_INSTALL_PUBLIC_HEADER_PERMISSIONS)
                set(PERMISSIONS ${COR_INSTALL_PUBLIC_HEADER_PERMISSIONS})
            elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
                set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
            else()
                # Directories need OWNER_EXECUTE in order to be deletable by owner
                set(PERMISSIONS ${DEFAULT_PERMISSIONS} OWNER_EXECUTE)
            endif()

            if (DEFINED COR_INSTALL_PUBLIC_HEADER_CONFIGURATIONS)
                set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_PUBLIC_HEADER_CONFIGURATIONS})
            elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
                set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
            else()
                set(CONFIGURATIONS)
            endif()

            get_target_property(FILE_SET ${INSTALL_TARGET} INTERFACE_HEADER_SETS)
            if(NOT FILE_SET OR FILE_SET MATCHES .*-NOTFOUND)
                set(TARGET_HAS_FILE_SET FALSE)
            else()
                set(TARGET_HAS_FILE_SET TRUE)
            endif()

            if(NOT TARGET_HAS_FILE_SET)
                if(EXPORT_NAME)
                    # We still need to generate a EXPORT but we can't do that with install(DIRECTORY)
                    install(TARGETS ${INSTALL_TARGET} ${EXPORT_NAME})
                endif()

                set(PUBLIC_HEADER_PROPERTIES INCLUDE_DIRECTORIES PUBLIC_INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES)
                foreach(PUBLIC_HEADER_PROPERTY ${PUBLIC_HEADER_PROPERTIES})
                    get_target_property(PUBLIC_HEADER ${INSTALL_TARGET} ${PUBLIC_HEADER_PROPERTY})

                    if(NOT PUBLIC_HEADER MATCHES .*-NOTFOUND)
                        foreach(INCLUDE_DIRECTORY ${PUBLIC_HEADER})
                            install(
                                    DIRECTORY ${INCLUDE_DIRECTORY}
                                    DESTINATION .
                                    FILE_PERMISSIONS ${PERMISSIONS}
                                    DIRECTORY_PERMISSIONS ${PERMISSIONS}
                                    ${CONFIGURATIONS}
                            )
                        endforeach()
                    endif()
                endforeach()
            else()
                install(
                        TARGETS ${INSTALL_TARGET}
                        ${EXPORT_NAME}
                        FILE_SET HEADERS
                        DESTINATION ${DESTINATION}
                        PERMISSIONS ${PERMISSIONS}
                        ${CONFIGURATIONS}
                )
            endif()
        endforeach()

    elseif(INSTALL_TYPE STREQUAL "EXPORT")
        message(FATAL_ERROR "install(EXPORT ...) not yet implemented")
    else()
        message(FATAL_ERROR "Unknown arg: ${INSTALL_TYPE}")
    endif()
endfunction()

function(_corrosion_check_cxx_version_helper manifest_dir cxx_name out_required_version)
    execute_process(COMMAND ${CMAKE_COMMAND} -E env
                    "CARGO_BUILD_RUSTC=${_CORROSION_RUSTC}"
                    ${_CORROSION_CARGO} tree -i "${cxx_name}"
                    # Usage of `cxx` could be gated behind a feature. Features can use Generator expressions,
                    # so we can't really know what features we will enable when building at this point.
                    # Features should be additive though, so simply enabling all-features should work for
                    # dependency resolution.
                    --all-features
                    --target all
                    --depth=0
                    WORKING_DIRECTORY "${manifest_dir}"
                    RESULT_VARIABLE cxx_version_result
                    OUTPUT_VARIABLE cxx_version_output
                    ERROR_VARIABLE cxx_version_error
    )
    if(NOT "${cxx_version_result}" EQUAL "0")
        message(DEBUG "`cargo tree -i ${cxx_name}` returned an error: ${cxx_version_error}")
        set("${out_required_version}" "${cxx_name}-NOTFOUND" PARENT_SCOPE)
        return()
    endif()
    if(cxx_version_output MATCHES "${cxx_name} v([0-9]+.[0-9]+.[0-9]+)")
        set("${out_required_version}" "${CMAKE_MATCH_1}" PARENT_SCOPE)
    else()
        message(DEBUG "Failed to parse `cargo tree -i ${cxx_name}` output: ${cxx_version_output}")
        set("${out_required_version}" "${cxx_name}-NOTFOUND" PARENT_SCOPE)
    endif()
endfunction()

function(_corrosion_check_cxx_version manifest_dir out_required_version)
    # cxxbridge-cmd is known to be available in lockfiles since cxx 1.0.131.
    # We include `cxx` as a fallback to support older versions too. `cxxbridge` should always
    # be exactly the same version as `cxx`, so falling back to `cxx` version should not cause issues.
    foreach(cxxbridge_name cxxbridge-cmd cxx)
        unset(cxx_required_version)
        _corrosion_check_cxx_version_helper("${manifest_dir}"
                                            "${cxxbridge_name}"
                                            cxx_required_version)
        if(cxx_required_version)
            set("${out_required_version}" "${cxx_required_version}" PARENT_SCOPE)
            break()
        else()
            set("${out_required_version}" "cxx-NOTFOUND" PARENT_SCOPE)
        endif()
    endforeach()

endfunction()



#[=======================================================================[.md:
** EXPERIMENTAL **: This function is currently still considered experimental
  and is not officially released yet. Feedback and Suggestions are welcome.

ANCHOR: corrosion_add_cxxbridge

```cmake
corrosion_add_cxxbridge(cxx_target
        CRATE <imported_target_name>
        REGEN_TARGET <regen_target_name>
        [FILES <file1.rs> <file2.rs>]
)
```

Adds build-rules to create C++ bindings using the [cxx] crate.

### Arguments:
* `cxxtarget`: Name of the C++ library target for the bindings, which corrosion will create.
* **FILES**: Input Rust source file containing #[cxx::bridge].
* **CRATE**: Name of an imported Rust target. Note: Parameter may be renamed before release
* **REGEN_TARGET**: Name of a custom target that will regenerate the cxx bindings **without** recompiling. Note: Parameter may be renamed before release

#### Currently missing arguments

The following arguments to cxxbridge **currently** have no way to be passed by the user:
- `--cfg`
- `--cxx-impl-annotations`
- `--include`

The created rules approximately do the following:
- Check which version of `cxx` the Rust crate specified by the `CRATE` argument depends on.
- Check if the exact same version of `cxxbridge-cmd` is installed (available in `PATH`)
- If not, create a rule to build the exact same version of `cxxbridge-cmd`.
- Create rules to run `cxxbridge` and generate
  - The `rust/cxx.h` header
  - A header and source file for each of the files specified in `FILES`
- The generated sources (and header include directories) are added to the `cxxtarget` CMake
  library target.

### Limitations

We currently require the `CRATE` argument to be a target imported by Corrosion, however,
Corrosion does not import `rlib` only libraries. As a workaround users can add
`staticlib` to their list of crate kinds. In the future this may be solved more properly,
by either adding an option to also import Rlib targets (without build rules) or by
adding a `MANIFEST_PATH` argument to this function, specifying where the crate is.

### Contributing

Specifically some more realistic test / demo projects and feedback about limitations would be
welcome.

[cxx]: https://github.com/dtolnay/cxx

ANCHOR_END: corrosion_add_cxxbridge
#]=======================================================================]
function(corrosion_add_cxxbridge cxx_target)
    set(OPTIONS)
    set(ONE_VALUE_KEYWORDS CRATE REGEN_TARGET)
    set(MULTI_VALUE_KEYWORDS FILES)
    cmake_parse_arguments(PARSE_ARGV 1 _arg "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")

    set(required_keywords CRATE FILES)
    foreach(keyword ${required_keywords})
        if(NOT DEFINED "_arg_${keyword}")
            message(FATAL_ERROR "Missing required parameter `${keyword}`.")
        elseif("${_arg_${keyword}}" STREQUAL "")
            message(FATAL_ERROR "Required parameter `${keyword}` may not be set to an empty string.")
        endif()
    endforeach()

    if(DEFINED _arg_UNPARSED_ARGUMENTS)
        message(AUTHOR_WARNING "corrosion_add_cxxbridge was called with the following unknown arguments: "
                "`${_arg_UNPARSED_ARGUMENTS}`\n"
                "Unknown arguments will be ignored."
        )
    endif()

    get_target_property(manifest_path "${_arg_CRATE}" INTERFACE_COR_PACKAGE_MANIFEST_PATH)

    if(NOT EXISTS "${manifest_path}")
        message(FATAL_ERROR "Internal error: No package manifest found at ${manifest_path}")
    endif()

    get_filename_component(manifest_dir ${manifest_path} DIRECTORY)

    _corrosion_check_cxx_version("${manifest_dir}" cxx_required_version)

    if(NOT cxx_required_version)
        message(FATAL_ERROR
                "Failed to find a dependency on `cxxbridge-cmd` / `cxx` for crate ${_arg_CRATE}"
        )
    endif()

    # First check if a suitable version of cxxbridge is installed
    find_program(INSTALLED_CXXBRIDGE cxxbridge PATHS "$ENV{HOME}/.cargo/bin/")
    mark_as_advanced(INSTALLED_CXXBRIDGE)
    if(INSTALLED_CXXBRIDGE)
        execute_process(COMMAND ${INSTALLED_CXXBRIDGE} --version OUTPUT_VARIABLE cxxbridge_version_output)
        if(cxxbridge_version_output MATCHES "cxxbridge ([0-9]+.[0-9]+.[0-9]+)")
            set(cxxbridge_version "${CMAKE_MATCH_1}")
        else()
            set(cxxbridge_version "")
        endif()
    endif()

    set(cxxbridge "")
    if(cxxbridge_version)
        if(cxxbridge_version VERSION_EQUAL cxx_required_version)
            set(cxxbridge "${INSTALLED_CXXBRIDGE}")
            if(NOT TARGET "cxxbridge_v${cxx_required_version}")
                # Add an empty target.
                add_custom_target("cxxbridge_v${cxx_required_version}"
                    )
            endif()
        endif()
    endif()

    # No suitable version of cxxbridge was installed, so use custom target to build correct version.
    if(NOT cxxbridge)
        if(NOT TARGET "cxxbridge_v${cxx_required_version}")
            unset(executable_postfix)
            if(Rust_CARGO_HOST_OS STREQUAL "windows")
                set(executable_postfix ".exe")
            endif()

            add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}/bin/cxxbridge${executable_postfix}"
                COMMAND
                ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}"
                COMMAND
                    ${CMAKE_COMMAND} -E env
                        "CARGO_BUILD_RUSTC=$CACHE{CORROSION_TOOLS_RUSTC}"
                    $CACHE{CORROSION_TOOLS_CARGO} install
                    cxxbridge-cmd
                    --version "${cxx_required_version}"
                    --locked
                    --root "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}"
                    --quiet
                    # todo: use --target-dir to potentially reuse artifacts
                COMMENT "Building cxxbridge (version ${cxx_required_version}) with Rust toolchain $CACHE{CORROSION_TOOLS_RUST_TOOLCHAIN}"
                )
            add_custom_target("cxxbridge_v${cxx_required_version}"
                DEPENDS "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}/bin/cxxbridge${executable_postfix}"
                )
        endif()
        set(cxxbridge "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}/bin/cxxbridge${executable_postfix}")
    endif()


    # The generated folder structure will be of the following form
    #
    #    CMAKE_CURRENT_BINARY_DIR
    #        corrosion_generated
    #            cxxbridge
    #                <cxx_target>
    #                    include
    #                        <cxx_target>
    #                            <headers>
    #                        rust
    #                            cxx.h
    #                    src
    #                        <sourcefiles>
    #            cbindgen
    #                ...
    #            other
    #                ...

    set(corrosion_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/corrosion_generated")
    set(generated_dir "${corrosion_generated_dir}/cxxbridge/${cxx_target}")
    set(header_placement_dir "${generated_dir}/include/${cxx_target}")
    set(source_placement_dir "${generated_dir}/src")

    add_library(${cxx_target} STATIC)
    target_include_directories(${cxx_target}
        PUBLIC
            $<BUILD_INTERFACE:${generated_dir}/include>
            $<INSTALL_INTERFACE:include>
    )

    # cxx generated code is using c++11 features in headers, so propagate c++11 as minimal requirement
    target_compile_features(${cxx_target} PUBLIC cxx_std_11)

    if (TARGET "${_arg_CRATE}-static")
        target_link_libraries(${cxx_target} PRIVATE "${_arg_CRATE}-static")
        target_link_libraries("${_arg_CRATE}-static" INTERFACE ${cxx_target})
    endif()
    if (TARGET "${_arg_CRATE}-shared")
        target_link_libraries(${cxx_target} PRIVATE "${_arg_CRATE}-shared")
        target_link_libraries("${_arg_CRATE}-shared" INTERFACE ${cxx_target})
    endif()

    file(MAKE_DIRECTORY "${generated_dir}/include/rust")
    add_custom_command(
            OUTPUT "${generated_dir}/include/rust/cxx.h"
            COMMAND
            ${cxxbridge} --header --output "${generated_dir}/include/rust/cxx.h"
            DEPENDS "cxxbridge_v${cxx_required_version}"
            COMMENT "Generating rust/cxx.h header"
    )

    set(GENERATED_SOURCES "")
    set(GENERATED_HEADERS "${generated_dir}/include/rust/cxx.h")

    foreach(filepath ${_arg_FILES})
        get_filename_component(filename ${filepath} NAME_WE)
        get_filename_component(directory ${filepath} DIRECTORY)
        set(directory_component "")
        if(directory)
            set(directory_component "${directory}/")
        endif()
        # todo: convert potentially absolute paths to relative paths..
        set(cxx_header ${directory_component}${filename}.h)
        set(cxx_source ${directory_component}${filename}.cpp)

        # todo: not all projects may use the `src` directory.
        set(rust_source_path "${manifest_dir}/src/${filepath}")

        file(MAKE_DIRECTORY "${header_placement_dir}/${directory}" "${source_placement_dir}/${directory}")

        add_custom_command(
            OUTPUT
            "${header_placement_dir}/${cxx_header}"
            "${source_placement_dir}/${cxx_source}"
            COMMAND
                ${cxxbridge} ${rust_source_path} --header --output "${header_placement_dir}/${cxx_header}"
            COMMAND
                ${cxxbridge} ${rust_source_path}
                    --output "${source_placement_dir}/${cxx_source}"
                    --include "${cxx_target}/${cxx_header}"
            DEPENDS "cxxbridge_v${cxx_required_version}" "${rust_source_path}"
            COMMENT "Generating cxx bindings for crate ${_arg_CRATE} and file src/${filepath}"
        )

        list(APPEND GENERATED_SOURCES "${source_placement_dir}/${cxx_source}")
        list(APPEND GENERATED_HEADERS "${header_placement_dir}/${cxx_header}")
    endforeach()
    target_sources(${cxx_target} PRIVATE ${GENERATED_SOURCES})
    # Make sure to export the headers with PUBLIC.
    # This ensures that any target that depends on cxx_target also has these files as a dependency
    # CMake will then make sure to generate the files before building either target, which is important
    # in the presence of circular dependencies
    target_sources(${cxx_target} PUBLIC ${GENERATED_HEADERS})

    if(DEFINED _arg_REGEN_TARGET)
        # Add only the headers to the regen target, as the sources are actually not needed
        # For the IDE to pick everything up
        add_custom_target(${_arg_REGEN_TARGET}
            DEPENDS ${GENERATED_HEADERS}
            COMMENT "Generated cxx bindings for crate ${_arg_CRATE}")
    endif()

endfunction()

#[=======================================================================[.md:
ANCHOR: corrosion_cbindgen

A helper function which uses [cbindgen] to generate C/C++ bindings for a Rust crate.
If `cbindgen` is not in `PATH` the helper function will automatically try to download
`cbindgen` and place the built binary into `CMAKE_BINARY_DIR`. The binary is shared
between multiple invocations of this function.

The function comes with two different signatures. It's recommended to use the `TARGET` based signature when possible.

### Auto mode (With a Rust target imported by corrosion)
```cmake
corrosion_experimental_cbindgen(
        TARGET <imported_target_name>
        HEADER_NAME <output_header_name>
        [CBINDGEN_VERSION <version>]
        [FLAGS <flag1> ... <flagN>]
)
```

### Auto-mode specific Arguments


* **TARGET**: The name of an imported Rust library target, for which bindings should be generated.
              If the target is not imported by Corrosion, because the crate only produces an
              `rlib`, you can instead use the second signature and manually pass `MANIFEST_DIRECTORY`,
              `CARGO_PACKAGE` and `BINDINGS_TARGET`

### Manual mode (Without a Rust target imported by corrosion)
```cmake
corrosion_experimental_cbindgen(
        MANIFEST_DIRECTORY <package_manifest_directory>
        CARGO_PACKAGE <package_name>
        BINDINGS_TARGET <cmake_library>
        [TARGET_TRIPLE <rust_target_triple>]
        HEADER_NAME <output_header_name>
        [CBINDGEN_VERSION <version>]
        [FLAGS <flag1> ... <flagN>]
)
```

### Manual-mode specific Arguments

* **MANIFEST_DIRECTORY**: Manual mode only.
    Directory of the package defining the library crate bindings should be generated for.
    If you want to avoid specifying `MANIFEST_DIRECTORY` you could add a `staticlib` target to your package
    manifest as a workaround to make corrosion import the crate.

* **CARGO_PACKAGE**: Manual mode only.
    The name of the cargo package that bindings should be generated for.
    Note: This corresponds to the `cbindgen` `--crate` option, which actually wants a package name.

* **BINDINGS_TARGET**: Manual mode only.
    Name of an `INTERFACE` CMake target that the generated bindings should be attached to.
    In auto mode, the generated headers will be attached to the imported rust CMake crate,
    and corrosion will take care of adding the necessary build dependencies.
    In manual mode, this target likely doesn't exist, so the user needs to specify an INTERFACE CMake
    target, which the header files should be attached to. The user must create this target themselves and
    ensure to add any necessary dependencies (e.g. via `add_dependencies()`) to ensure that consumers of the
    `INTERFACE` library are not linked before the Rust library has been built.

* **TARGET_TRIPLE**: Manual mode only.
    Rust target triple (e.g. `x86_64-unknown-linux-gnu`) that cbindgen should use when generating the bindings.
    Defaults to target triple that corrosion was confiured to compile for.

### Common Arguments

* **HEADER_NAME**: The name of the generated header file. This will be the name which you include in your C/C++ code
                    (e.g. `#include "myproject/myheader.h" if you specify `HEADER_NAME "myproject/myheader.h"`.
* **CBINDGEN_VERSION**: Version requirement for cbindgen. Exact semantics to be specified. Currently not implemented.
* **FLAGS**: Arbitrary other flags for `cbindgen`. Run `cbindgen --help` to see the possible flags.

[cbindgen]: https://github.com/mozilla/cbindgen

### Current limitations

- Cbindgens (optional) macro expansion feature internally actually builds the crate / runs the build script.
  For this to work as expected in all cases, we probably need to set all the same environment variables
  as when corrosion builds the crate. However the crate is a **library**, so we would need to figure out which
  target builds it - and if there are multiple, potentially generate bindings per-target?
  Alternatively we could add support of setting some environment variables on rlibs, and pulling that
  information in when building the actual corrosion targets
  Alternatively we could restrict corrosions support of this feature to actual imported staticlib/cdylib targets.
ANCHOR_END: corrosion_cbindgen
#]=======================================================================]
function(corrosion_experimental_cbindgen)
    set(OPTIONS "")
    set(ONE_VALUE_KEYWORDS
            TARGET
            MANIFEST_DIRECTORY
            CARGO_PACKAGE
            BINDINGS_TARGET
            TARGET_TRIPLE
            HEADER_NAME
            CBINDGEN_VERSION
    )
    set(MULTI_VALUE_KEYWORDS "FLAGS")
    cmake_parse_arguments(PARSE_ARGV 0 CCN "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")

    set(required_keywords HEADER_NAME)
    foreach(keyword ${required_keywords})
        if(NOT DEFINED "CCN_${keyword}")
            message(FATAL_ERROR "Missing required parameter `${keyword}`.")
        elseif("${CCN_${keyword}}" STREQUAL "")
            message(FATAL_ERROR "Required parameter `${keyword}` may not be set to an empty string.")
        endif()
    endforeach()
    if(NOT (DEFINED CCN_TARGET
            OR (DEFINED CCN_MANIFEST_DIRECTORY AND DEFINED CCN_BINDINGS_TARGET
                AND DEFINED CCN_BINDINGS_TARGET)
            )
    )
        message(FATAL_ERROR "Unknown signature for corrosion_experimental_cbindgen.\n"
                "Either the `TARGET` or the `MANIFEST_DIRECTORY` based signature must be chosen.\n"
                "Please view the documentation for details on the function signature.\n"
                "Passed arguments where: `${ARGV}`"
        )
    endif()

    if(DEFINED CCN_UNPARSED_ARGUMENTS)
        message(AUTHOR_WARNING "corrosion_experimental_cbindgen was called with the following unknown arguments: "
                "`${CCN_UNPARSED_ARGUMENTS}`\n"
                "Unknown arguments will be ignored."
        )
    endif()
    unset(package_manifest_dir)


    if(TARGET "${CCN_TARGET}")
        set(cbindgen_bindings_target "${CCN_TARGET}")
        set(hostbuild_override "$<BOOL:$<TARGET_PROPERTY:${CCN_TARGET},${_CORR_PROP_HOST_BUILD}>>")
        set(cbindgen_target_triple "$<IF:${hostbuild_override},${_CORROSION_RUST_CARGO_HOST_TARGET},${_CORROSION_RUST_CARGO_TARGET}>")

        get_target_property(package_manifest_path "${CCN_TARGET}" INTERFACE_COR_PACKAGE_MANIFEST_PATH)
        if(NOT EXISTS "${package_manifest_path}")
            message(FATAL_ERROR "Internal error: No package manifest found at ${package_manifest_path}")
        endif()
        get_filename_component(package_manifest_dir "${package_manifest_path}" DIRECTORY)
        get_target_property(rust_cargo_package "${CCN_TARGET}" COR_CARGO_PACKAGE_NAME )
        if(NOT rust_cargo_package)
            message(FATAL_ERROR "Internal Error: Could not determine cargo package name for cbindgen. ")
        endif()
        # todo: as an optimization we could cache the cargo metadata output (but --no-deps makes that slightly more complicated)
    else()
        if(NOT DEFINED CCN_MANIFEST_DIRECTORY)
            message(FATAL_ERROR
                "Internal error: There should have been a fatal error already if neither TARGET or "
                    "MANIFEST_DIRECTORY are specfied.")
        endif()
        cmake_path(ABSOLUTE_PATH CCN_MANIFEST_DIRECTORY NORMALIZE OUTPUT_VARIABLE package_manifest_dir)
        if(DEFINED CCN_TARGET_TRIPLE)
            set(cbindgen_target_triple "${CCN_TARGET_TRIPLE}")
        else()
            set(cbindgen_target_triple "${Rust_CARGO_TARGET}")
        endif()
        set(rust_cargo_package "${CCN_CARGO_PACKAGE}")
        set(cbindgen_bindings_target "${CCN_BINDINGS_TARGET}")
        get_target_property(type "${cbindgen_bindings_target}" TYPE)
        if(NOT ${type} STREQUAL "INTERFACE_LIBRARY")
            message(AUTHOR_WARNING "The CMake target for the cbindgen generated files is expected to be"
                " an `INTERFACE` library, but was `${type}` instead."
            )
        endif()
    endif()

    message(STATUS "Using package `${rust_cargo_package}` as crate for cbindgen")

    set(output_header_name "${CCN_HEADER_NAME}")

    find_program(installed_cbindgen cbindgen)

    # Install the newest cbindgen version into our build tree.
    if(installed_cbindgen)
        set(cbindgen "${installed_cbindgen}")
    else()
        set(local_cbindgen_install_dir "${CMAKE_BINARY_DIR}/corrosion/cbindgen")
        unset(executable_postfix)
        if(Rust_CARGO_HOST_OS STREQUAL "windows")
            set(executable_postfix ".exe")
        endif()
        set(cbindgen "${local_cbindgen_install_dir}/bin/cbindgen${executable_postfix}")

        if(NOT TARGET "_corrosion_cbindgen")
            file(MAKE_DIRECTORY "${local_cbindgen_install_dir}")

            add_custom_command(OUTPUT "${cbindgen}"
                COMMAND ${CMAKE_COMMAND}
                -E env
                "CARGO_BUILD_RUSTC=$CACHE{CORROSION_TOOLS_RUSTC}"
                $CACHE{CORROSION_TOOLS_CARGO} install
                    cbindgen
                    --locked
                    --root "${local_cbindgen_install_dir}"
                    ${_CORROSION_QUIET_OUTPUT_FLAG}
                COMMENT "Building cbindgen with Rust toolchain $CACHE{CORROSION_TOOLS_RUST_TOOLCHAIN}"
                VERBATIM
                )
            add_custom_target("_corrosion_cbindgen"
                DEPENDS "${cbindgen}"
                )
        endif()
    endif()

    set(corrosion_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/corrosion_generated")
    set(generated_dir "${corrosion_generated_dir}/cbindgen/${cbindgen_bindings_target}")
    set(header_placement_dir "${generated_dir}/include")
    set(depfile_placement_dir "${generated_dir}/depfile")
    set(generated_depfile "${depfile_placement_dir}/${output_header_name}.d")
    set(generated_header "${header_placement_dir}/${output_header_name}")

    if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.23")
        target_sources(${cbindgen_bindings_target}
            INTERFACE
            FILE_SET HEADERS
            BASE_DIRS "${header_placement_dir}"
            FILES "${header_placement_dir}/${output_header_name}"
        )
    else()
        # Note: not clear to me how install would best work before CMake 3.23
        target_include_directories(${cbindgen_bindings_target}
            INTERFACE
            $<BUILD_INTERFACE:${header_placement_dir}>
            $<INSTALL_INTERFACE:include>
            )
    endif()

    # This may be different from $header_placement_dir since the user specified HEADER_NAME may contain
    # relative directories.
    get_filename_component(generated_header_dir "${generated_header}" DIRECTORY)
    file(MAKE_DIRECTORY "${generated_header_dir}")

    unset(depfile_cbindgen_arg)
    get_filename_component(generated_depfile_dir "${generated_depfile}" DIRECTORY)
    file(MAKE_DIRECTORY "${generated_depfile_dir}")
    set(depfile_cbindgen_arg "--depfile=${generated_depfile}")

    add_custom_command(
        OUTPUT
        "${generated_header}"
        COMMAND
        "${CMAKE_COMMAND}" -E env
            TARGET="${cbindgen_target_triple}"
            # cbindgen invokes cargo-metadata and checks the CARGO environment variable
            CARGO="${_CORROSION_CARGO}"
            RUSTC="${_CORROSION_RUSTC}"
            "${cbindgen}"
                    --output "${generated_header}"
                    --crate "${rust_cargo_package}"
                    ${depfile_cbindgen_arg}
                    ${CCN_FLAGS}
        COMMENT "Generate cbindgen bindings for package ${rust_cargo_package} and output header ${generated_header}"
        DEPFILE "${generated_depfile}"
        COMMAND_EXPAND_LISTS
        WORKING_DIRECTORY "${package_manifest_dir}"
    )

    if(NOT installed_cbindgen)
        add_custom_command(
            OUTPUT "${generated_header}"
            APPEND
            DEPENDS _corrosion_cbindgen
        )
    endif()

    if(NOT TARGET "_corrosion_cbindgen_${cbindgen_bindings_target}_bindings")
        add_custom_target(_corrosion_cbindgen_${cbindgen_bindings_target}_bindings
                COMMENT "Generate cbindgen bindings for package ${rust_cargo_package}"
        )
    endif()
    # Users might want to call cbindgen multiple times, e.g. to generate separate C++ and C header files.
    string(MAKE_C_IDENTIFIER "${output_header_name}" header_identifier )
    add_custom_target("_corrosion_cbindgen_${cbindgen_bindings_target}_bindings_${header_identifier}"
            DEPENDS "${generated_header}"
            COMMENT "Generate ${generated_header} for ${cbindgen_bindings_target}"
    )
    add_dependencies("_corrosion_cbindgen_${cbindgen_bindings_target}_bindings" "_corrosion_cbindgen_${cbindgen_bindings_target}_bindings_${header_identifier}")
    add_dependencies(${cbindgen_bindings_target} "_corrosion_cbindgen_${cbindgen_bindings_target}_bindings")
    if(TARGET "${CCN_TARGET}")
        add_dependencies(cargo-build_${CCN_TARGET} "_corrosion_cbindgen_${cbindgen_bindings_target}_bindings")
    endif()
endfunction()

# Parse the version of a Rust package from it's package manifest (Cargo.toml)
function(corrosion_parse_package_version package_manifest_path out_package_version)
    if(NOT EXISTS "${package_manifest_path}")
        message(FATAL_ERROR "Package manifest `${package_manifest_path}` does not exist.")
    endif()

    file(READ "${package_manifest_path}" package_manifest)

    # Find the package table. It may contain arrays, so match until \n\[, which should mark the next
    # table. Note: backslashes must be doubled to escape the backslash for the bracket. LF is single
    # backslash however. On windows the line also ends in \n, so matching against \n\[ is sufficient
    # to detect an opening bracket on a new line.
    set(package_table_regex "\\[package\\](.*)\n\\[")

    string(REGEX MATCH "${package_table_regex}" _package_table "${package_manifest}")

    if(CMAKE_MATCH_COUNT EQUAL "1")
        set(package_table "${CMAKE_MATCH_1}")
    else()
        message(DEBUG
                "Failed to find `[package]` table in package manifest `${package_manifest_path}`.\n"
                "Matches: ${CMAKE_MATCH_COUNT}\n"
        )
        set(${out_package_version}
            "NOTFOUND"
            PARENT_SCOPE
        )
    endif()
    # Match `version = "0.3.2"`, `"version" = "0.3.2" Contains one matching group for the version
    set(version_regex "[\r]?\n[\"']?version[\"']?[ \t]*=[ \t]*[\"']([0-9\.]+)[\"']")

    string(REGEX MATCH "${version_regex}" _version "${package_table}")

    if("${package_table}" MATCHES "${version_regex}")
        set(${out_package_version}
            "${CMAKE_MATCH_1}"
            PARENT_SCOPE
        )
    else()
        message(DEBUG "Failed to extract package version from manifest `${package_manifest_path}`.")
        set(${out_package_version}
            "NOTFOUND"
            PARENT_SCOPE
        )
    endif()
endfunction()

function(_corrosion_initialize_properties target_name)
    # Initialize the `<XYZ>_OUTPUT_DIRECTORY` properties based on `CMAKE_<XYZ>_OUTPUT_DIRECTORY`.
    foreach(output_var RUNTIME_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY)
        if (DEFINED "CMAKE_${output_var}")
            set_property(TARGET ${target_name} PROPERTY "${output_var}" "${CMAKE_${output_var}}")
        endif()

        foreach(config_type ${CMAKE_CONFIGURATION_TYPES})
            string(TOUPPER "${config_type}" config_type_upper)
            if (DEFINED "CMAKE_${output_var}_${config_type_upper}")
                set_property(TARGET ${target_name} PROPERTY "${output_var}_${config_type_upper}" "${CMAKE_${output_var}_${config_type_upper}}")
            endif()
        endforeach()
    endforeach()
endfunction()

# Helper macro to pass through an optional `OPTION` argument parsed via `cmake_parse_arguments`
# to another function that takes the same OPTION.
# If the option was set, then the variable <var_name> will be set to the same option name again,
# otherwise <var_name> will be unset.
macro(_corrosion_option_passthrough_helper option_name prefix var_name)
    if(${${prefix}_${option_name}})
        set("${var_name}" "${option_name}")
    else()
        unset("${var_name}")
    endif()
endmacro()

# Helper macro to pass through an optional argument with value(s), parsed via `cmake_parse_arguments`,
# to another function that takes the same keyword + associated values.
# If the argument was given, then the variable <var_name> will be a list of the argument name and the values,
# which will be expanded, when calling the function (assuming no quotes).
macro(_corrosion_arg_passthrough_helper arg_name prefix var_name)
    if(DEFINED "${prefix}_${arg_name}")
        set("${var_name}" "${arg_name}" "${${prefix}_${arg_name}}")
    else()
        unset("${var_name}")
    endif()
endmacro()

list(POP_BACK CMAKE_MESSAGE_CONTEXT)


================================================
FILE: cmake/CorrosionConfig.cmake.in
================================================
@PACKAGE_INIT@

if (Corrosion_FOUND)
    return()
endif()

list(APPEND CMAKE_MODULE_PATH "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_DATADIR@/cmake")

include(Corrosion)


================================================
FILE: cmake/CorrosionGenerator.cmake
================================================
function(_cargo_metadata out manifest)
    set(OPTIONS LOCKED FROZEN)
    set(ONE_VALUE_KEYWORDS "")
    set(MULTI_VALUE_KEYWORDS "")
    cmake_parse_arguments(PARSE_ARGV 2 CM "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")

    list(APPEND CMAKE_MESSAGE_CONTEXT "_cargo_metadata")

    if(DEFINED CM_UNPARSED_ARGUMENTS)
        message(FATAL_ERROR "Internal error - unexpected arguments: ${CM_UNPARSED_ARGUMENTS}")
    elseif(DEFINED CM_KEYWORDS_MISSING_VALUES)
        message(FATAL_ERROR "Internal error - the following keywords had no associated value(s):"
            "${CM_KEYWORDS_MISSING_VALUES}")
    endif()

    set(cargo_locked "")
    set(cargo_frozen "")
    if(LOCKED)
        set(cargo_locked "--locked")
    endif()
    if(FROZEN)
        set(cargo_frozen "--frozen")
    endif()
    
    get_filename_component(workspace_toml_dir "${manifest}" DIRECTORY)
    
    execute_process(
        COMMAND
            ${CMAKE_COMMAND} -E env
                "CARGO_BUILD_RUSTC=${_CORROSION_RUSTC}"
                "${_CORROSION_CARGO}"
                    metadata
                        --manifest-path "${manifest}"
                        --format-version 1
                        # We don't care about non-workspace dependencies
                        --no-deps
                        ${cargo_locked}
                        ${cargo_frozen}
        # Set WORKING_DIRECTORY to the directory containing the manifest, so that configuration files
        # such as `.cargo/config.toml` or `toolchain.toml` are applied as expected. Cargo searches for
        # configuration files by walking upward from the current directory.
        WORKING_DIRECTORY "${workspace_toml_dir}"
        OUTPUT_VARIABLE json
        COMMAND_ERROR_IS_FATAL ANY
    )

    set(${out} "${json}" PARENT_SCOPE)
endfunction()

# Add targets (crates) of one package
function(_generator_add_package_targets)
    set(OPTIONS NO_LINKER_OVERRIDE)
    set(ONE_VALUE_KEYWORDS
        WORKSPACE_MANIFEST_PATH
        PACKAGE_MANIFEST_PATH
        PACKAGE_NAME
        PACKAGE_VERSION
        TARGETS_JSON
        OUT_CREATED_TARGETS)
    set(MULTI_VALUE_KEYWORDS CRATE_TYPES OVERRIDE_CRATE_TYPE_ARGS)
    cmake_parse_arguments(PARSE_ARGV 0 GAPT "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")

    if(DEFINED GAPT_UNPARSED_ARGUMENTS)
        message(FATAL_ERROR "Internal error - unexpected arguments: ${GAPT_UNPARSED_ARGUMENTS}")
    elseif(DEFINED GAPT_KEYWORDS_MISSING_VALUES)
        message(FATAL_ERROR "Internal error - the following keywords had no associated value(s):"
                    "${GAPT_KEYWORDS_MISSING_VALUES}")
    endif()

    _corrosion_option_passthrough_helper(NO_LINKER_OVERRIDE GAPT no_linker_override)

    set(workspace_manifest_path "${GAPT_WORKSPACE_MANIFEST_PATH}")
    set(package_manifest_path "${GAPT_PACKAGE_MANIFEST_PATH}")
    set(package_name "${GAPT_PACKAGE_NAME}")
    set(package_version "${GAPT_PACKAGE_VERSION}")
    set(targets "${GAPT_TARGETS_JSON}")
    set(out_created_targets "${GAPT_OUT_CREATED_TARGETS}")
    set(crate_types "${GAPT_CRATE_TYPES}")
    if(DEFINED GAPT_OVERRIDE_CRATE_TYPE_ARGS)
        list(GET GAPT_OVERRIDE_CRATE_TYPE_ARGS 0 override_crate_name_list_ref)
        list(GET GAPT_OVERRIDE_CRATE_TYPE_ARGS 1 override_crate_types_list_ref)
    endif()

    set(corrosion_targets "")

    file(TO_CMAKE_PATH "${package_manifest_path}" manifest_path)

    string(JSON targets_len LENGTH "${targets}")
    math(EXPR targets_len-1 "${targets_len} - 1")

    message(DEBUG "Found ${targets_len} targets in package ${package_name}")

    foreach(ix RANGE ${targets_len-1})
        string(JSON target GET "${targets}" ${ix})
        string(JSON target_name GET "${target}" "name")
        string(JSON target_kind GET "${target}" "kind")
        string(JSON target_kind_len LENGTH "${target_kind}")

        math(EXPR target_kind_len-1 "${target_kind_len} - 1")
        set(kinds)
        unset(override_package_crate_type)
        # OVERRIDE_CRATE_TYPE is more specific than the CRATE_TYPES argument to corrosion_import_crate, and thus takes
        # priority.
        if(DEFINED GAPT_OVERRIDE_CRATE_TYPE_ARGS)
            foreach(override_crate_name override_crate_types IN ZIP_LISTS ${override_crate_name_list_ref} ${override_crate_types_list_ref})
                if("${override_crate_name}" STREQUAL "${target_name}")
                    message(DEBUG "Forcing crate ${target_name} to crate-type(s): ${override_crate_types}.")
                    # Convert to CMake list
                    string(REPLACE "," ";" kinds "${override_crate_types}")
                    break()
                endif()
            endforeach()
        else()
            foreach(ix RANGE ${target_kind_len-1})
                string(JSON kind GET "${target_kind}" ${ix})
                if(NOT crate_types OR ${kind} IN_LIST crate_types)
                    list(APPEND kinds ${kind})
                endif()
            endforeach()
        endif()
        if(TARGET "${target_name}"
            AND ("staticlib" IN_LIST kinds OR "cdylib" IN_LIST kinds OR "bin" IN_LIST kinds)
            )
            message(WARNING "Failed to import Rust crate ${target_name} (kind: `${target_kind}`) because a target "
                "with the same name already exists. Skipping this target.\n"
                "Help: If you are importing a package which exposes both a `lib` and "
                "a `bin` target, please consider explicitly naming the targets in your `Cargo.toml` manifest.\n"
                "Note: If you have multiple different packages which have targets with the same name, please note that "
                "this is currently not supported by Corrosion. Feel free to open an issue on Github to request "
                "supporting this scenario."
                )
            # Skip this target to prevent a hard error.
            continue()
        endif()

        if("staticlib" IN_LIST kinds OR "cdylib" IN_LIST kinds)
            # Explicitly set library names have always been forbidden from using dashes (by cargo).
            # Starting with Rust 1.79, names inherited from the package name will have dashes replaced
            # by underscores too. Corrosion will thus replace dashes with underscores, to make the target
            # name consistent independent of the Rust version. `bin` target names are not affected.
            # See https://github.com/corrosion-rs/corrosion/issues/501 for more details.
            string(REPLACE "\-" "_" target_name "${target_name}")

            set(archive_byproducts "")
            set(shared_lib_byproduct "")
            set(pdb_byproduct "")

            add_library(${target_name} INTERFACE)
            _corrosion_initialize_properties(${target_name})
            _corrosion_add_library_target(
                WORKSPACE_MANIFEST_PATH "${workspace_manifest_path}"
                TARGET_NAME "${target_name}"
                LIB_KINDS ${kinds}
                OUT_ARCHIVE_OUTPUT_BYPRODUCTS archive_byproducts
                OUT_SHARED_LIB_BYPRODUCTS shared_lib_byproduct
                OUT_PDB_BYPRODUCT pdb_byproduct
            )

            set(byproducts "")
            list(APPEND byproducts "${archive_byproducts}" "${shared_lib_byproduct}" "${pdb_byproduct}")

            set(cargo_build_out_dir "")
            _add_cargo_build(
                cargo_build_out_dir
                PACKAGE ${package_name}
                TARGET ${target_name}
                MANIFEST_PATH "${manifest_path}"
                WORKSPACE_MANIFEST_PATH "${workspace_manifest_path}"
                TARGET_KINDS "${kinds}"
                BYPRODUCTS "${byproducts}"
                # Optional
                ${no_linker_override}
            )
            if(archive_byproducts)
                _corrosion_copy_byproducts(
                    ${target_name} ARCHIVE_OUTPUT_DIRECTORY "${cargo_build_out_dir}" "${archive_byproducts}"
                )
            endif()
            if(shared_lib_byproduct)
                _corrosion_copy_byproducts(
                    ${target_name} LIBRARY_OUTPUT_DIRECTORY "${cargo_build_out_dir}" "${shared_lib_byproduct}"
                )
            endif()
            if(pdb_byproduct)
                _corrosion_copy_byproducts(
                    ${target_name} "PDB_OUTPUT_DIRECTORY;LIBRARY_OUTPUT_DIRECTORY" "${cargo_build_out_dir}" "${pdb_byproduct}"
                )
            endif()
            list(APPEND corrosion_targets ${target_name})
            set_property(TARGET "${target_name}" PROPERTY COR_CARGO_PACKAGE_NAME "${package_name}" )
        # Note: "bin" is mutually exclusive with "staticlib/cdylib", since `bin`s are seperate crates from libraries.
        elseif("bin" IN_LIST kinds)
            set(bin_byproduct "")
            set(pdb_byproduct "")
            add_executable(${target_name} IMPORTED GLOBAL)
            _corrosion_initialize_properties(${target_name})
            _corrosion_add_bin_target("${workspace_manifest_path}" "${target_name}"
                "bin_byproduct" "pdb_byproduct"
            )

            set(byproducts "")
            list(APPEND byproducts "${bin_byproduct}" "${pdb_byproduct}")

            set(cargo_build_out_dir "")
            _add_cargo_build(
                cargo_build_out_dir
                PACKAGE "${package_name}"
                TARGET "${target_name}"
                MANIFEST_PATH "${manifest_path}"
                WORKSPACE_MANIFEST_PATH "${workspace_manifest_path}"
                TARGET_KINDS "bin"
                BYPRODUCTS "${byproducts}"
                # Optional
                ${no_linker_override}
            )
            _corrosion_copy_byproducts(
                    ${target_name} RUNTIME_OUTPUT_DIRECTORY "${cargo_build_out_dir}" "${bin_byproduct}"
            )
            if(pdb_byproduct)
                _corrosion_copy_byproducts(
                        ${target_name} "PDB_OUTPUT_DIRECTORY;RUNTIME_OUTPUT_DIRECTORY" "${cargo_build_out_dir}" "${pdb_byproduct}"
                )
            endif()
            list(APPEND corrosion_targets ${target_name})
            set_property(TARGET "${target_name}" PROPERTY COR_CARGO_PACKAGE_NAME "${package_name}" )
        else()
            # ignore other kinds (like examples, tests, build scripts, ...)
        endif()
    endforeach()

    if(NOT corrosion_targets)
        message(DEBUG "No relevant targets found in package ${package_name} - Ignoring")
    else()
        set_target_properties(${corrosion_targets} PROPERTIES INTERFACE_COR_PACKAGE_MANIFEST_PATH "${package_manifest_path}")
    endif()
    set(${out_created_targets} "${corrosion_targets}" PARENT_SCOPE)

endfunction()

# Add all cargo targets defined in the packages defined in the Cargo.toml manifest at
# `MANIFEST_PATH`.
function(_generator_add_cargo_targets)
    set(options NO_LINKER_OVERRIDE)
    set(one_value_args MANIFEST_PATH IMPORTED_CRATES)
    set(multi_value_args CRATES CRATE_TYPES OVERRIDE_CRATE_TYPE_ARGS)
    cmake_parse_arguments(
        GGC
        "${options}"
        "${one_value_args}"
        "${multi_value_args}"
        ${ARGN}
    )
    list(APPEND CMAKE_MESSAGE_CONTEXT "_add_cargo_targets")

    _corrosion_option_passthrough_helper(NO_LINKER_OVERRIDE GGC no_linker_override)
    _corrosion_arg_passthrough_helper(CRATE_TYPES GGC crate_types)
    _corrosion_arg_passthrough_helper(OVERRIDE_CRATE_TYPE_ARGS GGC override_crate_types)

    _cargo_metadata(json "${GGC_MANIFEST_PATH}")
    string(JSON packages GET "${json}" "packages")
    string(JSON workspace_members GET "${json}" "workspace_members")

    string(JSON pkgs_len LENGTH "${packages}")
    math(EXPR pkgs_len-1 "${pkgs_len} - 1")

    string(JSON ws_mems_len LENGTH ${workspace_members})
    math(EXPR ws_mems_len-1 "${ws_mems_len} - 1")

    set(created_targets "")
    set(available_package_names "")
    foreach(ix RANGE ${pkgs_len-1})
        string(JSON pkg GET "${packages}" ${ix})
        string(JSON pkg_id GET "${pkg}" "id")
        string(JSON pkg_name GET "${pkg}" "name")
        string(JSON pkg_manifest_path GET "${pkg}" "manifest_path")
        string(JSON pkg_version GET "${pkg}" "version")
        list(APPEND available_package_names "${pkg_name}")

        if(DEFINED GGC_CRATES)
            if(NOT pkg_name IN_LIST GGC_CRATES)
                continue()
            endif()
        endif()

        # probably this loop is not necessary at all, since when using --no-deps, the
        # contents of packages should already be only workspace members!
        unset(pkg_is_ws_member)
        foreach(ix RANGE ${ws_mems_len-1})
            string(JSON ws_mem GET "${workspace_members}" ${ix})
            if(ws_mem STREQUAL pkg_id)
                set(pkg_is_ws_member YES)
                break()
            endif()
        endforeach()

        if(NOT DEFINED pkg_is_ws_member)
            # Since we pass `--no-deps` to cargo metadata now,  I think this situation can't happen, but lets check for
            # it anyway, just to discover any potential issues.
            # If nobody complains for a while, it should be safe to remove this check and the previous loop, which
            # should speed up the configuration process.
            message(WARNING "The package `${pkg_name}` unexpectedly is not part of the workspace."
                "Please open an issue at corrosion with some background information on the package"
            )
        endif()

        string(JSON targets GET "${pkg}" "targets")

        _generator_add_package_targets(
            WORKSPACE_MANIFEST_PATH "${GGC_MANIFEST_PATH}"
            PACKAGE_MANIFEST_PATH "${pkg_manifest_path}"
            PACKAGE_NAME "${pkg_name}"
            PACKAGE_VERSION "${pkg_version}"
            TARGETS_JSON "${targets}"
            OUT_CREATED_TARGETS curr_created_targets
            ${no_linker_override}
            ${crate_types}
            ${override_crate_types}
        )
        list(APPEND created_targets "${curr_created_targets}")
    endforeach()

    if(NOT created_targets)
        set(crates_error_message "")
        if(DEFINED GGC_CRATES)
            set(crates_error_message "\n`corrosion_import_crate()` was called with the `CRATES` "
                "parameter set to `${GGC_CRATES}`. Corrosion will only attempt to import packages matching "
                    "names from this list."
            )
        endif()
        message(FATAL_ERROR
                "Found no targets in ${pkgs_len} packages."
                ${crates_error_message}.
                "\nPlease keep in mind that corrosion will only import Rust `bin` targets or"
                "`staticlib` or `cdylib` library targets."
                "The following packages were found in the Manifest: ${available_package_names}"
        )
    else()
        message(DEBUG "Corrosion created the following CMake targets: ${created_targets}")
    endif()

    if(GGC_IMPORTED_CRATES)
        set(${GGC_IMPORTED_CRATES} "${created_targets}" PARENT_SCOPE)
    endif()
endfunction()


================================================
FILE: cmake/FindRust.cmake
================================================
#[=======================================================================[.rst:
FindRust
--------

Find Rust

This module finds an installed rustc compiler and the cargo build tool. If Rust
is managed by rustup it determines the available toolchains and returns a
concrete Rust version, not a rustup proxy.

#]=======================================================================]

cmake_minimum_required(VERSION 3.12)

option(
        Rust_RUSTUP_INSTALL_MISSING_TARGET
        "Use Rustup to automatically install missing targets instead of giving up"
        OFF
)

# search for Cargo here and set up a bunch of cool flags and stuff
include(FindPackageHandleStandardArgs)

list(APPEND CMAKE_MESSAGE_CONTEXT "FindRust")

# Print error message and return. Should not be used from inside functions
macro(_findrust_failed)
    if("${Rust_FIND_REQUIRED}")
        message(FATAL_ERROR ${ARGN})
    elseif(NOT "${Rust_FIND_QUIETLY}")
        message(WARNING ${ARGN})
    endif()
    set(Rust_FOUND "")
    return()
endmacro()

# Checks if the actual version of a Rust toolchain matches the VERSION requirements specified in find_package.
function(_findrust_version_ok ACTUAL_VERSION OUT_IS_OK)
    if(DEFINED Rust_FIND_VERSION_RANGE)
        if(Rust_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE")
            set(COMPARSION_OPERATOR "VERSION_LESS_EQUAL")
        elseif(Rust_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE")
            set(COMPARSION_OPERATOR "VERSION_LESS")
        else()
            message(FATAL_ERROR "Unexpected value in `<PackageName>_FIND_VERSION_RANGE_MAX`: "
                    "`${Rust_FIND_VERSION_RANGE_MAX}`.")
        endif()
        if(("${ACTUAL_VERSION}" VERSION_GREATER_EQUAL "${Rust_FIND_VERSION_RANGE_MIN}")
                AND
            ( "${ACTUAL_VERSION}" ${COMPARSION_OPERATOR} "${Rust_FIND_VERSION_RANGE_MAX}" )
        )
            set("${OUT_IS_OK}" TRUE PARENT_SCOPE)
        else()
            set("${OUT_IS_OK}" FALSE PARENT_SCOPE)
        endif()
    elseif(DEFINED Rust_FIND_VERSION)
        if(Rust_VERSION_EXACT)
            set(COMPARISON_OPERATOR VERSION_EQUAL)
        else()
            set(COMPARISON_OPERATOR VERSION_GREATER_EQUAL)
        endif()
        if(_TOOLCHAIN_${_TOOLCHAIN_SELECTED}_VERSION "${COMPARISON_OPERATOR}" Rust_FIND_VERSION)
            set("${OUT_IS_OK}" TRUE PARENT_SCOPE)
        else()
            set("${OUT_IS_OK}" FALSE PARENT_SCOPE)
        endif()
    else()
        # if no VERSION requirement was specified, the version is always okay.
        set("${OUT_IS_OK}" TRUE PARENT_SCOPE)
    endif()
endfunction()

function(_corrosion_strip_target_triple input_triple_or_path output_triple)
    # If the target_triple is a path to a custom target specification file, then strip everything
    # except the filename from `target_triple`.
    get_filename_component(target_triple_ext "${input_triple_or_path}" EXT)
    set(target_triple "${input_triple_or_path}")
    if(target_triple_ext)
        if(target_triple_ext STREQUAL ".json")
            get_filename_component(target_triple "${input_triple_or_path}"  NAME_WE)
        endif()
    endif()
    set(${output_triple} "${target_triple}" PARENT_SCOPE)
endfunction()

function(_corrosion_parse_target_triple target_triple out_arch out_vendor out_os out_env)
    _corrosion_strip_target_triple(${target_triple} target_triple)

    # The vendor part may be left out from the target triple, and since `env` is also optional,
    # we determine if vendor is present by matching against a list of known vendors.
    set(known_vendors
        "apple"
        "esp[a-z0-9]*" # espressif, e.g. riscv32imc-esp-espidf or xtensa-esp32s3-none-elf
        "fortanix"
        "kmc"
        "pc"
        "nintendo"
        "nvidia"
        "openwrt"
        "alpine"
        "chimera"
        "unikraft"
        "unknown"
        "uwp" # aarch64-uwp-windows-msvc
        "wrs" # e.g. aarch64-wrs-vxworks
        "sony"
        "sun"
        )
    # todo: allow users to add additional vendors to the list via a cmake variable.
    list(JOIN known_vendors "|" known_vendors_joined)
    # vendor is optional - We detect if vendor is present by matching against a known list of
    # vendors. The next field is the OS, which we assume to always be present, while the last field
    # is again optional and contains the environment.
    string(REGEX MATCH
        "^([a-z0-9_\.]+)-((${known_vendors_joined})-)?([a-z0-9_]+)(-([a-z0-9_]+))?$"
        whole_match
        "${target_triple}"
        )
    if((NOT whole_match) AND (NOT CORROSION_NO_WARN_PARSE_TARGET_TRIPLE_FAILED))
        message(WARNING "Failed to parse target-triple `${target_triple}`."
            "Corrosion determines some information about the output artifacts based on OS "
            "specified in the Rust target-triple.\n"
            "Currently this is relevant for windows and darwin (mac) targets, since file "
            "extensions differ.\n"
            "Note: If you are targeting a different OS you can suppress this warning by"
            " setting the CMake cache variable "
            
Download .txt
gitextract_hm2o3l7u/

├── .github/
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE/
│   │   └── bug_report.yml
│   ├── scripts/
│   │   ├── determine_compiler.sh
│   │   └── toolchains/
│   │       ├── aarch64-apple-darwin-clang.cmake
│   │       ├── aarch64-unknown-linux-gnu-clang.cmake
│   │       ├── aarch64-unknown-linux-gnu-gcc.cmake
│   │       ├── i686-unknown-linux-gnu-clang.cmake
│   │       ├── i686-unknown-linux-gnu-gcc.cmake
│   │       ├── x86_64-apple-darwin-clang.cmake
│   │       ├── x86_64-pc-windows-gnullvm.cmake
│   │       ├── x86_64-unknown-linux-gnu-clang.cmake
│   │       └── x86_64-unknown-linux-gnu-gcc.cmake
│   └── workflows/
│       ├── gh-pages.yaml
│       ├── linux.yaml
│       ├── test.yaml
│       └── visual_studio.yaml
├── .gitignore
├── CMakeLists.txt
├── CMakePresets.json
├── LICENSE
├── README.md
├── RELEASES.md
├── cmake/
│   ├── Corrosion.cmake
│   ├── CorrosionConfig.cmake.in
│   ├── CorrosionGenerator.cmake
│   └── FindRust.cmake
├── doc/
│   ├── .gitignore
│   ├── book.toml
│   └── src/
│       ├── SUMMARY.md
│       ├── advanced.md
│       ├── common_issues.md
│       ├── ffi_bindings.md
│       ├── introduction.md
│       ├── quick_start.md
│       ├── setup_corrosion.md
│       └── usage.md
└── test/
    ├── CMakeLists.txt
    ├── ConfigureAndBuild.cmake
    ├── README.md
    ├── TestFileExists.cmake
    ├── cargo_flags/
    │   ├── CMakeLists.txt
    │   └── cargo_flags/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── cbindgen/
    │   ├── CMakeLists.txt
    │   ├── auto/
    │   │   ├── CMakeLists.txt
    │   │   ├── main.cpp
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       ├── cbindgen.toml
    │   │       └── src/
    │   │           ├── ffi.rs
    │   │           ├── lib.rs
    │   │           └── other_mod/
    │   │               └── mod.rs
    │   ├── install_lib/
    │   │   ├── CMakeLists.txt
    │   │   └── rust_lib/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           └── lib.rs
    │   └── manual/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── cbindgen.toml
    │           └── src/
    │               ├── ffi.rs
    │               ├── lib.rs
    │               └── other_mod/
    │                   └── mod.rs
    ├── config_discovery/
    │   ├── CMakeLists.txt
    │   ├── README.md
    │   └── config_discovery/
    │       ├── .cargo/
    │       │   └── config.toml
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       └── src/
    │           └── main.rs
    ├── corrosion_install/
    │   ├── CMakeLists.txt
    │   ├── install_lib/
    │   │   ├── CMakeLists.txt
    │   │   ├── main.cpp
    │   │   └── rust_lib/
    │   │       ├── CMakeLists.txt
    │   │       ├── Cargo.toml
    │   │       ├── include/
    │   │       │   └── rust_lib/
    │   │       │       └── rust_lib.hpp
    │   │       └── src/
    │   │           └── lib.rs
    │   └── install_rust_bin/
    │       ├── CMakeLists.txt
    │       └── rust_bin/
    │           ├── CMakeLists.txt
    │           ├── Cargo.toml
    │           └── src/
    │               └── main.rs
    ├── cpp2rust/
    │   ├── CMakeLists.txt
    │   └── cpp2rust/
    │       ├── CMakeLists.txt
    │       ├── lib.cpp
    │       ├── lib2.cpp
    │       ├── path with space/
    │       │   └── lib3.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── build.rs
    │           ├── rust_dependency/
    │           │   ├── Cargo.toml
    │           │   └── src/
    │           │       └── lib.rs
    │           └── src/
    │               └── bin/
    │                   └── rust-exe.rs
    ├── crate_type/
    │   ├── CMakeLists.txt
    │   └── crate_type/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       ├── proj1/
    │       │   ├── Cargo.toml
    │       │   └── src/
    │       │       └── lib.rs
    │       └── proj2/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── custom_profiles/
    │   ├── CMakeLists.txt
    │   ├── basic_profiles/
    │   │   ├── CMakeLists.txt
    │   │   ├── main.cpp
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           └── lib.rs
    │   └── custom_profiles/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── custom_target/
    │   ├── CMakeLists.txt
    │   └── custom_target/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── build.rs
    │           ├── c_lib.c
    │           └── src/
    │               ├── bin.rs
    │               └── lib.rs
    ├── cxxbridge/
    │   ├── CMakeLists.txt
    │   ├── cxxbridge_circular/
    │   │   ├── CMakeLists.txt
    │   │   ├── cpplib.cpp
    │   │   ├── include/
    │   │   │   └── cpplib.h
    │   │   ├── main.cpp
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           └── lib.rs
    │   ├── cxxbridge_cpp2rust/
    │   │   ├── CMakeLists.txt
    │   │   ├── cpplib.cpp
    │   │   ├── include/
    │   │   │   └── cpplib.h
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           ├── lib.rs
    │   │           └── main.rs
    │   ├── cxxbridge_exported_impls/
    │   │   ├── CMakeLists.txt
    │   │   ├── main.cpp
    │   │   └── rust/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           ├── bridge_a.rs
    │   │           ├── bridge_b.rs
    │   │           └── lib.rs
    │   └── cxxbridge_rust2cpp/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               ├── foo/
    │               │   └── mod.rs
    │               └── lib.rs
    ├── envvar/
    │   ├── CMakeLists.txt
    │   └── envvar/
    │       ├── .cargo/
    │       │   └── config.toml
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       ├── build.rs
    │       ├── main.cpp
    │       └── src/
    │           └── lib.rs
    ├── features/
    │   ├── CMakeLists.txt
    │   └── features/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── find_rust/
    │   ├── CMakeLists.txt
    │   ├── find_rust/
    │   │   └── CMakeLists.txt
    │   └── rustup_proxy/
    │       └── CMakeLists.txt
    ├── gensource/
    │   ├── CMakeLists.txt
    │   └── gensource/
    │       ├── .gitignore
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       ├── generator/
    │       │   ├── CMakeLists.txt
    │       │   ├── Cargo.toml
    │       │   └── src/
    │       │       └── main.rs
    │       └── src/
    │           └── lib.rs
    ├── hostbuild/
    │   ├── CMakeLists.txt
    │   └── hostbuild/
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       ├── build.rs
    │       └── src/
    │           ├── lib.c
    │           └── main.rs
    ├── multitarget/
    │   ├── CMakeLists.txt
    │   └── multitarget/
    │       ├── CMakeLists.txt
    │       ├── Cargo.toml
    │       ├── lib.cpp
    │       └── src/
    │           ├── bin/
    │           │   ├── bin1.rs
    │           │   ├── bin2.rs
    │           │   └── bin3.rs
    │           └── lib.rs
    ├── nostd/
    │   ├── CMakeLists.txt
    │   └── nostd/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           └── src/
    │               └── lib.rs
    ├── output directory/
    │   ├── CMakeLists.txt
    │   ├── output directory/
    │   │   ├── CMakeLists.txt
    │   │   ├── consumer.cpp
    │   │   ├── proj1/
    │   │   │   ├── Cargo.toml
    │   │   │   └── src/
    │   │   │       ├── bin/
    │   │   │       │   └── rust_bin1.rs
    │   │   │       └── lib.rs
    │   │   ├── proj2/
    │   │   │   ├── Cargo.toml
    │   │   │   └── src/
    │   │   │       ├── bin/
    │   │   │       │   └── rust_bin2.rs
    │   │   │       └── lib.rs
    │   │   └── proj3/
    │   │       ├── Cargo.toml
    │   │       └── src/
    │   │           ├── bin/
    │   │           │   └── rust_bin3.rs
    │   │           └── lib.rs
    │   └── output_directory_config/
    │       ├── CMakeLists.txt
    │       ├── consumer.cpp
    │       └── proj1/
    │           ├── Cargo.toml
    │           └── src/
    │               ├── bin/
    │               │   └── rust_bin1.rs
    │               └── lib.rs
    ├── override_crate_type/
    │   ├── CMakeLists.txt
    │   └── override_crate_type/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── build.rs
    │           └── src/
    │               └── lib.rs
    ├── parse_target_triple/
    │   ├── CMakeLists.txt
    │   ├── parse_target_triple/
    │   │   └── CMakeLists.txt
    │   └── parse_target_triple_should_fail/
    │       └── CMakeLists.txt
    ├── rust2cpp/
    │   ├── CMakeLists.txt
    │   └── rust2cpp/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── build.rs
    │           └── src/
    │               └── lib.rs
    ├── rustflags/
    │   ├── CMakeLists.txt
    │   ├── cargo_config_rustflags/
    │   │   ├── .cargo/
    │   │   │   └── config.toml
    │   │   ├── CMakeLists.txt
    │   │   ├── Cargo.toml
    │   │   └── src/
    │   │       └── main.rs
    │   └── rustflags/
    │       ├── CMakeLists.txt
    │       ├── main.cpp
    │       └── rust/
    │           ├── Cargo.toml
    │           ├── some_dependency/
    │           │   ├── Cargo.toml
    │           │   └── src/
    │           │       └── lib.rs
    │           └── src/
    │               └── lib.rs
    └── workspace/
        ├── CMakeLists.txt
        └── workspace/
            ├── CMakeLists.txt
            ├── Cargo.toml
            ├── main.cpp
            ├── member1/
            │   ├── Cargo.toml
            │   └── src/
            │       └── lib.rs
            ├── member2/
            │   ├── Cargo.toml
            │   └── src/
            │       └── lib.rs
            └── member3/
                ├── Cargo.toml
                └── src/
                    └── main.rs
Download .txt
SYMBOL INDEX (138 symbols across 87 files)

FILE: test/cargo_flags/cargo_flags/main.cpp
  function main (line 4) | int main(int argc, char **argv) {

FILE: test/cargo_flags/cargo_flags/rust/src/lib.rs
  function rust_function (line 4) | pub extern "C" fn rust_function(name: *const c_char) {

FILE: test/cbindgen/auto/main.cpp
  function main (line 4) | int main(int argc, char **argv) {

FILE: test/cbindgen/auto/rust/src/ffi.rs
  constant FFI_MAGIC_NUMBER (line 3) | pub const FFI_MAGIC_NUMBER: u64 = 0xFDA0_0184;

FILE: test/cbindgen/auto/rust/src/lib.rs
  constant MAGIC_NUMBER (line 1) | pub const MAGIC_NUMBER: u64 = 0xABCD_EFAB;
  type Point (line 8) | pub struct Point {
    method add (line 14) | pub(crate) fn add(&mut self, rhs: &Point) {
  function add_point (line 21) | pub extern "C" fn add_point(lhs: Option<&mut Point>, rhs: Option<&Point>) {
  function is_magic_number (line 31) | pub extern "C" fn is_magic_number(num: u64) -> bool {

FILE: test/cbindgen/auto/rust/src/other_mod/mod.rs
  constant OTHER_MOD_MAGIC_NUMBER (line 1) | pub const OTHER_MOD_MAGIC_NUMBER: u32 = 192312312;

FILE: test/cbindgen/install_lib/rust_lib/src/lib.rs
  function add (line 3) | pub extern "C" fn add(left: u64, right: u64) -> u64 {

FILE: test/cbindgen/manual/main.cpp
  function main (line 4) | int main(int argc, char **argv) {

FILE: test/cbindgen/manual/rust/src/ffi.rs
  constant FFI_MAGIC_NUMBER (line 3) | pub const FFI_MAGIC_NUMBER: u64 = 0xFDA0_0184;

FILE: test/cbindgen/manual/rust/src/lib.rs
  constant MAGIC_NUMBER (line 1) | pub const MAGIC_NUMBER: u64 = 0xABCD_EFAB;
  type Point (line 8) | pub struct Point {
    method add (line 14) | pub(crate) fn add(&mut self, rhs: &Point) {
  function add_point (line 21) | pub extern "C" fn add_point(lhs: Option<&mut Point>, rhs: Option<&Point>) {
  function is_magic_number (line 31) | pub extern "C" fn is_magic_number(num: u64) -> bool {

FILE: test/cbindgen/manual/rust/src/other_mod/mod.rs
  constant OTHER_MOD_MAGIC_NUMBER (line 1) | pub const OTHER_MOD_MAGIC_NUMBER: u32 = 192312312;

FILE: test/config_discovery/config_discovery/src/main.rs
  function main (line 9) | fn main() {

FILE: test/corrosion_install/install_lib/main.cpp
  function main (line 7) | int main(int argc, char **argv) {

FILE: test/corrosion_install/install_lib/rust_lib/src/lib.rs
  function add (line 3) | pub extern "C" fn add(left: u64, right: u64) -> u64 {

FILE: test/corrosion_install/install_rust_bin/rust_bin/src/main.rs
  function main (line 1) | fn main() {

FILE: test/cpp2rust/cpp2rust/lib.cpp
  function cpp_function (line 3) | void cpp_function(char const *name) {

FILE: test/cpp2rust/cpp2rust/lib2.cpp
  function cpp_function2 (line 4) | void cpp_function2(char const *name) {
  function get_42 (line 8) | uint32_t get_42() {

FILE: test/cpp2rust/cpp2rust/path with space/lib3.cpp
  function cpp_function3 (line 5) | void cpp_function3(char const *name) {

FILE: test/cpp2rust/cpp2rust/rust/build.rs
  function main (line 2) | fn main() {

FILE: test/cpp2rust/cpp2rust/rust/rust_dependency/src/lib.rs
  function get_42 (line 3) | fn get_42() -> u32;
  function calls_ffi (line 5) | pub fn calls_ffi() {

FILE: test/cpp2rust/cpp2rust/rust/src/bin/rust-exe.rs
  function cpp_function (line 4) | fn cpp_function(name: *const c_char);
  function cpp_function2 (line 5) | fn cpp_function2(name: *const c_char);
  function cpp_function3 (line 6) | fn cpp_function3(name: *const c_char);
  function greeting (line 10) | fn greeting(name: &str) {
  function main (line 19) | fn main() {

FILE: test/crate_type/crate_type/main.cpp
  function main (line 4) | int main() {

FILE: test/crate_type/crate_type/proj1/src/lib.rs
  function rust_function1 (line 2) | pub extern "C" fn rust_function1() {

FILE: test/crate_type/crate_type/proj2/src/lib.rs
  function rust_function2 (line 2) | pub extern "C" fn rust_function2() {

FILE: test/custom_profiles/basic_profiles/main.cpp
  function main (line 4) | int main(int argc, char **argv) {

FILE: test/custom_profiles/basic_profiles/rust/src/lib.rs
  function rust_function (line 4) | pub extern "C" fn rust_function(name: *const c_char) {

FILE: test/custom_profiles/custom_profiles/main.cpp
  function main (line 4) | int main(int argc, char **argv) {

FILE: test/custom_profiles/custom_profiles/rust/src/lib.rs
  function rust_function (line 4) | pub extern "C" fn rust_function(name: *const c_char) {
  constant _ (line 11) | const _: () = assert!(false, "Debug assertions where not disabled via cu...

FILE: test/custom_target/custom_target/main.cpp
  function main (line 4) | int main(int argc, char **argv) {

FILE: test/custom_target/custom_target/rust/build.rs
  function main (line 1) | fn main() {

FILE: test/custom_target/custom_target/rust/c_lib.c
  function calculate_42 (line 3) | uint32_t calculate_42(void) {

FILE: test/custom_target/custom_target/rust/src/bin.rs
  function main (line 3) | fn main() {

FILE: test/custom_target/custom_target/rust/src/lib.rs
  function calculate_42 (line 4) | pub fn calculate_42() -> u32;
  function rust_function (line 8) | pub extern "C" fn rust_function(name: *const c_char) {

FILE: test/cxxbridge/cxxbridge_circular/cpplib.cpp
  function RsImage (line 6) | RsImage read_image(rust::Str path) {
  function assert_equality (line 14) | void assert_equality() {

FILE: test/cxxbridge/cxxbridge_circular/main.cpp
  function main (line 5) | int main(void) {

FILE: test/cxxbridge/cxxbridge_circular/rust/src/lib.rs
  type Rgba (line 4) | pub struct Rgba {
  type RsImage (line 12) | pub struct RsImage {
    method equal_to (line 30) | pub fn equal_to(&self, path: &str) -> bool {
  function read_image (line 19) | pub fn read_image(path: &str) -> RsImage;
  function equal_to (line 23) | pub fn equal_to(self: &RsImage, other: &str) -> bool;

FILE: test/cxxbridge/cxxbridge_cpp2rust/cpplib.cpp
  function RsImage (line 6) | RsImage read_image(rust::Str path) {
  function write_image (line 13) | void write_image(::rust::Str path, ::RsImage const & image) {

FILE: test/cxxbridge/cxxbridge_cpp2rust/rust/src/lib.rs
  type Rgba (line 5) | pub struct Rgba
  type RsImage (line 14) | pub struct RsImage
  function read_image (line 23) | pub fn read_image(path: &str) -> RsImage;
  function write_image (line 24) | fn write_image(path: &str, image: &RsImage);

FILE: test/cxxbridge/cxxbridge_cpp2rust/rust/src/main.rs
  function main (line 3) | fn main() {

FILE: test/cxxbridge/cxxbridge_exported_impls/main.cpp
  function main (line 5) | int main()

FILE: test/cxxbridge/cxxbridge_exported_impls/rust/src/bridge_a.rs
  type OkResult (line 3) | pub struct OkResult {
  type TestResult (line 8) | pub struct TestResult {
  function make_result (line 15) | fn make_result() -> Result<TestResult>;
  function make_result (line 19) | pub fn make_result() -> Result<ffi::TestResult, String> {

FILE: test/cxxbridge/cxxbridge_exported_impls/rust/src/bridge_b.rs
  type NewVal (line 5) | pub struct NewVal {
  function make_new_val (line 13) | fn make_new_val() -> SharedPtr<NewVal>;
  function make_new_val (line 17) | pub fn make_new_val() -> cxx::SharedPtr<ffi::NewVal> {

FILE: test/cxxbridge/cxxbridge_exported_impls/rust/src/lib.rs
  type TestResult (line 12) | type TestResult = crate::bridge_a::ffi::TestResult;
  type NewVal (line 13) | type NewVal = crate::bridge_b::ffi::NewVal;
  function combine_result (line 17) | fn combine_result(other: SharedPtr<NewVal>) -> Result<TestResult>;
  function combine_result (line 22) | pub fn combine_result(other: cxx::SharedPtr<crate::bridge_b::ffi::NewVal...

FILE: test/cxxbridge/cxxbridge_rust2cpp/main.cpp
  function main (line 5) | int main(int argc, char **argv)

FILE: test/cxxbridge/cxxbridge_rust2cpp/rust/src/foo/mod.rs
  function print (line 4) | fn print(slice: &[u64]);
  function print (line 8) | fn print(slice: &[u64]) {

FILE: test/cxxbridge/cxxbridge_rust2cpp/rust/src/lib.rs
  function print (line 6) | fn print(slice: &[u64]);
  function print (line 10) | fn print(slice: &[u64]) {

FILE: test/envvar/envvar/build.rs
  function main (line 1) | fn main() {

FILE: test/envvar/envvar/main.cpp
  function main (line 3) | int main() {

FILE: test/envvar/envvar/src/lib.rs
  function it_works (line 4) | fn it_works() {

FILE: test/features/features/main.cpp
  function main (line 5) | int main(int argc, char **argv) {

FILE: test/features/features/rust/src/lib.rs
  function rust_function (line 6) | pub extern "C" fn rust_function(name: *const c_char) {
  function rust_second_function (line 13) | pub extern "C" fn rust_second_function(name: *const c_char) {
  function rust_third_function (line 20) | pub extern "C" fn rust_third_function(name: *const c_char) {
  constant _ (line 26) | const _: [(); 1] = [(); 2];

FILE: test/gensource/gensource/generator/src/main.rs
  function main (line 2) | fn main() -> Result<(), std::io::Error> {

FILE: test/gensource/gensource/src/lib.rs
  function it_works (line 6) | fn it_works() {

FILE: test/hostbuild/hostbuild/build.rs
  function main (line 1) | fn main() {

FILE: test/hostbuild/hostbuild/src/lib.c
  function c_function (line 3) | void c_function(char const *name) {

FILE: test/hostbuild/hostbuild/src/main.rs
  function c_function (line 4) | fn c_function(name: *const c_char);
  function main (line 7) | fn main() {

FILE: test/multitarget/multitarget/lib.cpp
  function cpp_function (line 3) | void cpp_function(char const *name) {

FILE: test/multitarget/multitarget/src/bin/bin1.rs
  function main (line 3) | fn main() {

FILE: test/multitarget/multitarget/src/bin/bin2.rs
  function main (line 3) | fn main() {

FILE: test/multitarget/multitarget/src/bin/bin3.rs
  function main (line 3) | fn main() {

FILE: test/multitarget/multitarget/src/lib.rs
  function hello_world (line 3) | pub fn hello_world() {
  function cpp_function (line 8) | pub fn cpp_function(name: *const c_char);

FILE: test/nostd/nostd/main.cpp
  function cpp_function (line 3) | void cpp_function() {

FILE: test/nostd/nostd/rust/src/lib.rs
  function rust_function (line 5) | pub extern "C" fn rust_function() {}
  function panic (line 8) | fn panic(_panic: &PanicInfo<'_>) -> ! {

FILE: test/output directory/output directory/consumer.cpp
  function main (line 7) | int main(int argc, char *argv[])

FILE: test/output directory/output directory/proj1/src/bin/rust_bin1.rs
  function main (line 1) | fn main() {

FILE: test/output directory/output directory/proj1/src/lib.rs
  function ret_12 (line 2) | pub extern "C" fn ret_12() -> u32 {

FILE: test/output directory/output directory/proj2/src/bin/rust_bin2.rs
  function main (line 1) | fn main() {

FILE: test/output directory/output directory/proj2/src/lib.rs
  function ret_12 (line 2) | pub extern "C" fn ret_12() -> u32 {

FILE: test/output directory/output directory/proj3/src/bin/rust_bin3.rs
  function main (line 1) | fn main() {

FILE: test/output directory/output directory/proj3/src/lib.rs
  function ret_12 (line 2) | pub extern "C" fn ret_12() -> u32 {

FILE: test/output directory/output_directory_config/consumer.cpp
  function main (line 7) | int main(int argc, char *argv[])

FILE: test/output directory/output_directory_config/proj1/src/bin/rust_bin1.rs
  function main (line 1) | fn main() {

FILE: test/output directory/output_directory_config/proj1/src/lib.rs
  function ret_12 (line 2) | pub extern "C" fn ret_12() -> u32 {

FILE: test/override_crate_type/override_crate_type/main.cpp
  function main (line 3) | int main(int argc, char **argv) {

FILE: test/override_crate_type/override_crate_type/rust/build.rs
  function main (line 2) | fn main() {

FILE: test/override_crate_type/override_crate_type/rust/src/lib.rs
  function rust_function (line 4) | pub extern "C" fn rust_function(name: *const c_char) {

FILE: test/rust2cpp/rust2cpp/main.cpp
  function main (line 3) | int main(int argc, char **argv) {

FILE: test/rust2cpp/rust2cpp/rust/build.rs
  function main (line 2) | fn main() {

FILE: test/rust2cpp/rust2cpp/rust/src/lib.rs
  function rust_function (line 4) | pub extern "C" fn rust_function(name: *const c_char) {

FILE: test/rustflags/cargo_config_rustflags/src/main.rs
  function print_line (line 3) | fn print_line() {
  function test_local_rustflag (line 9) | fn test_local_rustflag() {
  function main (line 13) | fn main() {

FILE: test/rustflags/rustflags/main.cpp
  function main (line 5) | int main(int argc, char **argv) {

FILE: test/rustflags/rustflags/rust/some_dependency/src/lib.rs
  constant _ (line 3) | const _: [(); 1] = [(); 2];
  constant _ (line 6) | const _: [(); 1] = [(); 2];
  function some_function (line 8) | pub fn some_function() -> u32 {

FILE: test/rustflags/rustflags/rust/src/lib.rs
  function rust_function (line 6) | pub extern "C" fn rust_function(name: *const c_char) {
  function rust_second_function (line 13) | pub extern "C" fn rust_second_function(name: *const c_char) {
  function rust_second_function (line 20) | pub extern "C" fn rust_second_function(name: *const c_char) {
  function rust_third_function (line 27) | pub extern "C" fn rust_third_function(name: *const c_char) {
  constant _ (line 34) | const _: [(); 1] = [(); 2];
  constant _ (line 37) | const _: [(); 1] = [(); 2];
  constant _ (line 40) | const _: [(); 1] = [(); 2];

FILE: test/workspace/workspace/main.cpp
  function main (line 2) | int main() {

FILE: test/workspace/workspace/member1/src/lib.rs
  function it_works (line 4) | fn it_works() {

FILE: test/workspace/workspace/member2/src/lib.rs
  function it_works (line 4) | fn it_works() {

FILE: test/workspace/workspace/member3/src/main.rs
  function main (line 1) | fn main() {
Condensed preview — 233 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (404K chars).
[
  {
    "path": ".github/FUNDING.yml",
    "chars": 19,
    "preview": "github: [\"jschwe\"]\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.yml",
    "chars": 1972,
    "preview": "name: Bug Report\ndescription: File a bug report\ntitle: \"[Bug]: \"\nlabels: [\"bug\", \"triage\"]\nassignees:\n  - jschwe\nbody:\n "
  },
  {
    "path": ".github/scripts/determine_compiler.sh",
    "chars": 1696,
    "preview": "#!/usr/bin/env bash\n\ncompiler_kind=\"$1\"\nrunner_os=\"$2\"\ntarget_abi=\"$3\"\ntarget_system_name=\"$4\"\ntarget_arch=\"$5\"\n\nset -e\n"
  },
  {
    "path": ".github/scripts/toolchains/aarch64-apple-darwin-clang.cmake",
    "chars": 223,
    "preview": "set(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\nset(CMAKE_C_COMPILER_TARGET \"aarch64-apple-darwin\")\nset("
  },
  {
    "path": ".github/scripts/toolchains/aarch64-unknown-linux-gnu-clang.cmake",
    "chars": 164,
    "preview": "set(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\nset(CMAKE_C_COMPILER_TARGET \"aarch64-linux-gnu\")\nset(CMA"
  },
  {
    "path": ".github/scripts/toolchains/aarch64-unknown-linux-gnu-gcc.cmake",
    "chars": 125,
    "preview": "set(CMAKE_C_COMPILER \"aarch64-linux-gnu-gcc\")\nset(CMAKE_CXX_COMPILER \"aarch64-linux-gnu-g++\")\nset(CMAKE_SYSTEM_NAME \"Lin"
  },
  {
    "path": ".github/scripts/toolchains/i686-unknown-linux-gnu-clang.cmake",
    "chars": 164,
    "preview": "set(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\nset(CMAKE_C_COMPILER_TARGET \"i686-pc-linux-gnu\")\nset(CMA"
  },
  {
    "path": ".github/scripts/toolchains/i686-unknown-linux-gnu-gcc.cmake",
    "chars": 119,
    "preview": "set(CMAKE_C_COMPILER \"i686-linux-gnu-gcc\")\nset(CMAKE_CXX_COMPILER \"i686-linux-gnu-g++\")\nset(CMAKE_SYSTEM_NAME \"Linux\")\n"
  },
  {
    "path": ".github/scripts/toolchains/x86_64-apple-darwin-clang.cmake",
    "chars": 309,
    "preview": "set(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\nset(CMAKE_C_COMPILER_TARGET \"x86_64-apple-darwin\")\nset(C"
  },
  {
    "path": ".github/scripts/toolchains/x86_64-pc-windows-gnullvm.cmake",
    "chars": 172,
    "preview": "set(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\nset(CMAKE_C_COMPILER_TARGET \"x86_64-pc-windows-gnu\")\nset"
  },
  {
    "path": ".github/scripts/toolchains/x86_64-unknown-linux-gnu-clang.cmake",
    "chars": 110,
    "preview": "# Assumption: This is the native host target.\nset(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\n"
  },
  {
    "path": ".github/scripts/toolchains/x86_64-unknown-linux-gnu-gcc.cmake",
    "chars": 104,
    "preview": "# Assumption: This is the native host target.\nset(CMAKE_C_COMPILER \"gcc\")\nset(CMAKE_CXX_COMPILER \"g++\")\n"
  },
  {
    "path": ".github/workflows/gh-pages.yaml",
    "chars": 2582,
    "preview": "name: Deploy GH pages\non:\n  push:\n    branches:\n      - master\n  # Allows you to run this workflow manually from the Act"
  },
  {
    "path": ".github/workflows/linux.yaml",
    "chars": 1793,
    "preview": "# Workflow file for Linux hosts\nname: Corrosion on Linux\non:\n  workflow_call:\n    inputs:\n      ubuntu_version:\n        "
  },
  {
    "path": ".github/workflows/test.yaml",
    "chars": 15294,
    "preview": "name: Tests\non:\n  push:\n    branches:\n      - master\n  pull_request:\n    branches:\n      - 'master'\n      - 'stable/**'\n"
  },
  {
    "path": ".github/workflows/visual_studio.yaml",
    "chars": 1800,
    "preview": "name: Corrosion with Visual Studio\n\non:\n  workflow_call:\n    inputs:\n      vs_version:\n        required: true\n        ty"
  },
  {
    "path": ".gitignore",
    "chars": 82,
    "preview": "\n**/target/\n**/*.rs.bk\nbuild*/\n.vscode\n.idea\ncmake-build-*\ntest/test_header.cmake\n"
  },
  {
    "path": "CMakeLists.txt",
    "chars": 2075,
    "preview": "cmake_minimum_required(VERSION 3.22)\nproject(Corrosion\n    VERSION 0.6.1\n    LANGUAGES NONE\n    HOMEPAGE_URL \"https://co"
  },
  {
    "path": "CMakePresets.json",
    "chars": 9309,
    "preview": "{\n    \"version\": 3,\n    \"cmakeMinimumRequired\": {\n        \"major\": 3,\n        \"minor\": 22,\n        \"patch\": 0\n    },\n   "
  },
  {
    "path": "LICENSE",
    "chars": 1070,
    "preview": "MIT License\n\nCopyright (c) 2018 Andrew Gaspar\n\nPermission is hereby granted, free of charge, to any person obtaining a c"
  },
  {
    "path": "README.md",
    "chars": 2008,
    "preview": "# Corrosion\n[![Build Status](https://github.com/corrosion-rs/corrosion/actions/workflows/test.yaml/badge.svg)](https://g"
  },
  {
    "path": "RELEASES.md",
    "chars": 25471,
    "preview": "# v0.6.1 (2025-01-17)\n\n## Fixes\n\n- Fix building shared libraries for iOS.\n- Fix host linker detection for iOS and add th"
  },
  {
    "path": "cmake/Corrosion.cmake",
    "chars": 109324,
    "preview": "cmake_minimum_required(VERSION 3.22)\n\nlist(APPEND CMAKE_MESSAGE_CONTEXT \"Corrosion\")\n\nmessage(DEBUG \"Using Corrosion ${C"
  },
  {
    "path": "cmake/CorrosionConfig.cmake.in",
    "chars": 164,
    "preview": "@PACKAGE_INIT@\n\nif (Corrosion_FOUND)\n    return()\nendif()\n\nlist(APPEND CMAKE_MODULE_PATH \"${PACKAGE_PREFIX_DIR}/@CMAKE_I"
  },
  {
    "path": "cmake/CorrosionGenerator.cmake",
    "chars": 15056,
    "preview": "function(_cargo_metadata out manifest)\n    set(OPTIONS LOCKED FROZEN)\n    set(ONE_VALUE_KEYWORDS \"\")\n    set(MULTI_VALUE"
  },
  {
    "path": "cmake/FindRust.cmake",
    "chars": 42804,
    "preview": "#[=======================================================================[.rst:\nFindRust\n--------\n\nFind Rust\n\nThis modul"
  },
  {
    "path": "doc/.gitignore",
    "chars": 5,
    "preview": "book\n"
  },
  {
    "path": "doc/book.toml",
    "chars": 90,
    "preview": "[book]\nlanguage = \"en\"\nmultilingual = false\nsrc = \"src\"\ntitle = \"Corrosion documentation\"\n"
  },
  {
    "path": "doc/src/SUMMARY.md",
    "chars": 259,
    "preview": "# Summary\n\n- [Introduction](./introduction.md)\n- [Quick Start](./quick_start.md)\n- [Setup Corrosion](./setup_corrosion.m"
  },
  {
    "path": "doc/src/advanced.md",
    "chars": 5520,
    "preview": "## What does corrosion do?\n\nThe specifics of what corrosion does should be regarded as an implementation detail and not "
  },
  {
    "path": "doc/src/common_issues.md",
    "chars": 7041,
    "preview": "# Commonly encountered (Non-Corrosion) Issues\n\n## Table of Contents\n\n- [Linking Debug C/C++ libraries into Rust fails on"
  },
  {
    "path": "doc/src/ffi_bindings.md",
    "chars": 1385,
    "preview": "# Integrating Automatically Generated FFI Bindings\n\nThere are a number of tools to automatically generate bindings betwe"
  },
  {
    "path": "doc/src/introduction.md",
    "chars": 983,
    "preview": "## About Corrosion\n\nCorrosion, formerly known as cmake-cargo, is a tool for integrating Rust into an existing CMake\nproj"
  },
  {
    "path": "doc/src/quick_start.md",
    "chars": 1664,
    "preview": "# Quick Start\n\nYou can add corrosion to your project via the `FetchContent` CMake module or one of the other methods\ndes"
  },
  {
    "path": "doc/src/setup_corrosion.md",
    "chars": 3709,
    "preview": "# Adding Corrosion to your project\n\nThere are two fundamental installation methods that are supported by Corrosion - ins"
  },
  {
    "path": "doc/src/usage.md",
    "chars": 20990,
    "preview": "## Usage\n\n### Automatically import crate targets with `corrosion_import_crate`\n\nIn order to integrate a Rust crate into "
  },
  {
    "path": "test/CMakeLists.txt",
    "chars": 8755,
    "preview": "# This option is currently used to prevent recursion\noption(CORROSION_TESTS \"Enable Corrosion tests\" ON)\nmark_as_advance"
  },
  {
    "path": "test/ConfigureAndBuild.cmake",
    "chars": 3672,
    "preview": "# CMake script to configure and build a test project\n\nset(TEST_ARG_LIST)\n\n# Expect actual arguments to start at index 3 "
  },
  {
    "path": "test/README.md",
    "chars": 421,
    "preview": "# Corrosion Tests\n\nCorrosions tests are run via ctest. The tests themselves utilize CMake script mode\nto configure and b"
  },
  {
    "path": "test/TestFileExists.cmake",
    "chars": 1118,
    "preview": "# CMake script to test if a file exists. Errors if the file does not exist.\n# Expect actual arguments to start at index "
  },
  {
    "path": "test/cargo_flags/CMakeLists.txt",
    "chars": 163,
    "preview": "corrosion_tests_add_test(cargo_flags \"flags-exe\")\n\nset_tests_properties(\"cargo_flags_run_flags-exe\" PROPERTIES PASS_REGU"
  },
  {
    "path": "test/cargo_flags/cargo_flags/CMakeLists.txt",
    "chars": 487,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/cargo_flags/cargo_flags/main.cpp",
    "chars": 117,
    "preview": "extern \"C\" void rust_function(char const *name);\n\n\nint main(int argc, char **argv) {\n        rust_function(\"Cxx\");\n}\n"
  },
  {
    "path": "test/cargo_flags/cargo_flags/rust/Cargo.toml",
    "chars": 138,
    "preview": "[package]\nname = \"flags-lib\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\ncrate-type=[\"staticlib\"]\n\n[features]\n\none = []\ntw"
  },
  {
    "path": "test/cargo_flags/cargo_flags/rust/src/lib.rs",
    "chars": 472,
    "preview": "use std::os::raw::c_char;\n\n#[no_mangle]\npub extern \"C\" fn rust_function(name: *const c_char) {\n    let name = unsafe { s"
  },
  {
    "path": "test/cbindgen/CMakeLists.txt",
    "chars": 2407,
    "preview": "corrosion_tests_add_test(cbindgen_rust2cpp_auto \"cpp-exe\" TEST_SRC_DIR auto)\ncorrosion_tests_add_test(cbindgen_manual \"c"
  },
  {
    "path": "test/cbindgen/auto/CMakeLists.txt",
    "chars": 445,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\n\nset(CORROSION_TOOLS_RUST_TOOLCHAIN \"stable\")\ni"
  },
  {
    "path": "test/cbindgen/auto/main.cpp",
    "chars": 499,
    "preview": "#include \"rust-lib.h\"\n#include <cassert>\n\nint main(int argc, char **argv) {\n    assert(is_magic_number(MAGIC_NUMBER));\n "
  },
  {
    "path": "test/cbindgen/auto/rust/Cargo.toml",
    "chars": 173,
    "preview": "[package]\nname = \"the_rust_package_name\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nedition = \"2018\"\n\n[dependencies]\n\n[lib]\ncrate"
  },
  {
    "path": "test/cbindgen/auto/rust/cbindgen.toml",
    "chars": 42,
    "preview": "language = \"C++\"\ninclude_version = true\n\n\n"
  },
  {
    "path": "test/cbindgen/auto/rust/src/ffi.rs",
    "chars": 128,
    "preview": "//! Just a module that contains some entries that should be parsed by cbindgen.\n\npub const FFI_MAGIC_NUMBER: u64 = 0xFDA"
  },
  {
    "path": "test/cbindgen/auto/rust/src/lib.rs",
    "chars": 749,
    "preview": "pub const MAGIC_NUMBER: u64 = 0xABCD_EFAB;\n\npub mod ffi;\npub mod other_mod;\n\n#[derive(Debug)]\n#[repr(C)]\npub struct Poin"
  },
  {
    "path": "test/cbindgen/auto/rust/src/other_mod/mod.rs",
    "chars": 51,
    "preview": "pub const OTHER_MOD_MAGIC_NUMBER: u32 = 192312312;\n"
  },
  {
    "path": "test/cbindgen/install_lib/CMakeLists.txt",
    "chars": 939,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\n\nset(CORROSION_TOOLS_RUST_TOOLCHAIN \"stable\")\ni"
  },
  {
    "path": "test/cbindgen/install_lib/rust_lib/Cargo.toml",
    "chars": 123,
    "preview": "[package]\nname = \"rust_lib\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[dependencies]\n\n[lib]\ncrate-type = [\"staticlib\", \"cdylib"
  },
  {
    "path": "test/cbindgen/install_lib/rust_lib/src/lib.rs",
    "chars": 87,
    "preview": "\n#[no_mangle]\npub extern \"C\" fn add(left: u64, right: u64) -> u64 {\n    left + right\n}\n"
  },
  {
    "path": "test/cbindgen/manual/CMakeLists.txt",
    "chars": 942,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\n\nset(CORROSION_TOOLS_RUST_TOOLCHAIN \"stable\")\ni"
  },
  {
    "path": "test/cbindgen/manual/main.cpp",
    "chars": 499,
    "preview": "#include \"rust-lib.h\"\n#include <cassert>\n\nint main(int argc, char **argv) {\n    assert(is_magic_number(MAGIC_NUMBER));\n "
  },
  {
    "path": "test/cbindgen/manual/rust/Cargo.toml",
    "chars": 183,
    "preview": "[package]\nname = \"the-rust-lib-package-name\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nedition = \"2018\"\n\n[dependencies]\n\n[lib]\nc"
  },
  {
    "path": "test/cbindgen/manual/rust/cbindgen.toml",
    "chars": 42,
    "preview": "language = \"C++\"\ninclude_version = true\n\n\n"
  },
  {
    "path": "test/cbindgen/manual/rust/src/ffi.rs",
    "chars": 128,
    "preview": "//! Just a module that contains some entries that should be parsed by cbindgen.\n\npub const FFI_MAGIC_NUMBER: u64 = 0xFDA"
  },
  {
    "path": "test/cbindgen/manual/rust/src/lib.rs",
    "chars": 749,
    "preview": "pub const MAGIC_NUMBER: u64 = 0xABCD_EFAB;\n\npub mod ffi;\npub mod other_mod;\n\n#[derive(Debug)]\n#[repr(C)]\npub struct Poin"
  },
  {
    "path": "test/cbindgen/manual/rust/src/other_mod/mod.rs",
    "chars": 51,
    "preview": "pub const OTHER_MOD_MAGIC_NUMBER: u32 = 192312312;\n"
  },
  {
    "path": "test/config_discovery/CMakeLists.txt",
    "chars": 685,
    "preview": "# The `.cargo/config.toml` file registers the `my-registry` index. If Cargo fails to\n# discover the config file, the bui"
  },
  {
    "path": "test/config_discovery/README.md",
    "chars": 729,
    "preview": "# Cargo Configuration Discovery Test\n\nThis test verifies that `cargo` correctly discovers configuration files such as `."
  },
  {
    "path": "test/config_discovery/config_discovery/.cargo/config.toml",
    "chars": 211,
    "preview": "# Defines registry alias `my-registry` pointing to crates.io.\n# If not discovered cargo errors: \"registry `my-registry` "
  },
  {
    "path": "test/config_discovery/config_discovery/CMakeLists.txt",
    "chars": 156,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/config_discovery/config_discovery/Cargo.toml",
    "chars": 295,
    "preview": "[package]\nname = \"config_discovery\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[dependencies]\n# Uses registry alias `my-registr"
  },
  {
    "path": "test/config_discovery/config_discovery/src/main.rs",
    "chars": 202,
    "preview": "use bitflags::bitflags;\n\nbitflags! {\n    struct TestFlags: u32 {\n        const VALUE = 0b00000001;\n    }\n}\n\nfn main() {\n"
  },
  {
    "path": "test/corrosion_install/CMakeLists.txt",
    "chars": 1324,
    "preview": "if(NOT (CMAKE_CROSSCOMPILING AND MSVC))\n    # When using MSVC the cmake build via ExternalProject seems to inherit the t"
  },
  {
    "path": "test/corrosion_install/install_lib/CMakeLists.txt",
    "chars": 1642,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(ExternalProject)\n\nadd_library(static_li"
  },
  {
    "path": "test/corrosion_install/install_lib/main.cpp",
    "chars": 252,
    "preview": "#include <stdint.h>\n#include <assert.h>\n#include <iostream>\n\nextern \"C\" uint64_t add(uint64_t a, uint64_t b);\n\nint main("
  },
  {
    "path": "test/corrosion_install/install_lib/rust_lib/CMakeLists.txt",
    "chars": 856,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../../test_header.cmake)\n\ncorrosion_"
  },
  {
    "path": "test/corrosion_install/install_lib/rust_lib/Cargo.toml",
    "chars": 123,
    "preview": "[package]\nname = \"rust_lib\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[dependencies]\n\n[lib]\ncrate-type = [\"staticlib\", \"cdylib"
  },
  {
    "path": "test/corrosion_install/install_lib/rust_lib/include/rust_lib/rust_lib.hpp",
    "chars": 78,
    "preview": "#include <cstdint.h>\n\nextern \"C\" uint64_t add(uint64_t left, uint64_t right);\n"
  },
  {
    "path": "test/corrosion_install/install_lib/rust_lib/src/lib.rs",
    "chars": 87,
    "preview": "\n#[no_mangle]\npub extern \"C\" fn add(left: u64, right: u64) -> u64 {\n    left + right\n}\n"
  },
  {
    "path": "test/corrosion_install/install_rust_bin/CMakeLists.txt",
    "chars": 1278,
    "preview": "cmake_minimum_required(VERSION 3.22)\nproject(test_project VERSION 0.1.0)\n\n# Note: Corrosion supports `hostbuild`, so bui"
  },
  {
    "path": "test/corrosion_install/install_rust_bin/rust_bin/CMakeLists.txt",
    "chars": 223,
    "preview": "cmake_minimum_required(VERSION 3.22)\nproject(test_rust_bin VERSION 0.1.0)\ninclude(../../../test_header.cmake)\ninclude(GN"
  },
  {
    "path": "test/corrosion_install/install_rust_bin/rust_bin/Cargo.toml",
    "chars": 98,
    "preview": "[package]\nname = \"my_rust_bin\"\nversion = \"0.1.0\"\nedition = \"2018\"\nlicense = \"MIT\"\n\n[dependencies]\n"
  },
  {
    "path": "test/corrosion_install/install_rust_bin/rust_bin/src/main.rs",
    "chars": 142,
    "preview": "fn main() {\n    println!(\n\"#include <iostream>\nint main() {{\n    std::cout << \\\"Hello World! I'm generated code\\\";\n    r"
  },
  {
    "path": "test/cpp2rust/CMakeLists.txt",
    "chars": 258,
    "preview": "corrosion_tests_add_test(cpp2rust \"rust-exe\")\n\nset_tests_properties(\"cpp2rust_run_rust-exe\" PROPERTIES PASS_REGULAR_EXPR"
  },
  {
    "path": "test/cpp2rust/cpp2rust/CMakeLists.txt",
    "chars": 815,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/cpp2rust/cpp2rust/lib.cpp",
    "chars": 127,
    "preview": "#include <iostream>\n\nextern \"C\" void cpp_function(char const *name) {\n    std::cout << \"Hello, \" << name << \"! I am Cpp!"
  },
  {
    "path": "test/cpp2rust/cpp2rust/lib2.cpp",
    "chars": 234,
    "preview": "#include <iostream>\n#include <stdint.h>\n\nextern \"C\" void cpp_function2(char const *name) {\n    std::cout << \"Hello, \" <<"
  },
  {
    "path": "test/cpp2rust/cpp2rust/path with space/lib3.cpp",
    "chars": 228,
    "preview": "// Check that libraries located at a path containing a space can also be linked.\n\n#include <iostream>\n\nextern \"C\" void c"
  },
  {
    "path": "test/cpp2rust/cpp2rust/rust/Cargo.toml",
    "chars": 198,
    "preview": "[package]\nname = \"rust-exe\"\nversion = \"0.1.0\"\nauthors = [\"Andrew Gaspar <andrew.gaspar@outlook.com>\"]\nlicense = \"MIT\"\ned"
  },
  {
    "path": "test/cpp2rust/cpp2rust/rust/build.rs",
    "chars": 149,
    "preview": "// Build-scripts also need to be linked, so just add a dummy buildscript ensuring this works.\nfn main() {\n    println!(\""
  },
  {
    "path": "test/cpp2rust/cpp2rust/rust/rust_dependency/Cargo.toml",
    "chars": 103,
    "preview": "[package]\nname = \"rust-dependency\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nedition = \"2018\"\n\n[dependencies]\n\n"
  },
  {
    "path": "test/cpp2rust/cpp2rust/rust/rust_dependency/src/lib.rs",
    "chars": 122,
    "preview": "\nextern \"C\" {\n    fn get_42() -> u32;\n}\npub fn calls_ffi() {\n    let res = unsafe { get_42()};\n    assert_eq!(res, 42);\n"
  },
  {
    "path": "test/cpp2rust/cpp2rust/rust/src/bin/rust-exe.rs",
    "chars": 594,
    "preview": "use std::os::raw::c_char;\n\nextern \"C\" {\n    fn cpp_function(name: *const c_char);\n    fn cpp_function2(name: *const c_ch"
  },
  {
    "path": "test/crate_type/CMakeLists.txt",
    "chars": 190,
    "preview": "corrosion_tests_add_test(crate_type \"cpp-exe\")\n\n\nset_tests_properties(\"crate_type_run_cpp-exe\" PROPERTIES PASS_REGULAR_E"
  },
  {
    "path": "test/crate_type/crate_type/CMakeLists.txt",
    "chars": 522,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\n# Add --crate"
  },
  {
    "path": "test/crate_type/crate_type/main.cpp",
    "chars": 142,
    "preview": "extern \"C\" void rust_function1();\nextern \"C\" void rust_function2();\n\nint main() {\n    rust_function1();\n    rust_functio"
  },
  {
    "path": "test/crate_type/crate_type/proj1/Cargo.toml",
    "chars": 119,
    "preview": "[package]\nname = \"proj1\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[dependencies]\n\n[lib]\ncrate-type=[\"staticlib\", \"cdylib\"]\n\n"
  },
  {
    "path": "test/crate_type/crate_type/proj1/src/lib.rs",
    "chars": 87,
    "preview": "#[no_mangle]\npub extern \"C\" fn rust_function1() {\n    println!(\"Hello from lib 1!\");\n}\n"
  },
  {
    "path": "test/crate_type/crate_type/proj2/Cargo.toml",
    "chars": 118,
    "preview": "[package]\nname = \"proj2\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[dependencies]\n\n[lib]\ncrate-type=[\"staticlib\", \"cdylib\"]\n"
  },
  {
    "path": "test/crate_type/crate_type/proj2/src/lib.rs",
    "chars": 87,
    "preview": "#[no_mangle]\npub extern \"C\" fn rust_function2() {\n    println!(\"Hello from lib 2!\");\n}\n"
  },
  {
    "path": "test/custom_profiles/CMakeLists.txt",
    "chars": 1418,
    "preview": "# The tests in this folder test specifying the cargo profile name via the --profile option.\n# The built-in `test` and `b"
  },
  {
    "path": "test/custom_profiles/basic_profiles/CMakeLists.txt",
    "chars": 450,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\nif(NOT DEFINE"
  },
  {
    "path": "test/custom_profiles/basic_profiles/main.cpp",
    "chars": 117,
    "preview": "extern \"C\" void rust_function(char const *name);\n\n\nint main(int argc, char **argv) {\n        rust_function(\"Cpp\");\n}\n"
  },
  {
    "path": "test/custom_profiles/basic_profiles/rust/Cargo.toml",
    "chars": 105,
    "preview": "[package]\nname = \"cargo-profiles-lib\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[lib]\ncrate-type=[\"staticlib\"]\n"
  },
  {
    "path": "test/custom_profiles/basic_profiles/rust/src/lib.rs",
    "chars": 218,
    "preview": "use std::os::raw::c_char;\n\n#[no_mangle]\npub extern \"C\" fn rust_function(name: *const c_char) {\n    let name = unsafe { s"
  },
  {
    "path": "test/custom_profiles/custom_profiles/CMakeLists.txt",
    "chars": 781,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\nset(_release_"
  },
  {
    "path": "test/custom_profiles/custom_profiles/main.cpp",
    "chars": 117,
    "preview": "extern \"C\" void rust_function(char const *name);\n\n\nint main(int argc, char **argv) {\n        rust_function(\"Cpp\");\n}\n"
  },
  {
    "path": "test/custom_profiles/custom_profiles/rust/Cargo.toml",
    "chars": 496,
    "preview": "[package]\nname = \"custom-profiles-lib\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[lib]\ncrate-type=[\"staticlib\"]\n\n# Test if nei"
  },
  {
    "path": "test/custom_profiles/custom_profiles/rust/src/lib.rs",
    "chars": 333,
    "preview": "use std::os::raw::c_char;\n\n#[no_mangle]\npub extern \"C\" fn rust_function(name: *const c_char) {\n    let name = unsafe { s"
  },
  {
    "path": "test/custom_target/CMakeLists.txt",
    "chars": 1170,
    "preview": "# Create a custom target triple, by taking the default host triple target spec.\n# This way we don't actually need to cro"
  },
  {
    "path": "test/custom_target/custom_target/CMakeLists.txt",
    "chars": 898,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0 LANGUAGES C CXX)\n# The outer test driver gives t"
  },
  {
    "path": "test/custom_target/custom_target/main.cpp",
    "chars": 117,
    "preview": "extern \"C\" void rust_function(char const *name);\n\n\nint main(int argc, char **argv) {\n        rust_function(\"Cxx\");\n}\n"
  },
  {
    "path": "test/custom_target/custom_target/rust/Cargo.toml",
    "chars": 180,
    "preview": "[package]\nname = \"rust-lib\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\ncrate-type=[\"staticlib\", \"lib\"]\n\n[[bin]]\nname = \"r"
  },
  {
    "path": "test/custom_target/custom_target/rust/build.rs",
    "chars": 437,
    "preview": "fn main() {\n    let mut builder = cc::Build::new();\n    // We override the target here, purely to make the testcase simp"
  },
  {
    "path": "test/custom_target/custom_target/rust/c_lib.c",
    "chars": 67,
    "preview": "#include <stdint.h>\n\nuint32_t calculate_42(void) {\n    return 42;\n}"
  },
  {
    "path": "test/custom_target/custom_target/rust/src/bin.rs",
    "chars": 130,
    "preview": "use rust_lib::calculate_42;\n\nfn main() {\n    let answer = unsafe { calculate_42() } ;\n    println!(\"The answer is {}\", a"
  },
  {
    "path": "test/custom_target/custom_target/rust/src/lib.rs",
    "chars": 334,
    "preview": "use std::os::raw::c_char;\n\nextern \"C\" {\n    pub fn calculate_42() -> u32;\n}\n\n#[no_mangle]\npub extern \"C\" fn rust_functio"
  },
  {
    "path": "test/cxxbridge/CMakeLists.txt",
    "chars": 1515,
    "preview": "if(CORROSION_TESTS_CXXBRIDGE)\n    corrosion_tests_add_test(cxxbridge_cpp2rust_1 \"rust_bin\"\n        TEST_SRC_DIR cxxbridg"
  },
  {
    "path": "test/cxxbridge/cxxbridge_circular/CMakeLists.txt",
    "chars": 2107,
    "preview": "# This CMake project tests the setup for circular dependencies that involve a CXX bridge\n# While circular dependencies a"
  },
  {
    "path": "test/cxxbridge/cxxbridge_circular/cpplib.cpp",
    "chars": 427,
    "preview": "#include \"cpplib.h\"\n#include \"cxxbridge/lib.h\"\n#include \"rust/cxx.h\"\n#include <iostream>\n\nRsImage read_image(rust::Str p"
  },
  {
    "path": "test/cxxbridge/cxxbridge_circular/include/cpplib.h",
    "chars": 106,
    "preview": "#pragma once\n#include \"cxxbridge/lib.h\"\n\n::RsImage read_image(::rust::Str path);\n\nvoid assert_equality();\n"
  },
  {
    "path": "test/cxxbridge/cxxbridge_circular/main.cpp",
    "chars": 307,
    "preview": "#include \"cpplib.h\"\n\n#include <iostream>\n\nint main(void) {\n  std::cout << \"Testing roundtrip...\" << std::endl;\n\n  try {\n"
  },
  {
    "path": "test/cxxbridge/cxxbridge_circular/rust/Cargo.toml",
    "chars": 143,
    "preview": "[package]\nname = \"rust_lib\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\nname = \"rust_lib\"\ncrate-type = [\"staticlib\"]\n\n[dep"
  },
  {
    "path": "test/cxxbridge/cxxbridge_circular/rust/src/lib.rs",
    "chars": 637,
    "preview": "#[cxx::bridge]\npub mod ffi {\n    #[derive(Debug, PartialEq)]\n    pub struct Rgba {\n        r: f32,\n        g: f32,\n     "
  },
  {
    "path": "test/cxxbridge/cxxbridge_cpp2rust/CMakeLists.txt",
    "chars": 1559,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0 LANGUAGES CXX)\ninclude(../../test_header.cmake)\n"
  },
  {
    "path": "test/cxxbridge/cxxbridge_cpp2rust/cpplib.cpp",
    "chars": 363,
    "preview": "#include <iostream>\n#include \"cpplib.h\"\n#include \"cxxbridge-cpp/lib.h\"\n#include \"rust/cxx.h\"\n\nRsImage read_image(rust::S"
  },
  {
    "path": "test/cxxbridge/cxxbridge_cpp2rust/include/cpplib.h",
    "chars": 146,
    "preview": "#pragma once\n#include \"cxxbridge-cpp/lib.h\"\n\n::RsImage read_image(::rust::Str path);\nvoid write_image(::rust::Str path, "
  },
  {
    "path": "test/cxxbridge/cxxbridge_cpp2rust/rust/Cargo.toml",
    "chars": 121,
    "preview": "[package]\nname = \"rust_bin\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\nname = \"cxxbridge_lib\"\n\n[dependencies]\ncxx = \"1.0\""
  },
  {
    "path": "test/cxxbridge/cxxbridge_cpp2rust/rust/src/lib.rs",
    "chars": 461,
    "preview": "#[cxx::bridge]\npub mod ffi\n{\n    #[derive(Debug, PartialEq)]\n    pub struct Rgba\n    {\n        r: f32,\n        g: f32,\n "
  },
  {
    "path": "test/cxxbridge/cxxbridge_cpp2rust/rust/src/main.rs",
    "chars": 344,
    "preview": "use cxxbridge_lib::ffi::{RsImage,Rgba,read_image};\n\nfn main() {\n    println!(\"main function\");\n    let expected = RsImag"
  },
  {
    "path": "test/cxxbridge/cxxbridge_exported_impls/CMakeLists.txt",
    "chars": 552,
    "preview": "cmake_minimum_required(VERSION 3.24)\nproject(test_project VERSION 0.1.0 LANGUAGES CXX)\ninclude(../../test_header.cmake)\n"
  },
  {
    "path": "test/cxxbridge/cxxbridge_exported_impls/main.cpp",
    "chars": 236,
    "preview": "#include \"cxxbridge/lib.h\"\n\n#include <iostream>\n\nint main()\n{\n    auto result = make_result();\n\n    std::cout << static_"
  },
  {
    "path": "test/cxxbridge/cxxbridge_exported_impls/rust/Cargo.toml",
    "chars": 143,
    "preview": "[package]\nname = \"rust_lib\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\nname = \"rust_lib\"\ncrate-type = [\"staticlib\"]\n\n[dep"
  },
  {
    "path": "test/cxxbridge/cxxbridge_exported_impls/rust/src/bridge_a.rs",
    "chars": 531,
    "preview": "#[cxx::bridge]\npub mod ffi {\n    pub struct OkResult {\n        pub value: bool,\n        pub message: String,\n    }\n\n    "
  },
  {
    "path": "test/cxxbridge/cxxbridge_exported_impls/rust/src/bridge_b.rs",
    "chars": 442,
    "preview": "#[cxx::bridge]\npub mod ffi {\n\n    #[derive(Clone)]\n    pub struct NewVal {\n        pub value: bool,\n        pub message:"
  },
  {
    "path": "test/cxxbridge/cxxbridge_exported_impls/rust/src/lib.rs",
    "chars": 853,
    "preview": "pub mod bridge_a;\npub mod bridge_b;\n// pub use bridge_a::combine_result;\n\n#[cxx::bridge]\npub mod ffi {\n\n    extern \"C++\""
  },
  {
    "path": "test/cxxbridge/cxxbridge_rust2cpp/CMakeLists.txt",
    "chars": 594,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\nset(CMAKE_CXX_"
  },
  {
    "path": "test/cxxbridge/cxxbridge_rust2cpp/main.cpp",
    "chars": 287,
    "preview": "#include <cxxbridge-cpp/foo/mod.h>\n#include <cxxbridge-cpp/lib.h>\n#include <vector>\n\nint main(int argc, char **argv)\n{\n "
  },
  {
    "path": "test/cxxbridge/cxxbridge_rust2cpp/rust/Cargo.toml",
    "chars": 132,
    "preview": "[package]\nname = \"cxxbridge-crate\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\ncrate-type = [\"staticlib\"]\n\n[dependencies]\n"
  },
  {
    "path": "test/cxxbridge/cxxbridge_rust2cpp/rust/src/foo/mod.rs",
    "chars": 199,
    "preview": "#[cxx::bridge(namespace = \"foo\")]\nmod bridge {\n    extern \"Rust\" {\n        fn print(slice: &[u64]);\n    }\n}\n\nfn print(sl"
  },
  {
    "path": "test/cxxbridge/cxxbridge_rust2cpp/rust/src/lib.rs",
    "chars": 205,
    "preview": "mod foo;\n\n#[cxx::bridge(namespace = \"lib\")]\nmod bridge {\n    extern \"Rust\" {\n        fn print(slice: &[u64]);\n    }\n}\n\nf"
  },
  {
    "path": "test/envvar/CMakeLists.txt",
    "chars": 206,
    "preview": "corrosion_tests_add_test(envvar \"program_requiring_rust_lib_with_envvar\")\n\nset_tests_properties(\"envvar_run_program_requ"
  },
  {
    "path": "test/envvar/envvar/.cargo/config.toml",
    "chars": 63,
    "preview": "[env]\nCOR_CONFIG_TOML_ENV_VAR = \"EnvVariableSetViaConfig.toml\"\n"
  },
  {
    "path": "test/envvar/envvar/CMakeLists.txt",
    "chars": 768,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/envvar/envvar/Cargo.toml",
    "chars": 192,
    "preview": "[package]\nname = \"rust-lib-requiring-envvar\"\nversion = \"0.1.0\"\nauthors = [\"Olivier Goffart <ogoffart@sixtyfps.io>\"]\nedit"
  },
  {
    "path": "test/envvar/envvar/build.rs",
    "chars": 855,
    "preview": "fn main() {\n    assert_eq!(env!(\"REQUIRED_VARIABLE\"), \"EXPECTED_VALUE\");\n    assert_eq!(std::env::var(\"ANOTHER_VARIABLE\""
  },
  {
    "path": "test/envvar/envvar/main.cpp",
    "chars": 59,
    "preview": "#include <iostream>\n\nint main() {\n    std::cout << \"Ok\";\n}\n"
  },
  {
    "path": "test/envvar/envvar/src/lib.rs",
    "chars": 95,
    "preview": "#[cfg(test)]\nmod tests {\n    #[test]\n    fn it_works() {\n        assert_eq!(2 + 2, 4);\n    }\n}\n"
  },
  {
    "path": "test/features/CMakeLists.txt",
    "chars": 283,
    "preview": "corrosion_tests_add_test(features \"features-cpp-exe\")\n\nset_tests_properties(\"features_run_features-cpp-exe\" PROPERTIES P"
  },
  {
    "path": "test/features/features/CMakeLists.txt",
    "chars": 665,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/features/features/main.cpp",
    "chars": 383,
    "preview": "extern \"C\" void rust_function(char const *name);\nextern \"C\" void rust_second_function(char const *name);\nextern \"C\" void"
  },
  {
    "path": "test/features/features/rust/Cargo.toml",
    "chars": 307,
    "preview": "[package]\nname = \"rust-feature-lib\"\nversion = \"0.1.0\"\nauthors = [\"Andrew Gaspar <andrew.gaspar@outlook.com>\"]\nlicense = "
  },
  {
    "path": "test/features/features/rust/src/lib.rs",
    "chars": 927,
    "preview": "#[cfg(feature = \"myfeature\")]\nuse std::os::raw::c_char;\n\n#[no_mangle]\n#[cfg(feature = \"myfeature\")]\npub extern \"C\" fn ru"
  },
  {
    "path": "test/find_rust/CMakeLists.txt",
    "chars": 221,
    "preview": "corrosion_tests_add_test(find_rust \"\")\ncorrosion_tests_add_test(rustup_proxy \"\")\n\nfind_program(rustup rustup)\nif(NOT rus"
  },
  {
    "path": "test/find_rust/find_rust/CMakeLists.txt",
    "chars": 267,
    "preview": "\ncmake_minimum_required(VERSION 3.15)\nproject(FindRust LANGUAGES CXX)\n\nset(CMAKE_MODULE_PATH \"${CMAKE_SOURCE_DIR}/../../"
  },
  {
    "path": "test/find_rust/rustup_proxy/CMakeLists.txt",
    "chars": 1301,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(RustupProxy LANGUAGES CXX)\n\nset(CMAKE_MODULE_PATH \"${CMAKE_SOURCE_DIR}/../."
  },
  {
    "path": "test/gensource/CMakeLists.txt",
    "chars": 270,
    "preview": "corrosion_tests_add_test(gensource \"\")\n\n#set_tests_properties(\"features_run_features-cpp-exe\" PROPERTIES PASS_REGULAR_EX"
  },
  {
    "path": "test/gensource/gensource/.gitignore",
    "chars": 11,
    "preview": "src/foo.rs\n"
  },
  {
    "path": "test/gensource/gensource/CMakeLists.txt",
    "chars": 1055,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\nadd_subdirect"
  },
  {
    "path": "test/gensource/gensource/Cargo.toml",
    "chars": 215,
    "preview": "[package]\nname = \"generated\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\ncrate-type = [\"lib\", \"cdylib\"]\n# See more keys an"
  },
  {
    "path": "test/gensource/gensource/generator/CMakeLists.txt",
    "chars": 81,
    "preview": "corrosion_import_crate(MANIFEST_PATH Cargo.toml)\ncorrosion_set_hostbuild(srcgen)\n"
  },
  {
    "path": "test/gensource/gensource/generator/Cargo.toml",
    "chars": 175,
    "preview": "[package]\nname = \"srcgen\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n# See more keys and their definitions at https://doc.rust-"
  },
  {
    "path": "test/gensource/gensource/generator/src/main.rs",
    "chars": 229,
    "preview": "use std::io::Write;\nfn main() -> Result<(), std::io::Error> {\n    let out_name = std::env::args().skip(1).next().unwrap("
  },
  {
    "path": "test/gensource/gensource/src/lib.rs",
    "chars": 134,
    "preview": "mod foo;\n\n#[cfg(test)]\nmod tests {\n    #[test]\n    fn it_works() {\n        let result = 2 + 2;\n        assert_eq!(result"
  },
  {
    "path": "test/hostbuild/CMakeLists.txt",
    "chars": 239,
    "preview": "corrosion_tests_add_test(hostbuild \"rust-host-program\" IS_HOSTBUILD)\n\nset_tests_properties(\"hostbuild_run_rust-host-prog"
  },
  {
    "path": "test/hostbuild/hostbuild/CMakeLists.txt",
    "chars": 228,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/hostbuild/hostbuild/Cargo.toml",
    "chars": 158,
    "preview": "[package]\nname = \"rust-host-program\"\nversion = \"0.1.0\"\nauthors = [\"Olivier Goffart <ogoffart@sixtyfps.io>\"]\nedition = \"2"
  },
  {
    "path": "test/hostbuild/hostbuild/build.rs",
    "chars": 296,
    "preview": "fn main() {\n    let out_dir = std::env::var(\"OUT_DIR\").unwrap();\n    cc::Build::new()\n        .file(\"src/lib.c\")\n       "
  },
  {
    "path": "test/hostbuild/hostbuild/src/lib.c",
    "chars": 118,
    "preview": "#include <stdio.h>\n\nvoid c_function(char const *name) {\n   printf(\"Hello %s, I am an external C function\\n\", name);\n}\n"
  },
  {
    "path": "test/hostbuild/hostbuild/src/main.rs",
    "chars": 212,
    "preview": "use std::os::raw::c_char;\n\nextern \"C\" {\n    fn c_function(name: *const c_char);\n}\n\nfn main() {\n    println!(\"ok\");\n    l"
  },
  {
    "path": "test/multitarget/CMakeLists.txt",
    "chars": 738,
    "preview": "corrosion_tests_add_test(multitarget \"bin1;bin2;bin3\")\n\n# Don't run this test in parallel with others, since the target "
  },
  {
    "path": "test/multitarget/multitarget/CMakeLists.txt",
    "chars": 428,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/multitarget/multitarget/Cargo.toml",
    "chars": 231,
    "preview": "[package]\nname = \"multitarget-crate\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[dependencies]\n\n[lib]\nname = \"multitarget_lib\"\n"
  },
  {
    "path": "test/multitarget/multitarget/lib.cpp",
    "chars": 126,
    "preview": "#include <iostream>\n\nextern \"C\" void cpp_function(char const *name) {\n    std::cout << \"Hello, \" << name << \"! I'm Cpp!\\"
  },
  {
    "path": "test/multitarget/multitarget/src/bin/bin1.rs",
    "chars": 157,
    "preview": "use multitarget_lib::hello_world;\n\nfn main() {\n    hello_world();\n    unsafe {\n        multitarget_lib::cpp_function(\"bi"
  },
  {
    "path": "test/multitarget/multitarget/src/bin/bin2.rs",
    "chars": 157,
    "preview": "use multitarget_lib::hello_world;\n\nfn main() {\n    hello_world();\n    unsafe {\n        multitarget_lib::cpp_function(\"bi"
  },
  {
    "path": "test/multitarget/multitarget/src/bin/bin3.rs",
    "chars": 157,
    "preview": "use multitarget_lib::hello_world;\n\nfn main() {\n    hello_world();\n    unsafe {\n        multitarget_lib::cpp_function(\"bi"
  },
  {
    "path": "test/multitarget/multitarget/src/lib.rs",
    "chars": 145,
    "preview": "use std::os::raw::c_char;\n\npub fn hello_world() {\n    println!(\"Hello, world!\");\n}\n\nextern \"C\" {\n    pub fn cpp_function"
  },
  {
    "path": "test/nostd/CMakeLists.txt",
    "chars": 35,
    "preview": "corrosion_tests_add_test(nostd \"\")\n"
  },
  {
    "path": "test/nostd/nostd/CMakeLists.txt",
    "chars": 397,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/nostd/nostd/main.cpp",
    "chars": 119,
    "preview": "extern \"C\" void rust_function();\n\nextern \"C\" void cpp_function() {\n    // Fail on linking issues\n    rust_function();\n}"
  },
  {
    "path": "test/nostd/nostd/rust/Cargo.toml",
    "chars": 281,
    "preview": "[package]\nname = \"rust-nostd-lib\"\nversion = \"0.1.0\"\nedition = \"2015\"\n\n# See more keys and their definitions at https://d"
  },
  {
    "path": "test/nostd/nostd/rust/src/lib.rs",
    "chars": 161,
    "preview": "#![no_std]\nuse core::panic::PanicInfo;\n\n#[no_mangle]\npub extern \"C\" fn rust_function() {}\n\n#[panic_handler]\nfn panic(_pa"
  },
  {
    "path": "test/output directory/CMakeLists.txt",
    "chars": 7802,
    "preview": "set(configure_cmake_args)\nif(CMAKE_C_COMPILER)\n    list(APPEND configure_cmake_args \"C_COMPILER\" \"${CMAKE_C_COMPILER}\")\n"
  },
  {
    "path": "test/output directory/output directory/CMakeLists.txt",
    "chars": 2522,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/output directory/output directory/consumer.cpp",
    "chars": 228,
    "preview": "#include <iostream>\n#include <cstdlib>\n\nextern \"C\" unsigned int ret_12();\n\n\nint main(int argc, char *argv[])\n{\n    std::"
  },
  {
    "path": "test/output directory/output directory/proj1/Cargo.toml",
    "chars": 157,
    "preview": "[package]\nname = \"rust_package1\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\nname = \"rust_lib1\"\ncrate-type=[\"staticlib\", \""
  },
  {
    "path": "test/output directory/output directory/proj1/src/bin/rust_bin1.rs",
    "chars": 66,
    "preview": "fn main() {\n    println!(\"Hello, world from test rust binary\");\n}\n"
  },
  {
    "path": "test/output directory/output directory/proj1/src/lib.rs",
    "chars": 58,
    "preview": "#[no_mangle]\npub extern \"C\" fn ret_12() -> u32 {\n    12\n}\n"
  },
  {
    "path": "test/output directory/output directory/proj2/Cargo.toml",
    "chars": 157,
    "preview": "[package]\nname = \"rust_package2\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\nname = \"rust_lib2\"\ncrate-type=[\"staticlib\", \""
  },
  {
    "path": "test/output directory/output directory/proj2/src/bin/rust_bin2.rs",
    "chars": 66,
    "preview": "fn main() {\n    println!(\"Hello, world from test rust binary\");\n}\n"
  },
  {
    "path": "test/output directory/output directory/proj2/src/lib.rs",
    "chars": 58,
    "preview": "#[no_mangle]\npub extern \"C\" fn ret_12() -> u32 {\n    12\n}\n"
  },
  {
    "path": "test/output directory/output directory/proj3/Cargo.toml",
    "chars": 157,
    "preview": "[package]\nname = \"rust_package3\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\nname = \"rust_lib3\"\ncrate-type=[\"staticlib\", \""
  },
  {
    "path": "test/output directory/output directory/proj3/src/bin/rust_bin3.rs",
    "chars": 66,
    "preview": "fn main() {\n    println!(\"Hello, world from test rust binary\");\n}\n"
  },
  {
    "path": "test/output directory/output directory/proj3/src/lib.rs",
    "chars": 58,
    "preview": "#[no_mangle]\npub extern \"C\" fn ret_12() -> u32 {\n    12\n}\n"
  },
  {
    "path": "test/output directory/output_directory_config/CMakeLists.txt",
    "chars": 958,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/output directory/output_directory_config/consumer.cpp",
    "chars": 276,
    "preview": "#include <iostream>\n#include <cstdlib>\n\nextern \"C\" unsigned int ret_12();\n\n\nint main(int argc, char *argv[])\n{\n    std::"
  },
  {
    "path": "test/output directory/output_directory_config/proj1/Cargo.toml",
    "chars": 157,
    "preview": "[package]\nname = \"rust_package1\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[lib]\nname = \"rust_lib1\"\ncrate-type=[\"staticlib\", \""
  },
  {
    "path": "test/output directory/output_directory_config/proj1/src/bin/rust_bin1.rs",
    "chars": 66,
    "preview": "fn main() {\n    println!(\"Hello, world from test rust binary\");\n}\n"
  },
  {
    "path": "test/output directory/output_directory_config/proj1/src/lib.rs",
    "chars": 58,
    "preview": "#[no_mangle]\npub extern \"C\" fn ret_12() -> u32 {\n    12\n}\n"
  },
  {
    "path": "test/override_crate_type/CMakeLists.txt",
    "chars": 358,
    "preview": "corrosion_tests_add_test(override_crate_type \"cpp-exe;cpp-exe-shared\")\n\nset_tests_properties(\"override_crate_type_run_cp"
  },
  {
    "path": "test/override_crate_type/override_crate_type/CMakeLists.txt",
    "chars": 407,
    "preview": "cmake_minimum_required(VERSION 3.15)\nproject(test_project VERSION 0.1.0)\ninclude(../../test_header.cmake)\n\ncorrosion_imp"
  },
  {
    "path": "test/override_crate_type/override_crate_type/main.cpp",
    "chars": 187,
    "preview": "extern \"C\" void rust_function(char const *name);\n\nint main(int argc, char **argv) {\n    if (argc < 2) {\n        rust_fun"
  }
]

// ... and 33 more files (download for full content)

About this extraction

This page contains the full source code of the AndrewGaspar/corrosion GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 233 files (363.2 KB), approximately 99.1k tokens, and a symbol index with 138 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!