Skip to content

Commit

Permalink
Set LLVM 13 as the default (#131)
Browse files Browse the repository at this point in the history
* LLVM 13 is now the default LLVM version used for packages and building.
* Fixing LLVM weekly builds
* Generating vscode and cargo config values during build for command line build and editor support.
* Bumping version to 0.5.0a1
* Ignoring 1.64 lint until we update to python 3.7+
  • Loading branch information
idavis authored Jul 13, 2022
1 parent d5ea6ef commit a656b26
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 72 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
config:
- {
os: "ubuntu-20.04",
os: "ubuntu-22.04",
arch: "amd64",
env: {},
}
Expand All @@ -39,26 +39,31 @@ jobs:
submodules: 'recursive'
- name: Linux - Install build dependencies, ccache, ninja
run: sudo apt-get install -y ccache ninja-build
if: ${{ matrix.config.os == 'ubuntu-20.04' }}
if: ${{ matrix.config.os == 'ubuntu-22.04' }}
- name: Windows - Install build dependencies, sccache, ninja
run: choco install --accept-license -y sccache ninja
if: ${{ matrix.config.os == 'windows-2019' }}
- name: MacOS - Install build dependencies, ccache, ninja
run: brew install ccache ninja
if: ${{ matrix.config.os == 'macOS-10.15' }}
- name: Windows - Install LLVM 11.1.0
run: choco install llvm --version=11.1.0 --allow-downgrade
- name: Windows - Install LLVM 13.0.1
run: choco install llvm --version=13.0.1 --allow-downgrade
if: ${{ matrix.config.os == 'windows-2019' }}
- name: "Build and Package LLVM"
run: ./build.ps1 -t package-llvm
shell: pwsh
if: ${{ matrix.config.os != 'ubuntu-22.04' }}
- name: "Build and Package LLVM for manylinux"
run: ./build.ps1 -t package-manylinux-llvm
shell: pwsh
if: ${{ matrix.config.os == 'ubuntu-22.04' }}
- name: Artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
if-no-files-found: error
path: |
target/*.zip
target/*.tar.gz
target/*.rpm
target/*.deb
target/**/*.zip
target/**/*.tar.gz
target/**/*.rpm
target/**/*.deb
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,6 @@ cython_debug/
/.cargo/config.toml
wheelhouse/

/.vscode/settings.json

.local/
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [Unreleased]

## [0.5.0a1] - 2022-07-13

- Added mypy github action to check type annotations and mypy stub files by @WingCode in https://github.com/qir-alliance/pyqir/pull/127
- Evaluator: Raise if bitcode contains unknown external functions. by @georgios-ts in https://github.com/qir-alliance/pyqir/pull/128
- Regenerate mock parser using ANTLR-4.10 by @georgios-ts in https://github.com/qir-alliance/pyqir/pull/129
- Set LLVM 13 as the default by @idavis in https://github.com/qir-alliance/pyqir/pull/131
- Fix type hinting errors by @LaurentAjdnik in https://github.com/qir-alliance/pyqir/pull/133
- Create CODEOWNERS by @samarsha in https://github.com/qir-alliance/pyqir/pull/134

## [0.4.2a1] - 2022-06-03

- Adding ability to do musl/alpine builds by @idavis in https://github.com/qir-alliance/pyqir/pull/111
Expand Down Expand Up @@ -109,7 +118,8 @@ class:

- Initial Release

[Unreleased]: https://github.com/qir-alliance/pyqir/compare/v0.4.2a1...HEAD
[Unreleased]: https://github.com/qir-alliance/pyqir/compare/v0.5.0a1...HEAD
[0.5.0a1]: https://github.com/qir-alliance/pyqir/compare/v0.4.2a1...v0.5.0a1
[0.4.2a1]: https://github.com/qir-alliance/pyqir/compare/v0.4.1a1...v0.4.2a1
[0.4.1a1]: https://github.com/qir-alliance/pyqir/compare/v0.4.0a1...v0.4.1a1
[0.4.0a1]: https://github.com/qir-alliance/pyqir/compare/v0.3.2a1...v0.4.0a1
Expand Down
20 changes: 9 additions & 11 deletions docs/development-guide/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

### Requirements

- [Rust 1.56+](https://rustup.rs/)
- [Rust 1.57+](https://rustup.rs/)
- [Python 3.6+](https://www.python.org)
- [PowerShell 7+
(Core)](https://github.com/powershell/powershell#get-powershell)
- [LLVM/Clang 11.1.0](https://llvm.org/) - See [Installing
- [LLVM/Clang 13.0.1](https://llvm.org/) - See [Installing
LLVM](#installing-llvm)
- If compiling LLVM from source:
- [CMake 3.10+](https://github.com/Kitware/CMake/releases/tag/v3.10.3)
Expand Down Expand Up @@ -63,25 +63,23 @@ Install Rust from [rustup](https://rustup.rs/).

### Installing Clang and Ninja

If you have a working installation of LLVM and [Clang](https://clang.llvm.org/),
each project can be built by running `cargo build` in the project directory. If
not, you can install Clang manually:
You can install Clang manually:

- Linux (Ubuntu)
- Linux (Ubuntu 22.04)

```bash
apt-get update
apt-get install -y clang-11 lldb-11 lld-11 clangd-11
apt-get install -y --no-install-recommends ninja-build clang-tidy-11 build-essential
apt-get install -y clang-13 lldb-13 lld-11 clangd-13
apt-get install -y --no-install-recommends ninja-build clang-tidy-13 build-essential
```

- Windows
- Download and install the `LLVM-11.1.0-win64.exe` from the [11.1.0
Release](https://github.com/llvm/llvm-project/releases/tag/llvmorg-11.1.0)
- Download and install the `LLVM-13.0.1-win64.exe` from the [13.0.1
Release](https://github.com/llvm/llvm-project/releases/tag/llvmorg-13.0.1)
page.
- This package only contains the Clang components. There is no package that
contains Clang and LLVM.
- MacOS
- MacOS
- Should be preinstalled.

### Installing LLVM
Expand Down
65 changes: 44 additions & 21 deletions eng/psakefile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ properties {
$repo = @{}
$repo.root = Resolve-Path (Split-Path -parent $PSScriptRoot)
$repo.target = Join-Path $repo.root "target"
$repo.dot_cargo = Join-Path $repo.root ".cargo"
$repo.workspace_config_file = Join-Path $repo.dot_cargo "config.toml"
$repo.dot_vscode = Join-Path $repo.root ".vscode"
$repo.vscode_config_file = Join-Path $repo.dot_vscode "settings.json"

$pyqir = @{}

Expand Down Expand Up @@ -74,7 +78,7 @@ task run-manylinux-container-image -preaction { Write-CacheStats } -postaction {

$cacheMount, $cacheEnv = Get-CCacheParams

Write-BuildLog "Running container image:"
Write-BuildLog "Running container image: $($linux.manylinux_tag)"
$ioVolume = "$($srcPath):$($linux.manylinux_root)"
$userName = Get-LinuxContainerUserName

Expand All @@ -93,7 +97,7 @@ task run-musllinux-container-image -preaction { Write-CacheStats } -postaction {

$cacheMount, $cacheEnv = Get-CCacheParams

Write-BuildLog "Running container image:"
Write-BuildLog "Running container image: $($linux.musllinux_tag)"
$ioVolume = "$($srcPath):$($linux.musllinux_root)"
$userName = Get-LinuxContainerUserName
if (Test-CI) {
Expand Down Expand Up @@ -243,17 +247,19 @@ task check-environment {
"Neither the VIRTUAL_ENV nor CONDA_PREFIX environment variables are set).",
"See https://virtualenv.pypa.io/en/latest/index.html on how to use virtualenv"
)
if((Test-InVirtualEnvironment) -eq $false) {
if ((Test-InVirtualEnvironment) -eq $false) {
Write-BuildLog "No virtual environment found."
$pyenv = Join-Path $repo.target ".env"
Write-BuildLog "Setting up virtual environment in $($pyenv)"
& $python -m venv $pyenv
if($IsWindows) {
if ($IsWindows) {
. (Join-Path $pyenv "Scripts" "Activate.ps1")
} else {
}
else {
. (Join-Path $pyenv "bin" "Activate.ps1")
}
} else {
}
else {
Write-BuildLog "Virtual environment found."
}
# ensure that we are now in a virtual environment
Expand Down Expand Up @@ -318,26 +324,42 @@ task install-llvm-from-source -depends configure-sccache -postaction { Write-Cac
}

task package-musllinux-llvm -depends build-musllinux-container-image -preaction { Write-CacheStats } -postaction { Write-CacheStats } {
if ($IsLinux) {
$srcPath = $repo.root
$ioVolume = "$($srcPath):$($linux.musllinux_root)"
$userName = Get-LinuxContainerUserName
$srcPath = $repo.root

Invoke-LoggedCommand {
docker run --rm --user $userName -v $ioVolume -w "$($linux.musllinux_root)/qirlib" -e QIRLIB_PKG_DEST="$($linux.musllinux_root)/target" "$($linux.musllinux_tag)" cargo build --release --no-default-features --features package-llvm -vv
}
# For any of the volumes mapped, if the dir doesn't exist,
# docker will create it and it will be owned by root and
# the caching/install breaks with permission errors.
# New-Item is idempotent so we don't need to check for existence

$cacheMount, $cacheEnv = Get-CCacheParams

Write-BuildLog "Running container image: $($linux.musllinux_tag)"
$ioVolume = "$($srcPath):$($linux.musllinux_root)"
$userName = Get-LinuxContainerUserName
if (Test-CI) {
$userName = "root"
}
Invoke-LoggedCommand {
docker run --rm --user $userName -v $ioVolume @cacheMount @cacheEnv -w "$($linux.musllinux_root)" -e QIRLIB_PKG_DEST="$($linux.musllinux_root)/target/musllinux" "$($linux.musllinux_tag)" pwsh build.ps1 -t package-llvm
}
}

task package-manylinux-llvm -depends build-manylinux-container-image -preaction { Write-CacheStats } -postaction { Write-CacheStats } {
if ($IsLinux) {
$srcPath = $repo.root
$ioVolume = "$($srcPath):$($linux.manylinux_root)"
$userName = Get-LinuxContainerUserName
$srcPath = $repo.root

Invoke-LoggedCommand {
docker run --rm --user $userName -v $ioVolume -w "$($linux.manylinux_root)/qirlib" -e QIRLIB_PKG_DEST="$($linux.manylinux_root)/target" "$($linux.manylinux_tag)" conda run --no-capture-output cargo build --release --no-default-features --features package-llvm -vv
}
# For any of the volumes mapped, if the dir doesn't exist,
# docker will create it and it will be owned by root and
# the caching/install breaks with permission errors.
# New-Item is idempotent so we don't need to check for existence

$cacheMount, $cacheEnv = Get-CCacheParams

Write-BuildLog "Running container image: $($linux.manylinux_tag)"
$ioVolume = "$($srcPath):$($linux.manylinux_root)"
$userName = Get-LinuxContainerUserName

Invoke-LoggedCommand {
docker run --rm --user $userName -v $ioVolume @cacheMount @cacheEnv -w "$($linux.manylinux_root)" -e QIRLIB_PKG_DEST="$($linux.manylinux_root)/target/manylinux" "$($linux.manylinux_tag)" conda run --no-capture-output pwsh build.ps1 -t package-llvm
}
}

Expand All @@ -350,9 +372,10 @@ task package-llvm {
$clear_pkg_dest_var = $true
$env:QIRLIB_PKG_DEST = Join-Path $repo.root "target"
}
New-Item $env:QIRLIB_PKG_DEST -ItemType Directory -Force
try {
Invoke-LoggedCommand -wd $pyqir.qirlib.dir {
cargo build --release --no-default-features --features package-llvm -vv
cargo build --release --no-default-features --features "package-llvm,$(Get-LLVMFeatureVersion)-no-llvm-linking" -vv
}
}
finally {
Expand Down
36 changes: 31 additions & 5 deletions eng/utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,47 @@ function Test-InDevContainer {
$IsLinux -and (Test-Path env:\IN_DEV_CONTAINER)
}

# This method should be able to be removed when Rust 1.56 is released
# which contains the feature for env sections in the .cargo/config.toml

# Sets the LLVM path in the env section of the .cargo/config.toml
# Configures vscode rust analyzer to the correct features
function Use-LlvmInstallation {
param (
[string]$path
)
Write-BuildLog "LLVM installation set to: $path"
Write-BuildLog "Setting LLVM installation to: $path"

$llvm_config_options = @(Get-Command (Join-Path $path "bin" "llvm-config*"))
Assert ($llvm_config_options.Length -gt 0) "llvm config not found in $path"

$llvm_config = $llvm_config_options[0].Source
Write-BuildLog "Found llvm-config : $llvm_config"

$version = [Version]::Parse("$(&$llvm_config --version)")
$prefix = "LLVM_SYS_$($version.Major)0_PREFIX"

Write-BuildLog "Setting $prefix set to: $path"
[Environment]::SetEnvironmentVariable($prefix, $path)

if ($IsWindows) {
# we have to escape '\'
$path = $path.Replace('\', '\\')
}

# Create the workspace cofig.toml and set the LLVM_SYS env var
New-Item -ItemType File -Path $repo.workspace_config_file -Force
Add-Content -Path $repo.workspace_config_file -Value "[env]"
Add-Content -Path $repo.workspace_config_file -Value "$($prefix) = `"$($path)`""

# Add llvm feature version for rust-analyzer extension
$vscode_settings = @{}
if (!(Test-Path $repo.vscode_config_file)) {
New-Item -ItemType File -Path $repo.vscode_config_file -Force
}
else {
$vscode_settings = Get-Content $repo.vscode_config_file | ConvertFrom-Json -AsHashtable
}

$vscode_settings."rust-analyzer.cargo.features" = @("$(Get-LLVMFeatureVersion)")
$vscode_settings | ConvertTo-Json | Set-Content -Path $repo.vscode_config_file
}

function Test-LlvmConfig {
Expand Down Expand Up @@ -229,7 +255,7 @@ function Get-LLVMFeatureVersion {
}
else {
# "llvm11-0", "llvm12-0", "llvm13-0", "llvm14-0"
"llvm11-0"
"llvm13-0"
}
}

Expand Down
4 changes: 2 additions & 2 deletions notice.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ This work contains work released under the following licenses:
{{/each}}{{/each}}
LLVM 11.0 - Apache-2.0 WITH LLVM-exception - Apache License v2.0 with LLVM Exceptions
LLVM 13.0 - Apache-2.0 WITH LLVM-exception - Apache License v2.0 with LLVM Exceptions
https://github.com/llvm/llvm-project
https://github.com/llvm/llvm-project/blob/llvmorg-11.1.0/llvm/LICENSE.TXT
https://github.com/llvm/llvm-project/blob/llvmorg-13.0.1/llvm/LICENSE.TXT
==============================================================================
The LLVM Project is under the Apache License v2.0 with LLVM Exceptions:
Expand Down
2 changes: 1 addition & 1 deletion pyqir-evaluator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Microsoft"]
name = "pyqir-evaluator"
version = "0.4.2-alpha"
version = "0.5.0-alpha"
edition = "2018"
license = "MIT"
description = "Python based QIR Evaluation (JIT) library."
Expand Down
6 changes: 3 additions & 3 deletions pyqir-evaluator/NOTICE-WHEEL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9103,7 +9103,7 @@ SOFTWARE.



pyqir-evaluator 0.4.2-alpha - SPDX: MIT - MIT License
pyqir-evaluator 0.5.0-alpha - SPDX: MIT - MIT License
https://github.com/qir-alliance/pyqir

MIT License
Expand Down Expand Up @@ -9131,10 +9131,10 @@ SOFTWARE.



LLVM 11.0 - Apache-2.0 WITH LLVM-exception - Apache License v2.0 with LLVM Exceptions
LLVM 13.0 - Apache-2.0 WITH LLVM-exception - Apache License v2.0 with LLVM Exceptions
https://github.com/llvm/llvm-project

https://github.com/llvm/llvm-project/blob/llvmorg-11.1.0/llvm/LICENSE.TXT
https://github.com/llvm/llvm-project/blob/llvmorg-13.0.1/llvm/LICENSE.TXT

==============================================================================
The LLVM Project is under the Apache License v2.0 with LLVM Exceptions:
Expand Down
2 changes: 1 addition & 1 deletion pyqir-evaluator/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pyqir-evaluator"
version = "0.4.2a1"
version = "0.5.0a1"
requires-python = ">=3.6"

[build-system]
Expand Down
2 changes: 1 addition & 1 deletion pyqir-generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Microsoft"]
name = "pyqir-generator"
version = "0.4.2-alpha"
version = "0.5.0-alpha"
edition = "2018"
license = "MIT"
description = "Python based QIR generator library."
Expand Down
Loading

0 comments on commit a656b26

Please sign in to comment.