From 6c7d3512571ef8631eae0b7b19dae532c41181e5 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Tue, 15 Jun 2021 15:48:41 -0700 Subject: [PATCH 1/2] Call cbindgen manually instead of in build.rs. --- src/Simulation/qdk_sim_rs/Cargo.toml.template | 7 +++--- src/Simulation/qdk_sim_rs/build.rs | 24 +------------------ src/Simulation/qdk_sim_rs/docs/c-api.md | 8 ++++--- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/Simulation/qdk_sim_rs/Cargo.toml.template b/src/Simulation/qdk_sim_rs/Cargo.toml.template index 64e8483c780..2d9006e9dce 100644 --- a/src/Simulation/qdk_sim_rs/Cargo.toml.template +++ b/src/Simulation/qdk_sim_rs/Cargo.toml.template @@ -11,9 +11,11 @@ description = "Experimental simulators for use with the Quantum Development Kit. homepage = "https://github.com/microsoft/qsharp-runtime" repository = "https://github.com/microsoft/qsharp-runtime" -# 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 Python sources or build artifacts. + "*.egg-info", "qdk_sim_experimental", "setup.py", "*.whl", "pyproject.toml" ] [lib] @@ -72,7 +74,6 @@ built = "0.5.0" [build-dependencies] built = "0.5.0" -cbindgen = "0.19.0" [dev-dependencies] diff --git a/src/Simulation/qdk_sim_rs/build.rs b/src/Simulation/qdk_sim_rs/build.rs index aae76e31ea3..52562de4dd0 100644 --- a/src/Simulation/qdk_sim_rs/build.rs +++ b/src/Simulation/qdk_sim_rs/build.rs @@ -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(()) } diff --git a/src/Simulation/qdk_sim_rs/docs/c-api.md b/src/Simulation/qdk_sim_rs/docs/c-api.md index 11d152bafe3..6a2216d3874 100644 --- a/src/Simulation/qdk_sim_rs/docs/c-api.md +++ b/src/Simulation/qdk_sim_rs/docs/c-api.md @@ -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 @@ -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 ``` From 6e7bd951a44fa5f938e203fa4bd907a1bc0a4017 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Tue, 15 Jun 2021 16:11:23 -0700 Subject: [PATCH 2/2] Updated metadata in Cargo.toml. --- src/Simulation/qdk_sim_rs/Cargo.toml.template | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Simulation/qdk_sim_rs/Cargo.toml.template b/src/Simulation/qdk_sim_rs/Cargo.toml.template index 2d9006e9dce..f589d6d411b 100644 --- a/src/Simulation/qdk_sim_rs/Cargo.toml.template +++ b/src/Simulation/qdk_sim_rs/Cargo.toml.template @@ -4,16 +4,19 @@ [package] name = "qdk_sim_experimental" version = "0.1.0" -authors = ["Christopher Granade "] +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 = [ # 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" ]