From 8805dd3d7b00e58b372c19fb3bb9fabd4b175642 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 20 Oct 2021 15:27:58 -0700 Subject: [PATCH 01/13] Basic Runtime Driver implementation --- .../Runtime/lib/QIR/BasicRuntimeDriver.cpp | 75 +++++++++++++++++++ src/Qir/Runtime/lib/QIR/CMakeLists.txt | 1 + .../public/BasicRuntimeDriverFactory.h | 21 ++++++ 3 files changed, 97 insertions(+) create mode 100644 src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp create mode 100644 src/Qir/Runtime/public/BasicRuntimeDriverFactory.h diff --git a/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp b/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp new file mode 100644 index 00000000000..a59bc3f1e26 --- /dev/null +++ b/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include + +#include "QirRuntimeApi_I.hpp" +#include "QubitManager.hpp" +#include "BasicRuntimeDriverFactory.h" + +namespace Microsoft +{ +namespace Quantum +{ + // TODO: is it OK to load/unload the dll for each simulator instance? + class CBasicRuntimeDriver : public IRuntimeDriver + { + std::unique_ptr qubitManager; + + public: + CBasicRuntimeDriver() + { + qubitManager = std::make_unique(); + } + + ~CBasicRuntimeDriver() override + { + } + + std::string QubitToString(QubitIdType q) override + { + return std::to_string(q); + } + + QubitIdType AllocateQubit() override + { + return qubitManager->Allocate(); + } + + void ReleaseQubit(QubitIdType q) override + { + qubitManager->Release(q); + } + + void ReleaseResult(Result /* result */) override + { + } + + bool AreEqualResults(Result r1, Result r2) override + { + return r1 == r2; + } + + ResultValue GetResultValue(Result r) override + { + return (r == UseZero()) ? Result_Zero : Result_One; + } + + Result UseZero() override + { + return reinterpret_cast(0); + } + + Result UseOne() override + { + return reinterpret_cast(1); + } + }; + + extern "C" void* CreateBasicRuntimeDriver() + { + return (IRuntimeDriver*)new CBasicRuntimeDriver(); + } + +} // namespace Quantum +} // namespace Microsoft diff --git a/src/Qir/Runtime/lib/QIR/CMakeLists.txt b/src/Qir/Runtime/lib/QIR/CMakeLists.txt index 8fcb15d7c04..f100670f063 100644 --- a/src/Qir/Runtime/lib/QIR/CMakeLists.txt +++ b/src/Qir/Runtime/lib/QIR/CMakeLists.txt @@ -19,6 +19,7 @@ set(rt_sup_source_files strings.cpp utils.cpp QubitManager.cpp + BasicRuntimeDriver.cpp ) # Produce object lib we'll use to create a shared lib (so/dll) later on diff --git a/src/Qir/Runtime/public/BasicRuntimeDriverFactory.h b/src/Qir/Runtime/public/BasicRuntimeDriverFactory.h new file mode 100644 index 00000000000..ca33e2b609b --- /dev/null +++ b/src/Qir/Runtime/public/BasicRuntimeDriverFactory.h @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#ifndef BASICRUNTIMEDRIVERFACTORY_H +#define BASICRUNTIMEDRIVERFACTORY_H + +#include +#include "CoreDefines.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + QIR_SHARED_API void* CreateBasicRuntimeDriver(); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // #ifndef BASICRUNTIMEDRIVERFACTORY_H From f552c3ae4b82897e3f91833e081349990395c1e6 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 20 Oct 2021 16:50:19 -0700 Subject: [PATCH 02/13] Remove leftover comment --- src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp b/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp index a59bc3f1e26..21518a87c45 100644 --- a/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp +++ b/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp @@ -11,7 +11,6 @@ namespace Microsoft { namespace Quantum { - // TODO: is it OK to load/unload the dll for each simulator instance? class CBasicRuntimeDriver : public IRuntimeDriver { std::unique_ptr qubitManager; From 98026b7de40d0c62d77aadd2add7711320dafb53 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 20 Oct 2021 17:20:33 -0700 Subject: [PATCH 03/13] fix copyright comment --- src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp b/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp index 21518a87c45..6076e8cf85b 100644 --- a/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp +++ b/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #include From 6e289b5b508285dfd9117f420e0cff57a7694a46 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 20 Oct 2021 21:57:02 -0700 Subject: [PATCH 04/13] Include memory header --- src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp b/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp index 6076e8cf85b..f84399ae30c 100644 --- a/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp +++ b/src/Qir/Runtime/lib/QIR/BasicRuntimeDriver.cpp @@ -2,6 +2,7 @@ // Licensed under the MIT License. #include +#include #include "QirRuntimeApi_I.hpp" #include "QubitManager.hpp" From f1b3dae5d167bdf77dab29566e23df46b14b9100 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Fri, 22 Oct 2021 08:03:51 -0700 Subject: [PATCH 05/13] Adding static lib generation --- src/Qir/Runtime/lib/QIR/CMakeLists.txt | 19 +++++++++++++++++ .../lib/QSharpFoundation/CMakeLists.txt | 21 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Qir/Runtime/lib/QIR/CMakeLists.txt b/src/Qir/Runtime/lib/QIR/CMakeLists.txt index f100670f063..bfe0bd0ddb4 100644 --- a/src/Qir/Runtime/lib/QIR/CMakeLists.txt +++ b/src/Qir/Runtime/lib/QIR/CMakeLists.txt @@ -39,7 +39,9 @@ target_compile_definitions(qir-rt-support-obj PRIVATE EXPORT_QIR_API) #=============================================================================== # Produce the Microsoft.Quantum.Qir.Runtime dynamic library # + add_library(Microsoft.Quantum.Qir.Runtime SHARED) +add_library(Microsoft.Quantum.Qir.Runtime.Static STATIC) target_link_libraries(Microsoft.Quantum.Qir.Runtime ${CMAKE_DL_LIBS} @@ -47,13 +49,30 @@ target_link_libraries(Microsoft.Quantum.Qir.Runtime ${SPECTRE_LIBS} ) +target_link_libraries(Microsoft.Quantum.Qir.Runtime.Static + ${CMAKE_DL_LIBS} + qir-rt-support-obj + ${SPECTRE_LIBS} +) + target_include_directories(Microsoft.Quantum.Qir.Runtime PUBLIC ${public_includes}) target_compile_definitions(Microsoft.Quantum.Qir.Runtime PRIVATE EXPORT_QIR_API) +target_include_directories(Microsoft.Quantum.Qir.Runtime.Static PUBLIC ${public_includes}) +target_compile_definitions(Microsoft.Quantum.Qir.Runtime.Static PRIVATE EXPORT_QIR_API) + set_property(TARGET Microsoft.Quantum.Qir.Runtime PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET Microsoft.Quantum.Qir.Runtime.Static PROPERTY POSITION_INDEPENDENT_CODE ON) + install(TARGETS Microsoft.Quantum.Qir.Runtime RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/bin" LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin" ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin" ) + +install(TARGETS Microsoft.Quantum.Qir.Runtime.Static + RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/bin" + LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin" + ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin" +) diff --git a/src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt b/src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt index 177ec7f4985..afc3641a462 100644 --- a/src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt +++ b/src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt @@ -25,6 +25,8 @@ target_compile_definitions(qsharp-foundation-qis-support-obj PUBLIC EXPORT_QIR_A # add_library(Microsoft.Quantum.Qir.QSharp.Foundation SHARED) +add_library(Microsoft.Quantum.Qir.QSharp.Foundation.Static STATIC) + target_link_libraries(Microsoft.Quantum.Qir.QSharp.Foundation ${CMAKE_DL_LIBS} qsharp-foundation-qis-support-obj @@ -34,17 +36,36 @@ target_link_libraries(Microsoft.Quantum.Qir.QSharp.Foundation ) add_dependencies(Microsoft.Quantum.Qir.QSharp.Foundation Microsoft.Quantum.Qir.Runtime) +target_link_libraries(Microsoft.Quantum.Qir.QSharp.Foundation.Static + ${CMAKE_DL_LIBS} + qsharp-foundation-qis-support-obj + "-L${CMAKE_BINARY_DIR}/lib/QIR" + -lMicrosoft.Quantum.Qir.Runtime.Static + ${SPECTRE_LIBS} +) +add_dependencies(Microsoft.Quantum.Qir.QSharp.Foundation.Static Microsoft.Quantum.Qir.Runtime.Static) + target_include_directories(Microsoft.Quantum.Qir.QSharp.Foundation PUBLIC ${public_includes} ${common_includes} ) + target_compile_definitions(Microsoft.Quantum.Qir.QSharp.Foundation PRIVATE EXPORT_QIR_API) +target_compile_definitions(Microsoft.Quantum.Qir.QSharp.Foundation.Static PRIVATE EXPORT_QIR_API) + set_property(TARGET Microsoft.Quantum.Qir.QSharp.Foundation PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET Microsoft.Quantum.Qir.QSharp.Foundation.Static PROPERTY POSITION_INDEPENDENT_CODE ON) + install(TARGETS Microsoft.Quantum.Qir.QSharp.Foundation RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/bin" LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin" ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin" ) +install(TARGETS Microsoft.Quantum.Qir.QSharp.Foundation.Static + RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/bin" + LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin" + ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin" +) From 69312ac81358396e4d59b88881461f35a58a84e4 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Fri, 5 Nov 2021 07:14:28 -0700 Subject: [PATCH 06/13] Removing static lib changes --- src/Qir/Runtime/lib/QIR/CMakeLists.txt | 19 ---------------- .../lib/QSharpFoundation/CMakeLists.txt | 22 ------------------- 2 files changed, 41 deletions(-) diff --git a/src/Qir/Runtime/lib/QIR/CMakeLists.txt b/src/Qir/Runtime/lib/QIR/CMakeLists.txt index bfe0bd0ddb4..f100670f063 100644 --- a/src/Qir/Runtime/lib/QIR/CMakeLists.txt +++ b/src/Qir/Runtime/lib/QIR/CMakeLists.txt @@ -39,9 +39,7 @@ target_compile_definitions(qir-rt-support-obj PRIVATE EXPORT_QIR_API) #=============================================================================== # Produce the Microsoft.Quantum.Qir.Runtime dynamic library # - add_library(Microsoft.Quantum.Qir.Runtime SHARED) -add_library(Microsoft.Quantum.Qir.Runtime.Static STATIC) target_link_libraries(Microsoft.Quantum.Qir.Runtime ${CMAKE_DL_LIBS} @@ -49,30 +47,13 @@ target_link_libraries(Microsoft.Quantum.Qir.Runtime ${SPECTRE_LIBS} ) -target_link_libraries(Microsoft.Quantum.Qir.Runtime.Static - ${CMAKE_DL_LIBS} - qir-rt-support-obj - ${SPECTRE_LIBS} -) - target_include_directories(Microsoft.Quantum.Qir.Runtime PUBLIC ${public_includes}) target_compile_definitions(Microsoft.Quantum.Qir.Runtime PRIVATE EXPORT_QIR_API) -target_include_directories(Microsoft.Quantum.Qir.Runtime.Static PUBLIC ${public_includes}) -target_compile_definitions(Microsoft.Quantum.Qir.Runtime.Static PRIVATE EXPORT_QIR_API) - set_property(TARGET Microsoft.Quantum.Qir.Runtime PROPERTY POSITION_INDEPENDENT_CODE ON) -set_property(TARGET Microsoft.Quantum.Qir.Runtime.Static PROPERTY POSITION_INDEPENDENT_CODE ON) - install(TARGETS Microsoft.Quantum.Qir.Runtime RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/bin" LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin" ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin" ) - -install(TARGETS Microsoft.Quantum.Qir.Runtime.Static - RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/bin" - LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin" - ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin" -) diff --git a/src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt b/src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt index afc3641a462..f8ca4ebe1c0 100644 --- a/src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt +++ b/src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt @@ -25,8 +25,6 @@ target_compile_definitions(qsharp-foundation-qis-support-obj PUBLIC EXPORT_QIR_A # add_library(Microsoft.Quantum.Qir.QSharp.Foundation SHARED) -add_library(Microsoft.Quantum.Qir.QSharp.Foundation.Static STATIC) - target_link_libraries(Microsoft.Quantum.Qir.QSharp.Foundation ${CMAKE_DL_LIBS} qsharp-foundation-qis-support-obj @@ -36,36 +34,16 @@ target_link_libraries(Microsoft.Quantum.Qir.QSharp.Foundation ) add_dependencies(Microsoft.Quantum.Qir.QSharp.Foundation Microsoft.Quantum.Qir.Runtime) -target_link_libraries(Microsoft.Quantum.Qir.QSharp.Foundation.Static - ${CMAKE_DL_LIBS} - qsharp-foundation-qis-support-obj - "-L${CMAKE_BINARY_DIR}/lib/QIR" - -lMicrosoft.Quantum.Qir.Runtime.Static - ${SPECTRE_LIBS} -) -add_dependencies(Microsoft.Quantum.Qir.QSharp.Foundation.Static Microsoft.Quantum.Qir.Runtime.Static) - target_include_directories(Microsoft.Quantum.Qir.QSharp.Foundation PUBLIC ${public_includes} ${common_includes} ) - target_compile_definitions(Microsoft.Quantum.Qir.QSharp.Foundation PRIVATE EXPORT_QIR_API) -target_compile_definitions(Microsoft.Quantum.Qir.QSharp.Foundation.Static PRIVATE EXPORT_QIR_API) - set_property(TARGET Microsoft.Quantum.Qir.QSharp.Foundation PROPERTY POSITION_INDEPENDENT_CODE ON) -set_property(TARGET Microsoft.Quantum.Qir.QSharp.Foundation.Static PROPERTY POSITION_INDEPENDENT_CODE ON) - install(TARGETS Microsoft.Quantum.Qir.QSharp.Foundation RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/bin" LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin" ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin" ) - -install(TARGETS Microsoft.Quantum.Qir.QSharp.Foundation.Static - RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/bin" - LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin" - ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin" -) From 2c15e3c6cb504e27647d5e2ca12f58a46630030d Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Thu, 4 Nov 2021 17:11:19 -0700 Subject: [PATCH 07/13] Moving QIR runtime build config into CMakeLists. (#863) * Moving QIR runtime build config into qir_cmake_include CMakeLists. --- src/Qir/Common/cmake/qir_cmake_include.cmake | 169 ++++++++++++++++++ src/Qir/Runtime/CMakeLists.txt | 7 - src/Qir/qir-utils.ps1 | 174 ++----------------- 3 files changed, 184 insertions(+), 166 deletions(-) diff --git a/src/Qir/Common/cmake/qir_cmake_include.cmake b/src/Qir/Common/cmake/qir_cmake_include.cmake index 25e66fbd104..9ad60d716ea 100644 --- a/src/Qir/Common/cmake/qir_cmake_include.cmake +++ b/src/Qir/Common/cmake/qir_cmake_include.cmake @@ -39,3 +39,172 @@ macro(target_source_from_qir target_name source_file) ${OBJFILE} ) endmacro() + + +#=============================================================================== +# Common flags + +# Always use available Spectre mitigations where available +if (NOT APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mspeculative-load-hardening -mretpoline") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mspeculative-load-hardening -mretpoline") +endif() + +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG") + +#=============================================================================== +# Warnings + +# Treat warnings as errors: +# https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages +set(WARNING_FLAGS "-Werror") + +# Enable all warnings: +# https://clang.llvm.org/docs/UsersManual.html#enabling-all-diagnostics +# https://clang.llvm.org/docs/DiagnosticsReference.html +set(WARNING_FLAGS "${WARNING_FLAGS} -Weverything") + +# Disable these warnings: + +# We don't care about keeping compatibility with C++98/03, C++11, C++14. Any new features unknown to our compiler version will be reported as errors. +# -Wc++98-compat-pedantic +# -Wc++98-compat, +# -Wc++98-compat-local-type-template-args, -Wc++98-compat-unnamed-type-template-args, -Wpre-c++14-compat, +# -Wpre-c++17-compat, -Wpre-c++20-compat, -Wpre-c++2b-compat. +# -Wc++98-compat-bind-to-temporary-copy, -Wc++98-compat-extra-semi, +# -Wpre-c++14-compat-pedantic, +# -Wc++98-c++11-compat-binary-literal, -Wpre-c++14-compat. +# -Wpre-c++17-compat-pedantic, +# -Wpre-c++17-compat. +# -Wpre-c++20-compat-pedantic, +# -Wpre-c++20-compat. +# -Wpre-c++2b-compat-pedantic (= -Wpre-c++2b-compat). + +# https://clang.llvm.org/docs/DiagnosticsReference.html#wc-98-compat-pedantic +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-c++98-compat-pedantic") + +# Old-style casts increase readability as opposed to `reinterpret_cast<..>()`. We want to be able to use the old-style casts. +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-old-style-cast") + +# Even if the `switch` covers all the enumerators, it is still good to have `default` label to cover the potential newly added (but not handled) enumerators. +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-covered-switch-default") + +# We are OK using C99 features. +# -Wc99-extension +# -Wc99-designator +# -Wc++20-designator +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-c99-extensions") + +# We are OK that the structs are padded to align the fields. +# https://clang.llvm.org/docs/DiagnosticsReference.html#wpadded +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-padded") + +# We are OK with abstract classes. +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-weak-vtables") + +# Temporarily disable the following warnings (until QIR RT is refactored to expose C interface). + +# Looks like the `-Wglobal-constructors` warns that the instance of the `__dllexport` class/struct (or a static member var of such class/struct) +# needs to be constructible by calling a global `__dllexport` function (to guarantee that a single instance is created and the same instance is used +# both inside and outside of the binary (dynamic library or executable)). +# Or it warns about the constructor that is invoked for a global (or static member) variable _before_ the `main()` is invoked, thus slowing down the start, +# see https://stackoverflow.com/a/15708829/6362941 + +# https://clang.llvm.org/docs/DiagnosticsReference.html#wglobal-constructors +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-global-constructors") + +# Looks like the `-Wexit-time-destructors` warns that the destructor of a global or static member variable will be invoked +# _after_ the `main()` returns (thus slowing down the termination/restart). +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-exit-time-destructors") + +# Temporarily disable "-Wextra-semi-stmt" that warns about redundant `;` in the end of `INFO(id);` of Catch tests framework (which looks fixed in the latest Catch version). +# Disable until the Catch header "src\Qir\Common\Externals\catch2\catch.hpp" is updated to a version newer than v2.12.1 (from https://github.com/catchorg/Catch2). + +# https://clang.llvm.org/docs/DiagnosticsReference.html#wextra-semi-stmt +set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-extra-semi-stmt") + +# Save the assembled warnings +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}") + + +#=============================================================================== +# Sanitizers (https://clang.llvm.org/docs/UsersManual.html#controlling-code-generation): + +if (NOT WIN32) + set(SANITIZE_FLAGS "") + + # Undefined Behavior Sanitizer (https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) + # Win: + # FAILED: lib/QIR/Microsoft.Quantum.Qir.Runtime.dll lib/QIR/Microsoft.Quantum.Qir.Runtime.lib + # lld-link: error: /failifmismatch: mismatch detected for 'RuntimeLibrary': + # >>> lib/QIR/CMakeFiles/qir-rt-support-obj.dir/QubitManager.cpp.obj has value MD_DynamicRelease + # >>> clang_rt.ubsan_standalone_cxx-x86_64.lib(ubsan_type_hash_win.cc.obj) has value MT_StaticRelease + # clang++: error: linker command failed with exit code 1 (use -v to see invocation) + set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=unsigned-integer-overflow -fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability") + + # TODO: + # For Win consider extra build configuration linking all libs statically, enable `-fsanitize=undefined`, run the statically linked tests. + + #if (-not ($IsMacOS)) # Cannot be combined with `-fsanitize=address`. + #{ + # # Safe Stack instrumentation (https://clang.llvm.org/docs/SafeStack.html): + # # No support for Win, Mac. + # # clang: error: unsupported option '-fsanitize=safe-stack' for target 'x86_64-apple-darwin19.6.0' + # # Linking a DSO with SafeStack is not currently supported. But compilation, linking, and test runs all succeed. + # $sanitizeFlags += " -fsanitize=safe-stack" + #} + + ## Memory Sanitizer (https://clang.llvm.org/docs/MemorySanitizer.html) + ## Win: Not supported. + ## clang: error: unsupported option '-fsanitize=memory' for target 'x86_64-pc-windows-msvc' + ## WSL: Complains for use-of-uninitialized-value in `catch2/catch.hpp` during initialization of global vars + ## (if run both as `pwsh Runtime/test-qir-runtime.ps1` (or Tests/test-qir-tests.ps1) and as standalone). + ## An update of `catch2/catch.hpp` to 2.13.6 (search for "go to the v2.x branch" at https://github.com/catchorg/Catch2) didn't help. + ## Suppressing of the errors in the updated `catch2/catch.hpp` and standard library headers eventually bumps into errors reported in `memcmp`, + ## suppressing of which does not work (https://github.com/google/sanitizers/issues/1429#issuecomment-876799463). + ## Looks like MSan will not work until the libstdc++ is recompiled to be instrumented (https://clang.llvm.org/docs/MemorySanitizer.html#handling-external-code). + ## Instrumenting libstdc++ during CI builds seems impractical (https://stackoverflow.com/a/22301584/6362941). + #$sanitizeFlags += " -fsanitize=memory -fsanitize-memory-track-origins=2" + + # Address Sanitizer (https://clang.llvm.org/docs/AddressSanitizer.html) + # Win: (Conflict between the ASan library and MSVC library) + # [19/35] Linking CXX shared library lib\QIR\Microsoft.Quantum.Qir.Runtime.dll + # FAILED: lib/QIR/Microsoft.Quantum.Qir.Runtime.dll lib/QIR/Microsoft.Quantum.Qir.Runtime.lib + # cmd.exe /C "cd . && C:\PROGRA~1\LLVM12\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -Werror -Weverything .... \ + # -fsanitize=address -g -Xclang -gcodeview -O0 -DDEBUG -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd \ + # -Xlinker /guard:cf -shared -o lib\QIR\Microsoft.Quantum.Qir.Runtime.dll -Xlinker /implib:lib\QIR\Microsoft.Quantum.Qir.Runtime.lib \ + # -Xlinker /pdb:lib\QIR\Microsoft.Quantum.Qir.Runtime.pdb -Xlinker /version:0.0 lib/QIR/bridge-rt.obj \ + # lib/QIR/CMakeFiles/qir-rt-support-obj.dir/QirRange.cpp.obj lib/QIR/CMakeFiles/qir-rt-support-obj.dir/OutputStream.cpp.obj ....\ + # -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ." + # lld-link: error: duplicate symbol: malloc + # >>> defined at C:\src\llvm_package_6923b0a7\llvm-project\compiler-rt\lib\asan\asan_win_dll_thunk.cpp:34 + # >>> clang_rt.asan_dll_thunk-x86_64.lib(asan_win_dll_thunk.cpp.obj) + # >>> defined at ucrtbased.dll + # clang++: error: linker command failed with exit code 1 (use -v to see invocation) + + # https://clang.llvm.org/docs/AddressSanitizer.html + set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fsanitize=address") + + # TODO: + # * Some tests verify the failure behavior, i.e. they cause `Fail()` to be called and return to the caller with the exception. + # Any allocations made between the call and the exception throw (caught by `REQUIRE_THROWS()`) are leaking. + # Extract such tests to a separate .cpp file or executable and compile with leak check off (or suppress leaks in that .cpp or executable only). + + # Common for all sanitizers: + # https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#suppressing-errors-in-recompiled-code-ignorelist + # https://releases.llvm.org/11.0.1/tools/clang/docs/SanitizerSpecialCaseList.html + set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fsanitize-blacklist=${CMAKE_CURRENT_LIST_DIR}/../../UBSan.ignore") + + # https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html + set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-omit-frame-pointer") + + # https://clang.llvm.org/docs/AddressSanitizer.html + set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-optimize-sibling-calls") + + # Save the flags + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${SANITIZE_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${SANITIZE_FLAGS}") +endif() + diff --git a/src/Qir/Runtime/CMakeLists.txt b/src/Qir/Runtime/CMakeLists.txt index 0635bcf57b2..0f4bdf52d55 100644 --- a/src/Qir/Runtime/CMakeLists.txt +++ b/src/Qir/Runtime/CMakeLists.txt @@ -9,13 +9,6 @@ project(qirruntime) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") - -# Always use available Spectre mitigations where available -if (NOT APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mspeculative-load-hardening -mretpoline") -endif() - if (WIN32) # Enforce use of static runtime (avoids target machine needing msvcrt installed). set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") diff --git a/src/Qir/qir-utils.ps1 b/src/Qir/qir-utils.ps1 index 11aac34ecfa..612c19b9246 100644 --- a/src/Qir/qir-utils.ps1 +++ b/src/Qir/qir-utils.ps1 @@ -34,163 +34,24 @@ function Build-CMakeProject { ) Write-Host "##[info]Build $Name" - $oldCC = $env:CC - $oldCXX = $env:CXX - $oldRC = $env:RC - $oldCFLAGS = $env:CFLAGS - $oldCXXFLAGS = $env:CXXFLAGS + $CMAKE_C_COMPILER = "" + $CMAKE_CXX_COMPILER = "" $clangTidy = "" - # Treat warnings as errors: - $warningFlags = "-Werror" # https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages - # Enable all warnings: - $warningFlags += " -Weverything" # https://clang.llvm.org/docs/UsersManual.html#enabling-all-diagnostics - # https://clang.llvm.org/docs/DiagnosticsReference.html - - # Disable these warnings: - - # We don't care about keeping compatibility with C++98/03, C++11, C++14. Any new features unknown to our compiler version will be reported as errors. - # -Wc++98-compat-pedantic - # -Wc++98-compat, - # -Wc++98-compat-local-type-template-args, -Wc++98-compat-unnamed-type-template-args, -Wpre-c++14-compat, - # -Wpre-c++17-compat, -Wpre-c++20-compat, -Wpre-c++2b-compat. - # -Wc++98-compat-bind-to-temporary-copy, -Wc++98-compat-extra-semi, - # -Wpre-c++14-compat-pedantic, - # -Wc++98-c++11-compat-binary-literal, -Wpre-c++14-compat. - # -Wpre-c++17-compat-pedantic, - # -Wpre-c++17-compat. - # -Wpre-c++20-compat-pedantic, - # -Wpre-c++20-compat. - # -Wpre-c++2b-compat-pedantic (= -Wpre-c++2b-compat). - $warningFlags += " -Wno-c++98-compat-pedantic" # https://clang.llvm.org/docs/DiagnosticsReference.html#wc-98-compat-pedantic - # Old-style casts increase readability as opposed to `reinterpret_cast<..>()`. We want to be able to use the old-style casts. - $warningFlags += " -Wno-old-style-cast" - # Even if the `switch` covers all the enumerators, it is still good to have `default` label to cover the potential newly added (but not handled) enumerators. - $warningFlags += " -Wno-covered-switch-default" - # We are OK using C99 features. - # -Wc99-extension - # -Wc99-designator - # -Wc++20-designator - $warningFlags += " -Wno-c99-extensions" - # We are OK that the structs are padded to align the fields. - $warningFlags += " -Wno-padded" # https://clang.llvm.org/docs/DiagnosticsReference.html#wpadded - # We are OK with abstract classes. - $warningFlags += " -Wno-weak-vtables" - - - # Temporarily disable the following warnings (until QIR RT is refactored to expose C interface). - - # Looks like the `-Wglobal-constructors` warns that the instance of the `__dllexport` class/struct (or a static member var of such class/struct) - # needs to be constructible by calling a global `__dllexport` function (to guarantee that a single instance is created and the same instance is used - # both inside and outside of the binary (dynamic library or executable)). - # Or it warns about the constructor that is invoked for a global (or static member) variable _before_ the `main()` is invoked, thus slowing down the start, - # see https://stackoverflow.com/a/15708829/6362941 - $warningFlags += " -Wno-global-constructors" # https://clang.llvm.org/docs/DiagnosticsReference.html#wglobal-constructors - # Looks like the `-Wexit-time-destructors` warns that the destructor of a global or static member variable will be invoked - # _after_ the `main()` returns (thus slowing down the termination/restart). - $warningFlags += " -Wno-exit-time-destructors" - - # Temporarily disable "-Wextra-semi-stmt" that warns about redundant `;` in the end of `INFO(id);` of Catch tests framework (which looks fixed in the latest Catch version). - # Disable until the Catch header "src\Qir\Common\Externals\catch2\catch.hpp" is updated to a version newer than v2.12.1 (from https://github.com/catchorg/Catch2). - $warningFlags += " -Wno-extra-semi-stmt" # https://clang.llvm.org/docs/DiagnosticsReference.html#wextra-semi-stmt - - $env:CFLAGS += $warningFlags - $env:CXXFLAGS += $warningFlags - - - if ($Env:BUILD_CONFIGURATION -eq "Debug") - { - # Sanitizers (https://clang.llvm.org/docs/UsersManual.html#controlling-code-generation): - - $sanitizeFlags = "" - if (-not ($IsWindows)) - { - # Undefined Behavior Sanitizer (https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) - # Win: - # FAILED: lib/QIR/Microsoft.Quantum.Qir.Runtime.dll lib/QIR/Microsoft.Quantum.Qir.Runtime.lib - # lld-link: error: /failifmismatch: mismatch detected for 'RuntimeLibrary': - # >>> lib/QIR/CMakeFiles/qir-rt-support-obj.dir/QubitManager.cpp.obj has value MD_DynamicRelease - # >>> clang_rt.ubsan_standalone_cxx-x86_64.lib(ubsan_type_hash_win.cc.obj) has value MT_StaticRelease - # clang++: error: linker command failed with exit code 1 (use -v to see invocation) - $sanitizeFlags += " -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=unsigned-integer-overflow -fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability" - # TODO: - # For Win consider extra build configuration linking all libs statically, enable `-fsanitize=undefined`, run the statically linked tests. - - #if (-not ($IsMacOS)) # Cannot be combined with `-fsanitize=address`. - #{ - # # Safe Stack instrumentation (https://clang.llvm.org/docs/SafeStack.html): - # # No support for Win, Mac. - # # clang: error: unsupported option '-fsanitize=safe-stack' for target 'x86_64-apple-darwin19.6.0' - # # Linking a DSO with SafeStack is not currently supported. But compilation, linking, and test runs all succeed. - # $sanitizeFlags += " -fsanitize=safe-stack" - #} - - ## Memory Sanitizer (https://clang.llvm.org/docs/MemorySanitizer.html) - ## Win: Not supported. - ## clang: error: unsupported option '-fsanitize=memory' for target 'x86_64-pc-windows-msvc' - ## WSL: Complains for use-of-uninitialized-value in `catch2/catch.hpp` during initialization of global vars - ## (if run both as `pwsh Runtime/test-qir-runtime.ps1` (or Tests/test-qir-tests.ps1) and as standalone). - ## An update of `catch2/catch.hpp` to 2.13.6 (search for "go to the v2.x branch" at https://github.com/catchorg/Catch2) didn't help. - ## Suppressing of the errors in the updated `catch2/catch.hpp` and standard library headers eventually bumps into errors reported in `memcmp`, - ## suppressing of which does not work (https://github.com/google/sanitizers/issues/1429#issuecomment-876799463). - ## Looks like MSan will not work until the libstdc++ is recompiled to be instrumented (https://clang.llvm.org/docs/MemorySanitizer.html#handling-external-code). - ## Instrumenting libstdc++ during CI builds seems impractical (https://stackoverflow.com/a/22301584/6362941). - #$sanitizeFlags += " -fsanitize=memory -fsanitize-memory-track-origins=2" - - # Address Sanitizer (https://clang.llvm.org/docs/AddressSanitizer.html) - # Win: (Conflict between the ASan library and MSVC library) - # [19/35] Linking CXX shared library lib\QIR\Microsoft.Quantum.Qir.Runtime.dll - # FAILED: lib/QIR/Microsoft.Quantum.Qir.Runtime.dll lib/QIR/Microsoft.Quantum.Qir.Runtime.lib - # cmd.exe /C "cd . && C:\PROGRA~1\LLVM12\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -Werror -Weverything .... \ - # -fsanitize=address -g -Xclang -gcodeview -O0 -DDEBUG -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd \ - # -Xlinker /guard:cf -shared -o lib\QIR\Microsoft.Quantum.Qir.Runtime.dll -Xlinker /implib:lib\QIR\Microsoft.Quantum.Qir.Runtime.lib \ - # -Xlinker /pdb:lib\QIR\Microsoft.Quantum.Qir.Runtime.pdb -Xlinker /version:0.0 lib/QIR/bridge-rt.obj \ - # lib/QIR/CMakeFiles/qir-rt-support-obj.dir/QirRange.cpp.obj lib/QIR/CMakeFiles/qir-rt-support-obj.dir/OutputStream.cpp.obj ....\ - # -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ." - # lld-link: error: duplicate symbol: malloc - # >>> defined at C:\src\llvm_package_6923b0a7\llvm-project\compiler-rt\lib\asan\asan_win_dll_thunk.cpp:34 - # >>> clang_rt.asan_dll_thunk-x86_64.lib(asan_win_dll_thunk.cpp.obj) - # >>> defined at ucrtbased.dll - # clang++: error: linker command failed with exit code 1 (use -v to see invocation) - $sanitizeFlags += " -fsanitize=address" # https://clang.llvm.org/docs/AddressSanitizer.html - # TODO: - # * Some tests verify the failure behavior, i.e. they cause `Fail()` to be called and return to the caller with the exception. - # Any allocations made between the call and the exception throw (caught by `REQUIRE_THROWS()`) are leaking. - # Extract such tests to a separate .cpp file or executable and compile with leak check off (or suppress leaks in that .cpp or executable only). - - # Common for all sanitizers: - $sanitizeFlags += " -fsanitize-blacklist=" # https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#suppressing-errors-in-recompiled-code-ignorelist - # https://releases.llvm.org/11.0.1/tools/clang/docs/SanitizerSpecialCaseList.html - $sanitizeFlags += (Join-Path $Path .. UBSan.ignore) - - $sanitizeFlags += " -fno-omit-frame-pointer" # https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html - $sanitizeFlags += " -fno-optimize-sibling-calls" # https://clang.llvm.org/docs/AddressSanitizer.html - } # if (-not ($IsWindows)) - - $env:CFLAGS += $sanitizeFlags - $env:CXXFLAGS += $sanitizeFlags - } # if ($Env:BUILD_CONFIGURATION -eq "Debug") - - - if (($IsMacOS) -or ((Test-Path Env:/AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin")))) - { + if (($IsMacOS) -or ((Test-Path Env:/AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin")))) { Write-Host "On MacOS build $Name using the default C/C++ compiler (should be AppleClang)" } - elseif (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin")))) - { + elseif (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin")))) { Write-Host "On Linux build $Name using Clang" - $env:CC = "clang-11" - $env:CXX = "clang++-11" - $env:RC = "clang++-11" + $CMAKE_C_COMPILER = "-DCMAKE_C_COMPILER=clang-11" + $CMAKE_CXX_COMPILER = "-DCMAKE_CXX_COMPILER=clang++-11" $clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy-11" } - elseif (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) - { + elseif (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) { Write-Host "On Windows build $Name using Clang" - $env:CC = "clang.exe" - $env:CXX = "clang++.exe" - $env:RC = "clang++.exe" + $CMAKE_C_COMPILER = "-DCMAKE_C_COMPILER=clang.exe" + $CMAKE_CXX_COMPILER = "-DCMAKE_CXX_COMPILER=clang++.exe" if ((!(Get-Command clang -ErrorAction SilentlyContinue) -and (choco find --idonly -l llvm) -contains "llvm") -or ` (Test-Path Env:/AGENT_OS)) { @@ -204,7 +65,8 @@ function Build-CMakeProject { # the Linux build catch tidy issues. $clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy" } - } else { + } + else { Write-Host "##vso[task.logissue type=warning;]Failed to identify the OS. Will use default CXX compiler" } @@ -218,15 +80,16 @@ function Build-CMakeProject { Push-Location $cmakeBuildFolder $buildType = $Env:BUILD_CONFIGURATION - if ($buildType -eq "Release"){ + if ($buildType -eq "Release") { $buildType = "RelWithDebInfo" } - cmake -G Ninja $clangTidy -D CMAKE_VERBOSE_MAKEFILE:BOOL=ON -D CMAKE_BUILD_TYPE="$buildType" ../.. | Write-Host + cmake -G Ninja $CMAKE_C_COMPILER $CMAKE_CXX_COMPILER $clangTidy -D CMAKE_BUILD_TYPE="$buildType" ../.. | Write-Host if ($LastExitCode -ne 0) { Write-Host "##vso[task.logissue type=error;]Failed to generate $Name." $all_ok = $false - } else { + } + else { cmake --build . --target install | Write-Host if ($LastExitCode -ne 0) { Write-Host "##vso[task.logissue type=error;]Failed to build $Name." @@ -236,13 +99,6 @@ function Build-CMakeProject { Pop-Location - $env:CXXFLAGS = $oldCXXFLAGS - $env:CFLAGS = $oldCFLAGS - - $env:CC = $oldCC - $env:CXX = $oldCXX - $env:RC = $oldRC - return $all_ok } From 3bf0e47b6d348b00aed377feeb44d47dbce73d69 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Fri, 5 Nov 2021 07:09:04 -0700 Subject: [PATCH 08/13] Adding foundation and runtime rust bundling --- Cargo.toml | 6 + .../Cargo.toml | 29 +++++ .../build.rs | 49 ++++++++ .../src/foundation.rs | 60 +++++++++ .../src/lib.rs | 10 ++ .../src/qir_libloading.rs | 48 +++++++ .../src/runtime.rs | 118 ++++++++++++++++++ 7 files changed, 320 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml create mode 100644 src/Qir/microsoft-quantum-qir-runtime-sys/build.rs create mode 100644 src/Qir/microsoft-quantum-qir-runtime-sys/src/foundation.rs create mode 100644 src/Qir/microsoft-quantum-qir-runtime-sys/src/lib.rs create mode 100644 src/Qir/microsoft-quantum-qir-runtime-sys/src/qir_libloading.rs create mode 100644 src/Qir/microsoft-quantum-qir-runtime-sys/src/runtime.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000000..152f6d6b86e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] + +members = [ + "src/Simulation/qdk_sim_rs", + "src/Qir/microsoft-quantum-qir-runtime-sys", +] \ No newline at end of file diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml new file mode 100644 index 00000000000..e7bc12943f2 --- /dev/null +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "microsoft-quantum-qir-runtime-sys" +version = "0.1.0" +edition = "2018" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +cty = "0.2.1" +libloading = "0.7.0" +log = "0.4.14" +tempfile = "3.2.0" +llvm-sys = "110" +inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", default-features = false, features = ["llvm11-0", "target-x86"] } +lazy_static = "1.4.0" +mut_static = "5.0.0" + +[build-dependencies] +cmake = "0.1.46" +bindgen = "0.59.1" + +[lib] + + +[features] +runtime = [] +foundation = [] +default = ["runtime", "foundation"] diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs new file mode 100644 index 00000000000..9524fe111a8 --- /dev/null +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +use cmake::Config; +use std::boxed::Box; +use std::error::Error; + +fn main() -> Result<(), Box> { + println!("cargo:rerun-if-env-changed=TARGET"); + println!("cargo:rerun-if-changed=build.rs"); + + let path_to_runtime_src = "../Runtime"; + compile_runtime_libraries(path_to_runtime_src)?; + + Ok(()) +} + +fn compile_runtime_libraries(path_to_runtime_src: &str) -> Result<(), Box> { + let mut config = Config::new(path_to_runtime_src); + + set_compiler(&mut config); + set_profile(&mut config)?; + + config.generator("Ninja").no_build_target(true); + + let _ = config.build(); + Ok(()) +} + +// https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-do-i-use-a-different-compiler +// We set this here as setting it in the cmakefile is discouraged +fn set_compiler(config: &mut Config) { + if cfg!(target_os = "linux") { + config.define("CMAKE_C_COMPILER", "clang-11"); + config.define("CMAKE_CXX_COMPILER", "clang++-11"); + } else if cfg!(target_os = "windows") { + config.define("CMAKE_C_COMPILER", "clang"); + config.define("CMAKE_CXX_COMPILER", "clang++"); + } else if cfg!(target_os = "macos") { + todo!("Identify the clang compiler on macos") + } else { + panic!("Unsupported platform") + } +} + +fn set_profile(config: &mut Config) -> Result<(), Box> { + config.define("CMAKE_BUILD_TYPE", "RelWithDebInfo"); + Ok(()) +} diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/src/foundation.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/src/foundation.rs new file mode 100644 index 00000000000..66e9d59fee0 --- /dev/null +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/src/foundation.rs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +use lazy_static::lazy_static; +use mut_static::MutStatic; + +use libloading::Library; + +#[cfg(target_os = "linux")] +const FOUNDATION_BYTES: &'static [u8] = include_bytes!(concat!( + env!("OUT_DIR"), + "/build/lib/QSharpFoundation/libMicrosoft.Quantum.Qir.QSharp.Foundation.so" +)); + +#[cfg(target_os = "macos")] +const FOUNDATION_BYTES: &'static [u8] = include_bytes!(concat!( + env!("OUT_DIR"), + "/build/lib/QSharpFoundation/libMicrosoft.Quantum.Qir.QSharp.Foundation.dylib" +)); + +#[cfg(target_os = "windows")] +const FOUNDATION_BYTES: &'static [u8] = include_bytes!(concat!( + env!("OUT_DIR"), + "/build/lib/QSharpFoundation/Microsoft.Quantum.Qir.QSharp.Foundation.dll" +)); + +lazy_static! { + pub(crate) static ref FOUNDATION_LIBRARY: MutStatic = unsafe { + MutStatic::from( + crate::qir_libloading::load_library_bytes( + "Microsoft.Quantum.Qir.QSharp.Foundation", + FOUNDATION_BYTES, + ) + .unwrap(), + ) + }; +} + +pub struct QSharpFoundation {} + +impl QSharpFoundation { + pub fn new() -> QSharpFoundation { + let _ = FOUNDATION_LIBRARY.read(); + QSharpFoundation {} + } +} + +#[cfg(test)] +mod tests { + #[test] + fn library_loads_on_new() { + let _ = QSharpFoundation::new(); + } + #[test] + fn library_can_be_initialized_multiple_times() { + let _ = QSharpFoundation::new(); + let _ = QSharpFoundation::new(); + let _ = QSharpFoundation::new(); + } +} diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/src/lib.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/src/lib.rs new file mode 100644 index 00000000000..5e2313ba80a --- /dev/null +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/src/lib.rs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#[cfg(feature = "foundation")] +pub mod foundation; + +#[cfg(feature = "runtime")] +pub mod runtime; + +mod qir_libloading; diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/src/qir_libloading.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/src/qir_libloading.rs new file mode 100644 index 00000000000..da81e0a46c2 --- /dev/null +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/src/qir_libloading.rs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +use libloading::{library_filename, Library}; +use log; +use std::error::Error; +use std::path::Path; +use tempfile::tempdir; + +pub(crate) fn write_library>( + path: P, + lib: &'static [u8], +) -> Result<(), Box> { + log::debug!("Writing {}", path.as_ref().display()); + std::fs::write(path, lib)?; + Ok(()) +} + +pub(crate) unsafe fn load_library_bytes( + base_name: &str, + lib: &'static [u8], +) -> Result> { + let name = library_filename(base_name) + .into_string() + .expect("Could not get library name as string"); + let path = tempdir().expect(""); + let filepath = path.as_ref().join(name); + write_library(&filepath, lib)?; + let library = load_library(&filepath)?; + Ok(library) +} + +pub(crate) unsafe fn load_library>(path: P) -> Result> { + log::debug!("Loading {}", path.as_ref().display()); + let library = Library::new(path.as_ref().as_os_str())?; + + let library_path = path + .as_ref() + .to_str() + .expect("Could not convert library path to &str"); + let was_loaded_by_llvm = inkwell::support::load_library_permanently(library_path); + if was_loaded_by_llvm { + log::error!("Failed to load {} into LLVM", library_path); + } else { + log::debug!("Loaded {} into LLVM", library_path); + } + Ok(library) +} diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/src/runtime.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/src/runtime.rs new file mode 100644 index 00000000000..2a3a8e02d44 --- /dev/null +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/src/runtime.rs @@ -0,0 +1,118 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +use lazy_static::lazy_static; +use mut_static::MutStatic; + +use std::ffi::CString; + +use cty; +use libloading::Library; + +#[cfg(target_os = "linux")] +const RUNTIME_BYTES: &'static [u8] = include_bytes!(concat!( + env!("OUT_DIR"), + "/build/lib/QIR/libMicrosoft.Quantum.Qir.Runtime.so" +)); + +#[cfg(target_os = "macos")] +const RUNTIME_BYTES: &'static [u8] = include_bytes!(concat!( + env!("OUT_DIR"), + "/build/lib/QIR/libMicrosoft.Quantum.Qir.Runtime.dylib" +)); + +#[cfg(target_os = "windows")] +const RUNTIME_BYTES: &'static [u8] = include_bytes!(concat!( + env!("OUT_DIR"), + "/build/lib/QIR/Microsoft.Quantum.Qir.Runtime.dll" +)); + +lazy_static! { + pub(crate) static ref RUNTIME_LIBRARY: MutStatic = unsafe { + MutStatic::from( + crate::qir_libloading::load_library_bytes( + "Microsoft.Quantum.Qir.Runtime", + RUNTIME_BYTES, + ) + .unwrap(), + ) + }; +} + +pub type QUBIT = u64; + +#[repr(C)] +pub struct QirArray { + private: [u8; 0], +} + +pub type IRuntimeDriver = cty::c_void; + +pub struct BasicRuntimeDriver {} + +impl BasicRuntimeDriver { + pub unsafe fn initialize_qir_context(track_allocated_objects: bool) { + // The libloading calls need to be used instead of the extern "C" calls + // to prevent linkage. Python can't init the lib if we take a hard + // dependency on the library + let driver = QirRuntime::create_basic_runtime_driver(); + QirRuntime::initialize_qir_context(driver, track_allocated_objects); + } +} + +pub struct QirRuntime {} + +impl QirRuntime { + pub unsafe fn create_basic_runtime_driver() -> *mut cty::c_void { + let library = RUNTIME_LIBRARY.read().unwrap(); + let create = library + .get:: *mut IRuntimeDriver>( + CString::new("CreateBasicRuntimeDriver") + .unwrap() + .as_bytes_with_nul(), + ) + .unwrap(); + create() + } + + pub unsafe fn initialize_qir_context(driver: *mut cty::c_void, track_allocated_objects: bool) { + let library = RUNTIME_LIBRARY.read().unwrap(); + let init = library + .get::( + CString::new("InitializeQirContext") + .unwrap() + .as_bytes_with_nul(), + ) + .unwrap(); + init(driver, track_allocated_objects) + } + + pub unsafe fn quantum_rt_array_get_element_ptr_1d( + array: *mut QirArray, + index: i64, + ) -> *mut cty::c_char { + let library = RUNTIME_LIBRARY.read().unwrap(); + let get_element_ptr = library + .get:: *mut cty::c_char>( + CString::new("__quantum__rt__array_get_element_ptr_1d") + .unwrap() + .as_bytes_with_nul(), + ) + .unwrap(); + get_element_ptr(array, index) + } +} + +#[cfg(test)] +mod tests { + #[test] + fn library_loads_on_new() { + let _ = QirRuntime::new(); + } + #[test] + fn library_can_be_initialized_multiple_times() { + let _ = QirRuntime::new(); + let _ = QirRuntime::new(); + let _ = QirRuntime::new(); + } +} From 533df83c26b152d48bec9349d041db19d8eb90b0 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Fri, 5 Nov 2021 13:50:44 -0700 Subject: [PATCH 09/13] Removing mut_static dep --- .../Cargo.toml | 1 - .../build.rs | 2 +- .../src/foundation.rs | 17 +++++++------ .../src/runtime.rs | 24 +++++++++---------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml index e7bc12943f2..946be2c4f31 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml @@ -14,7 +14,6 @@ tempfile = "3.2.0" llvm-sys = "110" inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", default-features = false, features = ["llvm11-0", "target-x86"] } lazy_static = "1.4.0" -mut_static = "5.0.0" [build-dependencies] cmake = "0.1.46" diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs index 9524fe111a8..93ff1487cf0 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs @@ -37,7 +37,7 @@ fn set_compiler(config: &mut Config) { config.define("CMAKE_C_COMPILER", "clang"); config.define("CMAKE_CXX_COMPILER", "clang++"); } else if cfg!(target_os = "macos") { - todo!("Identify the clang compiler on macos") + // Use macos default } else { panic!("Unsupported platform") } diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/src/foundation.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/src/foundation.rs index 66e9d59fee0..f061706b3ea 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/src/foundation.rs +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/src/foundation.rs @@ -2,7 +2,6 @@ // Licensed under the MIT License. use lazy_static::lazy_static; -use mut_static::MutStatic; use libloading::Library; @@ -25,14 +24,12 @@ const FOUNDATION_BYTES: &'static [u8] = include_bytes!(concat!( )); lazy_static! { - pub(crate) static ref FOUNDATION_LIBRARY: MutStatic = unsafe { - MutStatic::from( - crate::qir_libloading::load_library_bytes( - "Microsoft.Quantum.Qir.QSharp.Foundation", - FOUNDATION_BYTES, - ) - .unwrap(), + pub(crate) static ref FOUNDATION_LIBRARY: Library = unsafe { + crate::qir_libloading::load_library_bytes( + "Microsoft.Quantum.Qir.QSharp.Foundation", + FOUNDATION_BYTES, ) + .unwrap() }; } @@ -40,13 +37,15 @@ pub struct QSharpFoundation {} impl QSharpFoundation { pub fn new() -> QSharpFoundation { - let _ = FOUNDATION_LIBRARY.read(); + let _ = FOUNDATION_LIBRARY; QSharpFoundation {} } } #[cfg(test)] mod tests { + use crate::foundation::QSharpFoundation; + #[test] fn library_loads_on_new() { let _ = QSharpFoundation::new(); diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/src/runtime.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/src/runtime.rs index 2a3a8e02d44..948a0200235 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/src/runtime.rs +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/src/runtime.rs @@ -2,7 +2,6 @@ // Licensed under the MIT License. use lazy_static::lazy_static; -use mut_static::MutStatic; use std::ffi::CString; @@ -28,14 +27,9 @@ const RUNTIME_BYTES: &'static [u8] = include_bytes!(concat!( )); lazy_static! { - pub(crate) static ref RUNTIME_LIBRARY: MutStatic = unsafe { - MutStatic::from( - crate::qir_libloading::load_library_bytes( - "Microsoft.Quantum.Qir.Runtime", - RUNTIME_BYTES, - ) - .unwrap(), - ) + pub(crate) static ref RUNTIME_LIBRARY: Library = unsafe { + crate::qir_libloading::load_library_bytes("Microsoft.Quantum.Qir.Runtime", RUNTIME_BYTES) + .unwrap() }; } @@ -63,8 +57,13 @@ impl BasicRuntimeDriver { pub struct QirRuntime {} impl QirRuntime { + pub fn new() -> QirRuntime { + let _ = RUNTIME_LIBRARY; + QirRuntime {} + } + pub unsafe fn create_basic_runtime_driver() -> *mut cty::c_void { - let library = RUNTIME_LIBRARY.read().unwrap(); + let library = &RUNTIME_LIBRARY; let create = library .get:: *mut IRuntimeDriver>( CString::new("CreateBasicRuntimeDriver") @@ -76,7 +75,7 @@ impl QirRuntime { } pub unsafe fn initialize_qir_context(driver: *mut cty::c_void, track_allocated_objects: bool) { - let library = RUNTIME_LIBRARY.read().unwrap(); + let library = &RUNTIME_LIBRARY; let init = library .get::( CString::new("InitializeQirContext") @@ -91,7 +90,7 @@ impl QirRuntime { array: *mut QirArray, index: i64, ) -> *mut cty::c_char { - let library = RUNTIME_LIBRARY.read().unwrap(); + let library = &RUNTIME_LIBRARY; let get_element_ptr = library .get:: *mut cty::c_char>( CString::new("__quantum__rt__array_get_element_ptr_1d") @@ -105,6 +104,7 @@ impl QirRuntime { #[cfg(test)] mod tests { + use crate::runtime::QirRuntime; #[test] fn library_loads_on_new() { let _ = QirRuntime::new(); From d1ef7ebd25d664a80751c7eee3abfb6621a883c1 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Mon, 8 Nov 2021 10:24:54 -0800 Subject: [PATCH 10/13] Trying to get windows working. --- .../Cargo.toml | 1 + .../build.rs | 39 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml index 946be2c4f31..9185a9f25d5 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml @@ -18,6 +18,7 @@ lazy_static = "1.4.0" [build-dependencies] cmake = "0.1.46" bindgen = "0.59.1" +cc = "1.0.71" [lib] diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs index 93ff1487cf0..d66e65716e3 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs @@ -3,25 +3,38 @@ use cmake::Config; use std::boxed::Box; +use std::env; use std::error::Error; fn main() -> Result<(), Box> { println!("cargo:rerun-if-env-changed=TARGET"); println!("cargo:rerun-if-changed=build.rs"); - let path_to_runtime_src = "../Runtime"; - compile_runtime_libraries(path_to_runtime_src)?; + for (key, value) in env::vars() { + println!("{}: {}", key, value); + } + if cfg!(target_os = "windows") { + let path_to_runtime_src = "..\\Runtime"; + compile_runtime_libraries(path_to_runtime_src)?; + } else { + let path_to_runtime_src = "../Runtime"; + compile_runtime_libraries(path_to_runtime_src)?; + } Ok(()) } fn compile_runtime_libraries(path_to_runtime_src: &str) -> Result<(), Box> { let mut config = Config::new(path_to_runtime_src); + + if cfg!(target_os = "windows") { + config.static_crt(true); + } set_compiler(&mut config); set_profile(&mut config)?; - config.generator("Ninja").no_build_target(true); + config.generator("Ninja"); let _ = config.build(); Ok(()) @@ -31,11 +44,21 @@ fn compile_runtime_libraries(path_to_runtime_src: &str) -> Result<(), Box Result<(), Box> { config.define("CMAKE_BUILD_TYPE", "RelWithDebInfo"); + config.define("CMAKE_C_COMPILER_WORKS", "1"); + config.define("CMAKE_CXX_COMPILER_WORKS", "1"); Ok(()) } From 0edd58f0a17cfd58db815d465481dea175d8786f Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Mon, 8 Nov 2021 12:15:34 -0800 Subject: [PATCH 11/13] Making LLVM dependency optional --- src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml | 5 +++-- .../src/qir_libloading.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml index 9185a9f25d5..6403260f74f 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml @@ -11,8 +11,8 @@ cty = "0.2.1" libloading = "0.7.0" log = "0.4.14" tempfile = "3.2.0" -llvm-sys = "110" -inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", default-features = false, features = ["llvm11-0", "target-x86"] } +llvm-sys = { version = "110", optional = true } +inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", default-features = false, features = ["llvm11-0", "target-x86"], optional = true } lazy_static = "1.4.0" [build-dependencies] @@ -26,4 +26,5 @@ cc = "1.0.71" [features] runtime = [] foundation = [] +llvm-libloading = ["llvm-sys", "inkwell"] default = ["runtime", "foundation"] diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/src/qir_libloading.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/src/qir_libloading.rs index da81e0a46c2..0fdfd627505 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/src/qir_libloading.rs +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/src/qir_libloading.rs @@ -33,7 +33,15 @@ pub(crate) unsafe fn load_library_bytes( pub(crate) unsafe fn load_library>(path: P) -> Result> { log::debug!("Loading {}", path.as_ref().display()); let library = Library::new(path.as_ref().as_os_str())?; + + #[cfg(feature = "llvm-libloading")] + load_library_with_llvm(path); + Ok(library) +} + +#[cfg(feature = "llvm-libloading")] +fn load_library_with_llvm>(path: P) { let library_path = path .as_ref() .to_str() @@ -44,5 +52,4 @@ pub(crate) unsafe fn load_library>(path: P) -> Result Date: Mon, 8 Nov 2021 16:44:40 -0800 Subject: [PATCH 12/13] using full path to clang in cmake calls --- .../Cargo.toml | 1 + .../microsoft-quantum-qir-runtime-sys/build.rs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml index 6403260f74f..237bdcaa69a 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/Cargo.toml @@ -19,6 +19,7 @@ lazy_static = "1.4.0" cmake = "0.1.46" bindgen = "0.59.1" cc = "1.0.71" +which = "4.2.2" [lib] diff --git a/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs b/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs index d66e65716e3..287da25af7c 100644 --- a/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs +++ b/src/Qir/microsoft-quantum-qir-runtime-sys/build.rs @@ -31,7 +31,7 @@ fn compile_runtime_libraries(path_to_runtime_src: &str) -> Result<(), Box Result<(), Box Result<(), Box>{ if cfg!(target_os = "linux") { let mut c_cfg = cc::Build::new(); - c_cfg.compiler("clang-11"); + let clang_11 = which::which("clang-11")?; + c_cfg.compiler(clang_11); config.init_c_cfg(c_cfg); let mut cxx_cfg = cc::Build::new(); - cxx_cfg.compiler("clang++-11"); + let clangpp_11 = which::which("clang++-11")?; + cxx_cfg.compiler(clangpp_11); config.init_cxx_cfg(cxx_cfg); } else if cfg!(target_os = "windows") { let mut c_cfg = cc::Build::new(); - c_cfg.compiler("clang.exe"); + let clang = which::which("clang.exe")?; + c_cfg.compiler(clang); config.init_c_cfg(c_cfg); let mut cxx_cfg = cc::Build::new(); - cxx_cfg.compiler("clang++.exe"); + let clangpp = which::which("clang++.exe")?; + cxx_cfg.compiler(clangpp); config.init_cxx_cfg(cxx_cfg); } else if cfg!(target_os = "macos") { // Use macos default } else { panic!("Unsupported platform") } + Ok(()) } fn set_profile(config: &mut Config) -> Result<(), Box> { From f4ee60247ac0bb308735df2b9646d52cce117e6d Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Fri, 19 Nov 2021 13:23:12 -0800 Subject: [PATCH 13/13] Changing package dir due to root Cargo.toml introduction. --- build/pack.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/pack.ps1 b/build/pack.ps1 index 6bb5edcdf49..37882ee7581 100644 --- a/build/pack.ps1 +++ b/build/pack.ps1 @@ -129,10 +129,10 @@ function Pack-Crate() { $OutPath = Resolve-Path (Join-Path $PSScriptRoot $OutPath); } Push-Location (Join-Path $PSScriptRoot $PackageDirectory) - cargo package; - # 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; + cargo package; + # 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 $PSScriptRoot .. "target" "package" "*.crate") $OutPath; Pop-Location }