Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Simulation/qdk_sim_rs/Cargo.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
[package]
name = "qdk_sim_experimental"
version = "0.1.0"
authors = ["Christopher Granade <cgranade@cgranade.com>"]
authors = ["Microsoft"]
edition = "2018"
license = "MIT"
description = "Experimental simulators for use with the Quantum Development Kit."
homepage = "https://github.com/microsoft/qsharp-runtime"
repository = "https://github.com/microsoft/qsharp-runtime"
readme = "README.md"

# Exclude files specific to QDK build pipelines.
exclude = [
"*.template", "*.csx", "*.ps1", "NuGet.Config", "drops"
# Exclude files specific to QDK build pipelines.
"*.template", "*.csx", "*.ps1", "NuGet.Config", "drop",
# Don't include cbindgen configs and outputs.
"include", "cbindgen.toml",
# Don't include Python sources or build artifacts.
"*.egg-info", "qdk_sim_experimental", "setup.py", "*.whl", "pyproject.toml"
]

[lib]
Expand Down Expand Up @@ -72,7 +77,6 @@ built = "0.5.0"

[build-dependencies]
built = "0.5.0"
cbindgen = "0.19.0"


[dev-dependencies]
Expand Down
24 changes: 1 addition & 23 deletions src/Simulation/qdk_sim_rs/build.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

extern crate cbindgen;

use std::env;
use std::path::Path;

fn main() -> Result<(), String> {
built::write_built_file().expect("Failed to acquire build-time information");

let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();

cbindgen::generate_with_config(
&crate_dir,
cbindgen::Config {
language: cbindgen::Language::C,
..Default::default()
},
)
.map_err(|e| e.to_string())?
.write_to_file("include/qdk_sim.h");

cbindgen::generate_with_config(
&crate_dir,
cbindgen::Config {
..Default::default()
},
)
.map_err(|e| e.to_string())?
.write_to_file("include/qdk_sim.hpp");

Ok(())
}
8 changes: 5 additions & 3 deletions src/Simulation/qdk_sim_rs/docs/c-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ API.
The [`qdk_sim`](..) crate has enabled the use of [`cbindgen`](https://crates.io/crates/cbindgen), such that C-language header files are generated automatically as part of the build for this crate.

```bash
cargo build
cargo install --force cbindgen
cbindgen --language C --output include/qdk_sim.h
cbindgen --language C++ --output include/qdk_sim.hpp
```

This will generate `include/qdk_sim.h`, which can then be used from C callers:
This will generate `include/qdk_sim.h` and `include/qdk_sim.hpp, which can then be used from C and C++ callers, respectively. For example, to call from C:

```c
#include <stdio.h>
Expand All @@ -45,7 +47,7 @@ int main() {
To build and run the above example using Clang on Windows:

```bash
$ clang docs/example.c -Iinclude -Ltarget/debug -lqdk_sim -lws2_32 -lAdvapi32 -lUserenv
$ clang example.c -Iinclude -Ltarget/debug -lqdk_sim -lws2_32 -lAdvapi32 -lUserenv
got 1 1
```

Expand Down