This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Refactor QIR runtime CMakeLists and dynamic libraries #549
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d4ff288
Refactor cmakelists into common modules
swernli a6ad046
Split out QSharpCore lib
swernli 072c41d
Create full dynamic libs, including tracer
swernli 12ec703
Produce QIR dll pipeline artifacts
swernli 079f87e
Fix cmake existence check for generated obj
swernli 8415529
Fix dynamic lib linking in tests
swernli f473cc4
Use dynamic dependency for non-test libs too
swernli ab5f859
Clean up simulators CMakeLists
swernli 5be4f01
Expand use of dllexport to support Windows
swernli e8c3f68
Fix missing include
swernli 24834fa
Add thread_local global context exported accessor
swernli 1d6cfdf
Move implementaiton out of header
swernli 2ed8c91
Fix target_compile_definitions
swernli bf4c7f4
Fix typos
swernli d4bc496
More compile definitions
swernli 9cc3e7f
Use tracer types differently
swernli b78ec6b
Add dllexport to IR
swernli ef1dfed
Update test linkage, ResultOne/Zero def
swernli 91acd00
Try updating signature of ResultOne/Zero
swernli ae615f5
Try using dllimport for external global IR
swernli 4dd6875
Fix tracer API export
swernli a5733e2
Put back cmake install runtime directives
swernli 94f66a5
Return to plat specific handling of Result global
swernli 74e19af
move build and test of QIR to after sln
swernli ac74215
Update build scripts and readme
swernli 725b07a
Update build scripts for PR feedback
swernli b01e2eb
Fix qir build with dynamic path update
swernli c31949a
Rename qir.dll to Microsoft.Quantum.Qir.Runtime
swernli 275d354
Rename QSharpCore and qirtracer dlls
swernli bb80b93
Separate out quantum__qis into QSharp.Foundation
swernli 4c48ce2
Merge remote-tracking branch 'origin/main' into swernli/qirruntime-re…
swernli 500f0bc
Convert sample to dynamic, add to scripts
swernli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,68 +1,94 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| if ($Env:ENABLE_QIRRUNTIME -eq "true") { | ||
| Write-Host "##[info]Compile Q# Projects into QIR" | ||
| $qirStaticPath = Join-Path $PSScriptRoot test QIR-static qsharp | ||
| dotnet build $qirStaticPath -c $Env:BUILD_CONFIGURATION -v $Env:BUILD_VERBOSITY | ||
| if ($LastExitCode -ne 0) { | ||
| Write-Host "##vso[task.logissue type=error;]Failed to compile Q# project at '$qirStaticPath' into QIR." | ||
| return | ||
| } | ||
| Copy-Item -Path (Join-Path $qirStaticPath qir *.ll) -Destination (Split-Path $qirStaticPath -Parent) | ||
| # Also copy to drops so it ends up in build artifacts, for easier post-build debugging. | ||
| Copy-Item -Path (Join-Path $qirStaticPath qir *.ll) -Destination $Env:DROPS_DIR | ||
| & (Join-Path $PSScriptRoot .. .. build set-env.ps1) | ||
| Write-Host "##[info]Compile Q# Projects into QIR" | ||
| $qirStaticPath = Join-Path $PSScriptRoot test QIR-static qsharp | ||
| dotnet build $qirStaticPath -c $Env:BUILD_CONFIGURATION -v $Env:BUILD_VERBOSITY | ||
| if ($LastExitCode -ne 0) { | ||
| Write-Host "##vso[task.logissue type=error;]Failed to compile Q# project at '$qirStaticPath' into QIR." | ||
| return | ||
| } | ||
| Copy-Item -Path (Join-Path $qirStaticPath qir *.ll) -Destination (Split-Path $qirStaticPath -Parent) | ||
| # Also copy to drops so it ends up in build artifacts, for easier post-build debugging. | ||
| Copy-Item -Path (Join-Path $qirStaticPath qir *.ll) -Destination $Env:DROPS_DIR | ||
|
|
||
| Write-Host "##[info]Build QIR Runtime" | ||
| $oldCC = $env:CC | ||
| $oldCXX = $env:CXX | ||
| $oldRC = $env:RC | ||
| Write-Host "##[info]Build QIR Runtime" | ||
| $oldCC = $env:CC | ||
| $oldCXX = $env:CXX | ||
| $oldRC = $env:RC | ||
|
|
||
| $clangTidy = "" | ||
| $clangTidy = "" | ||
|
|
||
| if (($IsMacOS) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin")))) | ||
| { | ||
| Write-Host "On MacOS build QIR Runtim using the default C/C++ compiler (should be AppleClang)" | ||
| } | ||
| elseif (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin")))) | ||
| { | ||
| Write-Host "On Linux build QIR Runtime using Clang" | ||
| $env:CC = "/usr/bin/clang-11" | ||
| $env:CXX = "/usr/bin/clang++-11" | ||
| $env:RC = "/usr/bin/clang++-11" | ||
| $clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy-11" | ||
| } | ||
| elseif (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) | ||
| { | ||
| Write-Host "On Windows build QIR Runtime using Clang" | ||
| $env:CC = "C:\Program Files\LLVM\bin\clang.exe" | ||
| $env:CXX = "C:\Program Files\LLVM\bin\clang++.exe" | ||
| $env:RC = "C:\Program Files\LLVM\bin\clang++.exe" | ||
| $llvmExtras = (Join-Path $PSScriptRoot "externals/LLVM") | ||
| $env:PATH += ";$llvmExtras" | ||
| } else { | ||
| Write-Host "##vso[task.logissue type=error;]Failed to identify the OS. Will use default CXX compiler" | ||
| } | ||
| if (($IsMacOS) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin")))) | ||
| { | ||
| Write-Host "On MacOS build QIR Runtime using the default C/C++ compiler (should be AppleClang)" | ||
| } | ||
| elseif (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin")))) | ||
| { | ||
| Write-Host "On Linux build QIR Runtime using Clang" | ||
| $env:CC = "clang-11" | ||
| $env:CXX = "clang++-11" | ||
| $env:RC = "clang++-11" | ||
| $clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy-11" | ||
| } | ||
| elseif (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) | ||
| { | ||
| Write-Host "On Windows build QIR Runtime using Clang" | ||
| $env:CC = "clang.exe" | ||
| $env:CXX = "clang++.exe" | ||
| $env:RC = "clang++.exe" | ||
| $llvmExtras = Join-Path $PSScriptRoot externals LLVM | ||
| $env:PATH += ";$llvmExtras" | ||
|
|
||
| $qirRuntimeBuildFolder = (Join-Path $PSScriptRoot "build\$Env:BUILD_CONFIGURATION") | ||
| if (-not (Test-Path $qirRuntimeBuildFolder)) { | ||
| New-Item -Path $qirRuntimeBuildFolder -ItemType "directory" | ||
| if (!(Get-Command clang -ErrorAction SilentlyContinue) -and (choco find --idonly -l llvm) -contains "llvm") { | ||
| # LLVM was installed by Chocolatey, so add the install location to the path. | ||
| $env:PATH += ";$($env:SystemDrive)\Program Files\LLVM\bin" | ||
| } | ||
|
|
||
| Push-Location $qirRuntimeBuildFolder | ||
| if (Get-Command clang-tidy -ErrorAction SilentlyContinue) { | ||
| # Only run clang-tidy if it's installed. This is because the package used by chocolatey on | ||
| # the build pipeline doesn't include clang-tidy, so we allow skipping that there and let | ||
| # the Linux build catch tidy issues. | ||
| $clangTidy = "-DCMAKE_CXX_CLANG_TIDY=clang-tidy" | ||
| } | ||
| } else { | ||
| Write-Host "##vso[task.logissue type=error;]Failed to identify the OS. Will use default CXX compiler" | ||
| } | ||
|
|
||
| cmake -G Ninja $clangTidy -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" ../.. | ||
| cmake --build . --target install | ||
| $qirRuntimeBuildFolder = (Join-Path $PSScriptRoot "build\$Env:BUILD_CONFIGURATION") | ||
| if (-not (Test-Path $qirRuntimeBuildFolder)) { | ||
| New-Item -Path $qirRuntimeBuildFolder -ItemType "directory" | ||
| } | ||
|
|
||
| Pop-Location | ||
| Push-Location $qirRuntimeBuildFolder | ||
|
|
||
| $env:CC = $oldCC | ||
| $env:CXX = $oldCXX | ||
| $env:RC = $oldRC | ||
| cmake -G Ninja $clangTidy -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" ../.. | ||
| if ($LastExitCode -ne 0) { | ||
| Write-Host "##vso[task.logissue type=error;]Failed to generate QIR Runtime." | ||
| } | ||
| cmake --build . --target install | ||
| if ($LastExitCode -ne 0) { | ||
| Write-Host "##vso[task.logissue type=error;]Failed to build QIR Runtime." | ||
| } | ||
|
|
||
| if ($LastExitCode -ne 0) { | ||
| Write-Host "##vso[task.logissue type=error;]Failed to build QIR Runtime." | ||
| } | ||
| } else { | ||
| Write-Host "To enable build of QIR Runtime set ENABLE_QIRRUNTIME environment variable to 'true'" | ||
| $os = "win32" | ||
| $pattern = "*.dll" | ||
| if ($IsMacOS) { | ||
| $os = "osx" | ||
| $pattern = "*.dylib" | ||
| } elseif ($IsLinux) { | ||
| $os = "linux" | ||
| $pattern = "*.so" | ||
| } | ||
| $osQirDropFolder = Join-Path $Env:DROPS_DIR QIR $os | ||
| if (!(Test-Path $osQirDropFolder)) { | ||
| New-Item -Path $osQirDropFolder -ItemType "directory" | ||
| } | ||
| Copy-Item (Join-Path . bin $pattern) $osQirDropFolder | ||
|
|
||
| Pop-Location | ||
|
|
||
| $env:CC = $oldCC | ||
| $env:CXX = $oldCXX | ||
| $env:RC = $oldRC | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.