diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.yml index 81a720ce21f7..aabc5e9a55f3 100644 --- a/.github/workflows/build_package.yml +++ b/.github/workflows/build_package.yml @@ -18,10 +18,19 @@ on: description: "Suffix to append to package names" required: false default: "" - package_version: + legacy_package_version: description: "Version of the package" required: true default: "0.1a1" + package_version: + description: "Version of the package" + required: true + compiler_package_version: + description: "Version of the iree-compiler package" + required: true + runtime_package_version: + description: "Version of the iree-runtime package" + required: true release_id: description: "Release id to upload artifacts to" default: "" @@ -30,8 +39,78 @@ on: default: "" jobs: + # Note: For cross platform builds, it's useful to just generate the + # metadata on Linux and pass that to later jobs using artifacts. The + # metadata generation could also happen in a separate workflow and + # might be moved. + setup_metadata: + runs-on: ubuntu-24.04 + steps: + - name: Checkout repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + path: "c" # Windows can hit path length limits, so use a short path. + submodules: false + ref: ${{ github.event.inputs.commit }} + + - name: Write version info (release) + id: version_local + shell: bash + run: | + # Note: `version_info.json` holds the CalVer version and is still used + # for iree-tools-tf and iree-tools-tflite. + cat << EOF > ./c/version_info.json + { + "package-suffix": "${{ github.event.inputs.package_suffix }}", + "package-version": "${{ github.event.inputs.legacy_package_version }}", + "iree-revision": "$(cd ./c && git rev-parse HEAD)" + } + EOF + cat ./c/version_info.json + + echo "iree-dist" + cat << EOF > ./c/version_local.json + { + "package-suffix": "${{ github.event.inputs.package_suffix }}", + "package-version": "${{ github.event.inputs.package_version }}", + "iree-revision": "$(cd ./c && git rev-parse HEAD)" + } + EOF + cat ./c/version_local.json + + echo "iree-compiler" + cat << EOF > ./c/compiler/version_local.json + { + "package-suffix": "${{ github.event.inputs.package_suffix }}", + "package-version": "${{ github.event.inputs.compiler_package_version }}", + "iree-revision": "$(cd ./c && git rev-parse HEAD)" + } + EOF + cat ./c/compiler/version_local.json + + echo "iree-runtime" + cat << EOF > ./c/runtime/version_local.json + { + "package-suffix": "${{ github.event.inputs.package_suffix }}", + "package-version": "${{ github.event.inputs.runtime_package_version }}", + "iree-revision": "$(cd ./c && git rev-parse HEAD)" + } + EOF + cat ./c/runtime/version_local.json + + - name: Upload version_local.json + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 + with: + name: version_local + path: | + ./c/version_info.json + ./c/version_local.json + ./c/compiler/version_local.json + ./c/runtime/version_local.json + build_packages: name: "${{ matrix.build-family }} :: Build ${{ matrix.build-package }} Package" + needs: setup_metadata runs-on: ${{ matrix.runs-on }} continue-on-error: ${{ matrix.experimental }} strategy: @@ -124,36 +203,16 @@ jobs: run: sudo ./c/build_tools/python_deploy/install_macos_deps.sh ########################################################################## - # Write version_info.json + # Download version_info.json # Various tools will read this in order to embed release information. ########################################################################## - - name: Write version info (release) - if: "matrix.build-family != 'windows'" - shell: bash - run: | - cat << EOF > ./c/version_info.json - { - "package-suffix": "${{ github.event.inputs.package_suffix }}", - "package-version": "${{ github.event.inputs.package_version }}", - "iree-revision": "$(cd ./c && git rev-parse HEAD)" - } - EOF - cat ./c/version_info.json - - name: Write version info Windows (release) - if: "matrix.build-family == 'windows'" - shell: powershell - run: | - cd c - $verinfoprop = @{ - 'package-suffix'= "${{ github.event.inputs.package_suffix }}" - 'package-version'= "${{ github.event.inputs.package_version }}" - 'iree-revision'= $(git rev-parse HEAD) - } - - $info = New-Object -TypeName PSObject -Prop $verinfoprop - $info = $info | ConvertTo-JSON - $info | Out-File "version_info.json" -Encoding "ASCII" + - name: Download version_local.json + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: version_local + path: ./c/ + merge-multiple: true ########################################################################## # Build the main distribution tarball. diff --git a/.github/workflows/oneshot_candidate_release.yml b/.github/workflows/oneshot_candidate_release.yml index 595ba72d70ec..ada3aefcfb63 100644 --- a/.github/workflows/oneshot_candidate_release.yml +++ b/.github/workflows/oneshot_candidate_release.yml @@ -16,11 +16,25 @@ jobs: - name: Compute version run: | git fetch --depth=1 origin +refs/tags/*:refs/tags/* - package_version="$(printf '%(%Y%m%d)T.${{ github.run_number }}')" - tag_name="candidate-${package_version}" + + # common version + tag + package_version="$(python3 build_tools/python_deploy/compute_common_version.py -rc)" + tag_name="iree-${package_version}" echo "package_version=${package_version}" >> $GITHUB_ENV echo "tag_name=${tag_name}" >> $GITHUB_ENV + # legacy package version (for iree-tools-{tf,tflite}) + legacy_package_version="$(printf '%(%Y%m%d)T.${{ github.run_number }}')" + echo "legacy_package_version=${legacy_package_version}" >> $GITHUB_ENV + + # iree-compiler version + compiler_package_version="$(python3 build_tools/python_deploy/compute_local_version.py compiler -rc)" + echo "compiler_package_version=${compiler_package_version}" >> $GITHUB_ENV + + # iree-runtime version + runtime_package_version="$(python3 build_tools/python_deploy/compute_local_version.py runtime -rc)" + echo "runtime_package_version=${runtime_package_version}" >> $GITHUB_ENV + - name: Updating candidate tag run: | git tag "${tag_name}" @@ -51,4 +65,12 @@ jobs: workflow: Build Release Packages token: ${{ secrets.WRITE_ACCESS_TOKEN }} ref: "${{ env.tag_name }}" - inputs: '{"package_suffix": "", "package_version": "${{ env.package_version }}", "release_id": "${{ steps.create_release.outputs.id }}"}' + inputs: | + { + "package_suffix": "", + "legacy_package_version": "${{ env.legacy_package_version }}", + "package_version": "${{ env.package_version }}", + "compiler_package_version": "${{ env.compiler_package_version }}", + "runtime_package_version": "${{ env.runtime_package_version }}", + "release_id": "${{ steps.create_release.outputs.id }}" + } diff --git a/.github/workflows/pkgci.yml b/.github/workflows/pkgci.yml index 5c98cda6468b..69d2f43dda8e 100644 --- a/.github/workflows/pkgci.yml +++ b/.github/workflows/pkgci.yml @@ -34,8 +34,6 @@ jobs: needs: setup if: contains(fromJson(needs.setup.outputs.enabled-jobs), 'build_packages') uses: ./.github/workflows/pkgci_build_packages.yml - with: - package_version: 0.dev1 # Package sanity checks. unit_test: diff --git a/.github/workflows/pkgci_build_packages.yml b/.github/workflows/pkgci_build_packages.yml index 9df12ed1633f..40771a084991 100644 --- a/.github/workflows/pkgci_build_packages.yml +++ b/.github/workflows/pkgci_build_packages.yml @@ -7,10 +7,6 @@ name: PkgCI Build Packages on: workflow_call: - inputs: - package_version: - type: string - required: true jobs: linux_x86_64_release_packages: @@ -30,18 +26,53 @@ jobs: uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: submodules: true + - name: Setup Python + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.3 + with: + python-version: 3.12 + cache: "pip" + - name: Install Python packages + run: | + pip install packaging + pip freeze - name: Write version info shell: bash run: | + package_version="$(python3 build_tools/python_deploy/compute_common_version.py -dev)" cat << EOF > version_info.json { "package-suffix": "${PACKAGE_SUFFIX}", - "package-version": "${{ inputs.package_version }}", + "package-version": "${package_version}", "iree-revision": "$(cd ../iree && git rev-parse HEAD)" } EOF realpath version_info.json cat version_info.json + echo + + compiler_package_version="$(python3 build_tools/python_deploy/compute_local_version.py compiler -dev)" + cat << EOF > compiler/version_local.json + { + "package-suffix": "${PACKAGE_SUFFIX}", + "package-version": "${compiler_package_version}", + "iree-revision": "$(cd ../iree && git rev-parse HEAD)" + } + EOF + realpath compiler/version_local.json + cat compiler/version_local.json + echo + + runtime_package_version="$(python3 build_tools/python_deploy/compute_local_version.py runtime -dev)" + cat << EOF > runtime/version_local.json + { + "package-suffix": "${PACKAGE_SUFFIX}", + "package-version": "${runtime_package_version}", + "iree-revision": "$(cd ../iree && git rev-parse HEAD)" + } + EOF + realpath runtime/version_local.json + cat runtime/version_local.json + - name: Enable cache uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 with: diff --git a/.github/workflows/schedule_candidate_release.yml b/.github/workflows/schedule_candidate_release.yml index c5d1a8be33b1..d294201ce779 100644 --- a/.github/workflows/schedule_candidate_release.yml +++ b/.github/workflows/schedule_candidate_release.yml @@ -38,11 +38,24 @@ jobs: - name: Compute version run: | - package_version="$(printf '%(%Y%m%d)T.${{ github.run_number }}')" - tag_name="candidate-${package_version}" + # common version + tag + package_version="$(python3 build_tools/python_deploy/compute_common_version.py -rc)" + tag_name="iree-${package_version}" echo "package_version=${package_version}" >> $GITHUB_ENV echo "tag_name=${tag_name}" >> $GITHUB_ENV + # legacy package version (for iree-tools-{tf,tflite}) + legacy_package_version="$(printf '%(%Y%m%d)T.${{ github.run_number }}')" + echo "legacy_package_version=${legacy_package_version}" >> $GITHUB_ENV + + # iree-compiler version + compiler_package_version="$(python3 build_tools/python_deploy/compute_local_version.py compiler -rc)" + echo "compiler_package_version=${compiler_package_version}" >> $GITHUB_ENV + + # iree-runtime version + runtime_package_version="$(python3 build_tools/python_deploy/compute_local_version.py runtime -rc)" + echo "runtime_package_version=${runtime_package_version}" >> $GITHUB_ENV + - name: Updating candidate tag run: | git tag "${tag_name}" @@ -73,7 +86,10 @@ jobs: inputs: | { "package_suffix": "", + "legacy_package_version": "${{ env.legacy_package_version }}", "package_version": "${{ env.package_version }}", + "compiler_package_version": "${{ env.compiler_package_version }}", + "runtime_package_version": "${{ env.runtime_package_version }}", "release_id": "${{ steps.create_release.outputs.id }}", "commit": "${{ steps.last_green_commit.outputs.release-commit }}" } diff --git a/.gitignore b/.gitignore index 58f783104044..700eccf7081e 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ Testing/ configured.bazelrc user.bazelrc version_info.json +version_local.json CMakeUserPresets.json # Dear ImGui Ini files diff --git a/RELEASING.md b/RELEASING.md index 749f2d30f172..f9950bb7ed11 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -11,8 +11,7 @@ IREE development is primarily driven via automated nightly release snapshots. These are scheduled automatically each day by the `schedule_candidate_release.yml` workflow, which selects a green commit from main (for non optional CI tasks), created a tag of the format -`candidate-{YYYYMMDD}.{BUILDNUM}` and schedules automation to populate the -release. +`iree-{X.Y.ZrcYYYYMMDD}` and schedules automation to populate the release. The `build_package.yml` workflow then runs jobs to do builds for all platforms and packages, finally triggering the diff --git a/build_tools/github_actions/build_dist.py b/build_tools/github_actions/build_dist.py index cbc7497bb809..23068a880ff9 100644 --- a/build_tools/github_actions/build_dist.py +++ b/build_tools/github_actions/build_dist.py @@ -19,7 +19,8 @@ following sub-directories: - c/ : Main IREE repository checkout. - bindist/ : Directory where binary distribution artifacts are written. - - c/version_info.json : Version config information. + - c/version_info.json : Version config information (legacy). + - c/version_local.json : Version config information. Within the build environment (which may be the naked runner or a docker image): - iree-build/ : The build tree. @@ -80,14 +81,14 @@ # Load version info. def load_version_info(): - with open(os.path.join(IREESRC_DIR, "version_info.json"), "rt") as f: + with open(os.path.join(IREESRC_DIR, "version_local.json"), "rt") as f: return json.load(f) try: version_info = load_version_info() except FileNotFoundError: - print("version_info.json not found. Using defaults") + print("version_local.json not found. Using version.json defaults") version_info = { "package-version": "0.1dev1", "package-suffix": "-dev", diff --git a/build_tools/github_actions/ci_requirements.txt b/build_tools/github_actions/ci_requirements.txt index f4938640f732..9f707f1fb2f2 100644 --- a/build_tools/github_actions/ci_requirements.txt +++ b/build_tools/github_actions/ci_requirements.txt @@ -2,3 +2,4 @@ # Ensure a recent cmake cmake>=3.18.4 ninja +packaging diff --git a/build_tools/python_deploy/compute_common_version.py b/build_tools/python_deploy/compute_common_version.py new file mode 100644 index 000000000000..e9409522f6d4 --- /dev/null +++ b/build_tools/python_deploy/compute_common_version.py @@ -0,0 +1,64 @@ +# Copyright 2024 The IREE Authors +# +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# This scripts grabs the X.Y.Z[.dev]` version identifier from the +# compiler's and runtime's `version.json` files and computes the +# shared version. + +import argparse +from pathlib import Path +import json +from datetime import datetime +import subprocess + +from packaging.version import Version + + +parser = argparse.ArgumentParser() +release_type = parser.add_mutually_exclusive_group() +release_type.add_argument("-rc", "--nightly-release", action="store_true") +release_type.add_argument("-dev", "--development-release", action="store_true") +release_type.add_argument("--custom-string", action="store", type=str) +args = parser.parse_args() + +THIS_DIR = Path(__file__).parent.resolve() +REPO_ROOT = THIS_DIR.parent.parent + +VERSION_FILE_COMPILER = REPO_ROOT / "compiler/version.json" +VERSION_FILE_RUNTIME = REPO_ROOT / "runtime/version.json" + + +def load_version_info(version_file): + with open(version_file, "rt") as f: + return json.load(f) + + +compiler_version = load_version_info(VERSION_FILE_COMPILER) +COMPILER_PACKAGE_VERSION = compiler_version.get("package-version") +COMPILER_BASE_VERSION = Version(COMPILER_PACKAGE_VERSION).base_version + +runtime_version = load_version_info(VERSION_FILE_RUNTIME) +RUNTIME_PACKAGE_VERSION = runtime_version.get("package-version") +RUNTIME_BASE_VERSION = Version(RUNTIME_PACKAGE_VERSION).base_version + +if RUNTIME_BASE_VERSION > COMPILER_BASE_VERSION: + CURRENT_VERSION = RUNTIME_BASE_VERSION +else: + CURRENT_VERSION = COMPILER_BASE_VERSION + +if args.nightly_release: + CURRENT_VERSION += "rc" + datetime.today().strftime("%Y%m%d") + +if args.development_release: + CURRENT_VERSION += ( + ".dev+" + + subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip() + ) + +if args.custom_string: + CURRENT_VERSION += args.custom_string + +print(CURRENT_VERSION) diff --git a/build_tools/python_deploy/compute_local_version.py b/build_tools/python_deploy/compute_local_version.py new file mode 100644 index 000000000000..897e5dc3515d --- /dev/null +++ b/build_tools/python_deploy/compute_local_version.py @@ -0,0 +1,79 @@ +# Copyright 2024 The IREE Authors +# +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# This scripts grabs the X.Y.Z[.dev]` version identifier from a +# `version_info.json` and writes the corresponding +# `X.Y.ZrcYYYYMMDD` version identifier to `version_rc_info.json`. + +import argparse +from pathlib import Path +import json +from datetime import datetime +import sys +import subprocess + +from packaging.version import Version + + +parser = argparse.ArgumentParser() +parser.add_argument("path", type=Path) +parser.add_argument("--write-json", action="store_true") + +release_type = parser.add_mutually_exclusive_group() +release_type.add_argument("-stable", "--stable-release", action="store_true") # default +release_type.add_argument("-rc", "--nightly-release", action="store_true") +release_type.add_argument("-dev", "--development-release", action="store_true") +release_type.add_argument("--custom-string", action="store", type=str) + +args = parser.parse_args() + +if not ( + args.stable_release + or args.nightly_release + or args.development_release + or args.custom_string +): + parser.print_usage(sys.stderr) + sys.stderr.write("error: A release type or custom string is required\n") + sys.exit(1) + +VERSION_FILE = args.path / "version.json" +VERSION_FILE_LOCAL = args.path / "version_local.json" + + +def load_version_info(): + with open(VERSION_FILE, "rt") as f: + return json.load(f) + + +def write_version_info(): + with open(VERSION_FILE_LOCAL, "w") as f: + json.dump(version_local, f, indent=2) + f.write("\n") + + +version_info = load_version_info() + +PACKAGE_VERSION = version_info.get("package-version") +CURRENT_VERSION = Version(PACKAGE_VERSION).base_version + +if args.nightly_release: + CURRENT_VERSION += "rc" + datetime.today().strftime("%Y%m%d") + +if args.development_release: + CURRENT_VERSION += ( + ".dev+" + + subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip() + ) + +if args.custom_string: + CURRENT_VERSION += args.custom_string + +if args.write_json: + version_local = {"package-version": CURRENT_VERSION} + write_version_info() + +print(CURRENT_VERSION) diff --git a/compiler/setup.py b/compiler/setup.py index 5b4c456d2b00..5b2d33d93fdb 100644 --- a/compiler/setup.py +++ b/compiler/setup.py @@ -106,11 +106,12 @@ def check_pip_version(): ) # Setup and get version information. -VERSION_INFO_FILE = os.path.join(IREE_SOURCE_DIR, "version_info.json") +VERSION_FILE = os.path.join(IREE_SOURCE_DIR, "compiler/version.json") +VERSION_FILE_LOCAL = os.path.join(IREE_SOURCE_DIR, "compiler/version_local.json") -def load_version_info(): - with open(VERSION_INFO_FILE, "rt") as f: +def load_version_info(version_file): + with open(version_file, "rt") as f: return json.load(f) @@ -146,17 +147,19 @@ def find_git_submodule_revision(submodule_path): return "" +is_dev_build = False try: - version_info = load_version_info() + version_info = load_version_info(VERSION_FILE_LOCAL) except FileNotFoundError: - print("version_info.json not found. Using defaults", file=sys.stderr) - version_info = {} + print("version_local.json not found. Using version.json defaults") + version_info = load_version_info(VERSION_FILE) + is_dev_build = True git_versions = find_git_versions() PACKAGE_SUFFIX = version_info.get("package-suffix") or "" PACKAGE_VERSION = version_info.get("package-version") -if not PACKAGE_VERSION: - PACKAGE_VERSION = f"0.dev0+{git_versions.get('IREE') or '0'}" +if is_dev_build: + PACKAGE_VERSION += f"+{git_versions.get('IREE') or '0'}" def get_cmake_version_info_args(): diff --git a/compiler/version.json b/compiler/version.json new file mode 100644 index 000000000000..ca3c0ed0b904 --- /dev/null +++ b/compiler/version.json @@ -0,0 +1,3 @@ +{ + "package-version": "2.9.0.dev" +} diff --git a/runtime/setup.py b/runtime/setup.py index 72707daea3bf..09a5be2d868c 100644 --- a/runtime/setup.py +++ b/runtime/setup.py @@ -128,11 +128,12 @@ def check_pip_version(): ) # Setup and get version information. -VERSION_INFO_FILE = os.path.join(IREE_SOURCE_DIR, "version_info.json") +VERSION_FILE = os.path.join(IREE_SOURCE_DIR, "runtime/version.json") +VERSION_FILE_LOCAL = os.path.join(IREE_SOURCE_DIR, "runtime/version_local.json") -def load_version_info(): - with open(VERSION_INFO_FILE, "rt") as f: +def load_version_info(version_file): + with open(version_file, "rt") as f: return json.load(f) @@ -168,17 +169,19 @@ def find_git_submodule_revision(submodule_path): return "" +is_dev_build = False try: - version_info = load_version_info() + version_info = load_version_info(VERSION_FILE_LOCAL) except FileNotFoundError: - print("version_info.json not found. Using defaults", file=sys.stderr) - version_info = {} + print("version_local.json not found. Using version.json defaults") + version_info = load_version_info(VERSION_FILE) + is_dev_build = True git_versions = find_git_versions() PACKAGE_SUFFIX = version_info.get("package-suffix") or "" PACKAGE_VERSION = version_info.get("package-version") -if not PACKAGE_VERSION: - PACKAGE_VERSION = f"0.dev0+{git_versions.get('IREE') or '0'}" +if is_dev_build: + PACKAGE_VERSION += f"+{git_versions.get('IREE') or '0'}" def maybe_nuke_cmake_cache(cmake_build_dir, cmake_install_dir): diff --git a/runtime/version.json b/runtime/version.json new file mode 100644 index 000000000000..ca3c0ed0b904 --- /dev/null +++ b/runtime/version.json @@ -0,0 +1,3 @@ +{ + "package-version": "2.9.0.dev" +}