From eae5bd0edef3fcb5269584f26d5a98762bc2474a Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Thu, 11 Nov 2021 13:19:26 -0800 Subject: [PATCH 1/5] Use cargo-edit instead of dotnet-script to inject versions. --- bootstrap.ps1 | 11 +-- .../qdk_sim_rs/.config/dotnet-tools.json | 12 --- src/Simulation/qdk_sim_rs/Cargo.toml.template | 92 ------------------- 3 files changed, 2 insertions(+), 113 deletions(-) delete mode 100644 src/Simulation/qdk_sim_rs/.config/dotnet-tools.json delete mode 100644 src/Simulation/qdk_sim_rs/Cargo.toml.template diff --git a/bootstrap.ps1 b/bootstrap.ps1 index 44db7e6c17a..6a4ada722c6 100644 --- a/bootstrap.ps1 +++ b/bootstrap.ps1 @@ -7,16 +7,9 @@ Push-Location (Join-Path $PSScriptRoot "build") .\prerequisites.ps1 Pop-Location +cargo install cargo-edit Push-Location (Join-Path $PSScriptRoot "./src/Simulation/qdk_sim_rs") - # We use dotnet-script to inject the version number into Cargo.toml, - # so we go on ahead here and restore any missing tools. - # Since that Cargo.toml is referenced by CMake lists in the QIR - # runtime, this injection has to be the first thing we do. - dotnet tool restore - dotnet script inject-version.csx -- ` - --template Cargo.toml.template ` - --out-path Cargo.toml ` - --version $Env:NUGET_VERSION; + cargo set-version $Env:NUGET_VERSION; Pop-Location if (-not (Test-Path Env:/AGENT_OS)) { # If not CI build, i.e. local build (if AGENT_OS envvar is not defined) diff --git a/src/Simulation/qdk_sim_rs/.config/dotnet-tools.json b/src/Simulation/qdk_sim_rs/.config/dotnet-tools.json deleted file mode 100644 index 8e180ea3016..00000000000 --- a/src/Simulation/qdk_sim_rs/.config/dotnet-tools.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": 1, - "isRoot": true, - "tools": { - "dotnet-script": { - "version": "1.1.0", - "commands": [ - "dotnet-script" - ] - } - } -} \ No newline at end of file diff --git a/src/Simulation/qdk_sim_rs/Cargo.toml.template b/src/Simulation/qdk_sim_rs/Cargo.toml.template deleted file mode 100644 index f589d6d411b..00000000000 --- a/src/Simulation/qdk_sim_rs/Cargo.toml.template +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -[package] -name = "qdk_sim_experimental" -version = "0.1.0" -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" -] - -[lib] -name = "qdk_sim" -path = "src/lib.rs" -crate-type = ["rlib", "staticlib", "cdylib"] - -# Optional build-time features: we use this to create Python and WASM bindings. -[features] -default = [] -wasm = ["web-sys"] -# When Python bindings are enabled, we also need the pyo3 dependency. -python = ["pyo3", "numpy"] - -# Enable LaTeX on docs.rs. -# See https://stackoverflow.com/a/54573800/267841 and -# https://github.com/rust-num/num/pull/226/files for why this works. -[package.metadata.docs.rs] -rustdoc-args = [ "--html-in-header", "docs-includes/header.html", "--html-after-content", "docs-includes/after.html" ] - - -[profile.release] -opt-level = 3 -codegen-units = 1 # Reduce number of codegen units to increase optimizations. -panic = 'unwind' - -[dependencies] -ndarray = { version = "0.15.2", features = ["serde"] } -num-complex = { version = "0.4", features = ["serde"] } -num-traits = "0.2" -derive_more = "0.99.10" -itertools = "0.9.0" -rand = { version = "0.7.3", features = ["alloc"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -lazy_static = "1.4.0" -cfg-if = "1.0.0" -num_enum = "0.5.1" -# See https://github.com/rust-random/rand/issues/990 -# and https://docs.rs/getrandom/0.1.15/getrandom/index.html#support-for-webassembly-and-asmjs -# for why this is needed. -# NB: We depend on 0.1.15, since that's what gets brought in transitively -# by rand and rand_core. -getrandom = { version = "0.1.15", features = ["wasm-bindgen"] } - -# We only need web-sys when compiling with the wasm feature. -web-sys = { version = "0.3.4", features = ['console'], optional = true } - -# We only need PyO3 when generating Python bindings. -pyo3 = { version = "0.13.2", features = ["extension-module"], optional = true } -numpy = {version = "0.13.1", optional = true} - -# We use built to expose compile-time metadata about how this crate -# was built to C and Rust callers. -built = "0.5.0" - -[build-dependencies] -built = "0.5.0" - - -[dev-dependencies] -assert-json-diff = "2.0.1" -criterion = { version = "0.3", features = ['html_reports', 'csv_output'] } - -[[bench]] -name = "c_api_benchmark" -harness = false - -[[bench]] -name = "microbenchmark" -harness = false From 890d7bffa89d78db9488949cbcdca596b3749184 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Thu, 11 Nov 2021 13:20:12 -0800 Subject: [PATCH 2/5] Remove unused script. --- src/Simulation/qdk_sim_rs/inject-version.csx | 39 -------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/Simulation/qdk_sim_rs/inject-version.csx diff --git a/src/Simulation/qdk_sim_rs/inject-version.csx b/src/Simulation/qdk_sim_rs/inject-version.csx deleted file mode 100644 index ec71338f066..00000000000 --- a/src/Simulation/qdk_sim_rs/inject-version.csx +++ /dev/null @@ -1,39 +0,0 @@ -#r "nuget: System.CommandLine, 2.0.0-beta1.21216.1" -#r "nuget: Tommy, 2.0.0" - -using System.CommandLine; -using System.Linq; -using System.CommandLine.Invocation; -using Tommy; - -// Create a root command with some options -var rootCommand = new RootCommand -{ - new Option( - "--template", - description: "A file to use as the template for cargo manifest."), - new Option( - "--out-path", - description: "Path to write the generated manifest to."), - new Option( - "--version", - description: "The version number to inject.") -}; - -// Note that the parameters of the handler method are matched according to the names of the options -rootCommand.Handler = CommandHandler.Create((template, outPath, version) => -{ - Console.Out.WriteLine($"Injecting version {version} into {template} and writing to {outPath}."); - using var reader = new StreamReader(File.OpenRead(template.FullName)); - var table = TOML.Parse(reader); - - // Set the version number in the table. - table["package"]["version"] = version; - - using var writer = new StreamWriter(File.OpenWrite(outPath)); - table.WriteTo(writer); - // Remember to flush the data if needed! - writer.Flush(); -}); - -await rootCommand.InvokeAsync(Args.ToArray()); From 7b78596cff71dcac43a4e1e03e1a36c0f9967b7c Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Thu, 11 Nov 2021 14:54:26 -0800 Subject: [PATCH 3/5] Fix missing Cargo.toml. --- src/Simulation/qdk_sim_rs/.gitignore | 2 - src/Simulation/qdk_sim_rs/Cargo.toml | 92 ++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/Simulation/qdk_sim_rs/Cargo.toml diff --git a/src/Simulation/qdk_sim_rs/.gitignore b/src/Simulation/qdk_sim_rs/.gitignore index a740f3ce698..0af728fc99f 100644 --- a/src/Simulation/qdk_sim_rs/.gitignore +++ b/src/Simulation/qdk_sim_rs/.gitignore @@ -4,8 +4,6 @@ win10 target drop -# We inject version numbers into Cargo.toml, so don't want them stored in repo. -Cargo.toml # In the future, it would be good to enable reproducible builds by committing # the lockfile and using --locked in calls to cargo. Cargo.lock diff --git a/src/Simulation/qdk_sim_rs/Cargo.toml b/src/Simulation/qdk_sim_rs/Cargo.toml new file mode 100644 index 00000000000..3855ffe6a13 --- /dev/null +++ b/src/Simulation/qdk_sim_rs/Cargo.toml @@ -0,0 +1,92 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +[package] +name = "qdk_sim_experimental" +version = "0.0.1-alpha" +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" +] + +[lib] +name = "qdk_sim" +path = "src/lib.rs" +crate-type = ["rlib", "staticlib", "cdylib"] + +# Optional build-time features: we use this to create Python and WASM bindings. +[features] +default = [] +wasm = ["web-sys"] +# When Python bindings are enabled, we also need the pyo3 dependency. +python = ["pyo3", "numpy"] + +# Enable LaTeX on docs.rs. +# See https://stackoverflow.com/a/54573800/267841 and +# https://github.com/rust-num/num/pull/226/files for why this works. +[package.metadata.docs.rs] +rustdoc-args = [ "--html-in-header", "docs-includes/header.html", "--html-after-content", "docs-includes/after.html" ] + + +[profile.release] +opt-level = 3 +codegen-units = 1 # Reduce number of codegen units to increase optimizations. +panic = 'unwind' + +[dependencies] +ndarray = { version = "0.15.2", features = ["serde"] } +num-complex = { version = "0.4", features = ["serde"] } +num-traits = "0.2" +derive_more = "0.99.10" +itertools = "0.9.0" +rand = { version = "0.7.3", features = ["alloc"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +lazy_static = "1.4.0" +cfg-if = "1.0.0" +num_enum = "0.5.1" +# See https://github.com/rust-random/rand/issues/990 +# and https://docs.rs/getrandom/0.1.15/getrandom/index.html#support-for-webassembly-and-asmjs +# for why this is needed. +# NB: We depend on 0.1.15, since that's what gets brought in transitively +# by rand and rand_core. +getrandom = { version = "0.1.15", features = ["wasm-bindgen"] } + +# We only need web-sys when compiling with the wasm feature. +web-sys = { version = "0.3.4", features = ['console'], optional = true } + +# We only need PyO3 when generating Python bindings. +pyo3 = { version = "0.13.2", features = ["extension-module"], optional = true } +numpy = {version = "0.13.1", optional = true} + +# We use built to expose compile-time metadata about how this crate +# was built to C and Rust callers. +built = "0.5.0" + +[build-dependencies] +built = "0.5.0" + + +[dev-dependencies] +assert-json-diff = "2.0.1" +criterion = { version = "0.3", features = ['html_reports', 'csv_output'] } + +[[bench]] +name = "c_api_benchmark" +harness = false + +[[bench]] +name = "microbenchmark" +harness = false From 749b10aef6ee65dde2c09b538fbcde777deafd01 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Tue, 16 Nov 2021 16:08:22 -0800 Subject: [PATCH 4/5] Do Cargo package with Allow Dirty option because of changes to the TOML file --- build/pack.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pack.ps1 b/build/pack.ps1 index 6bb5edcdf49..1d9fb5b3720 100644 --- a/build/pack.ps1 +++ b/build/pack.ps1 @@ -129,7 +129,7 @@ function Pack-Crate() { $OutPath = Resolve-Path (Join-Path $PSScriptRoot $OutPath); } Push-Location (Join-Path $PSScriptRoot $PackageDirectory) - cargo package; + cargo package --allow-dirty; # Copy only the .crate file, since we don't need all the intermediate # artifacts brought in by the full folder under target/package. Copy-Item -Force (Join-Path . "target" "package" "*.crate") $OutPath; From 116438887cb3948bcdd3b505c7d654b3363f3040 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Tue, 16 Nov 2021 18:05:30 -0800 Subject: [PATCH 5/5] Reset test pipelines