Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build-nightly-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
name: Build on Linux x86-64
needs: [setup]
uses: ./.github/workflows/build-wheel-linux-x86_64.yaml
with:
build_dev_package: true

linux-aarch:
if: ${{ inputs.build-linux-arm }}
Expand All @@ -54,6 +56,8 @@ jobs:
name: Build on macOS arm64
needs: [setup]
uses: ./.github/workflows/build-wheel-macos-arm64.yaml
with:
build_dev_package: true

upload:
name: Prepare & Upload wheels to TestPyPI
Expand All @@ -67,6 +71,7 @@ jobs:
- name: Download wheels
uses: actions/download-artifact@v4
with:
pattern: "*wheel*"
merge-multiple: true
path: dist

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/build-wheel-linux-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ on:
required: false
default: 'main'
type: string
build_dev_package:
description: 'Build and upload the catalyst-dev archives'
required: false
default: false
type: boolean

concurrency:
group: Build Catalyst Wheel on Linux (x86_64)-${{ github.ref }}
Expand Down Expand Up @@ -397,6 +402,24 @@ jobs:

cmake --build $GITHUB_WORKSPACE/quantum-build --target check-dialects catalyst-cli

# Package the Catalyst MLIR development subsystem (headers, static libs, CMake config).
# Only build once per platform (primary Python version) since the archive is Python-agnostic.
- name: Package catalyst-dev (CPack)
if: inputs.build_dev_package && matrix.python_version == needs.constants.outputs.primary_python_version
run: |
cd $GITHUB_WORKSPACE/quantum-build
cpack

- name: Upload catalyst-dev Archive
if: inputs.build_dev_package && matrix.python_version == needs.constants.outputs.primary_python_version
uses: actions/upload-artifact@v4
with:
name: catalyst-dev_Linux_x86_64
path: |
${{ github.workspace }}/quantum-build/catalyst-dev_Linux_x86_64*.tar.gz
retention-days: 14
if-no-files-found: error

- name: Build Plugin wheel
# Run only on Thursday at the given time
if: env.BUILD_STANDALONE_PLUGIN == 'true'
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/build-wheel-macos-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ on:
required: false
default: 'main'
type: string
build_dev_package:
description: 'Build and upload the catalyst-dev archives'
required: false
default: false
type: boolean

env:
MACOSX_DEPLOYMENT_TARGET: 15.0
Expand Down Expand Up @@ -376,6 +381,24 @@ jobs:
# xcode builds significantly slower when multithreaded
cmake --build $GITHUB_WORKSPACE/quantum-build --target check-dialects catalyst-cli -- -j 1

# Package the Catalyst MLIR development subsystem (headers, static libs, CMake config).
# Only build once per platform (primary Python version) since the archive is Python-agnostic.
- name: Package catalyst-dev (CPack)
if: inputs.build_dev_package && matrix.python_version == needs.constants.outputs.primary_python_version
run: |
cd $GITHUB_WORKSPACE/quantum-build
cpack

- name: Upload catalyst-dev Archive
if: inputs.build_dev_package && matrix.python_version == needs.constants.outputs.primary_python_version
uses: actions/upload-artifact@v4
with:
name: catalyst-dev_macos_arm64
path: |
${{ github.workspace }}/quantum-build/catalyst-dev_Darwin_arm64*.tar.gz
retention-days: 14
if-no-files-found: error

- name: Build Plugin wheel
# Run only on Thursday at the given time
if: env.BUILD_STANDALONE_PLUGIN == 'true'
Expand Down
5 changes: 5 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@
`-stage` naming convention used when invoking them from the command line (e.g. `quantum-compilation-stage`).
[#3002](https://github.com/PennyLaneAI/catalyst/pull/3002)

* New build configurations have been added to allow building "development" packages of Catalyst and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't normally document CI/build changes in our release notes. Unless we think this is a feature we'd like to advertise?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it warrants a changelog entry, it's not only a change to the build system, but an addition that plugin developers (internal and external) could be interested in.

@dime10 dime10 Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to advertise it then it shouldn't be under internal changes imo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes no difference to me what section it's in, but Internal Changes seems like the best fit to me. It's not a new feature or improvement that an external user of Catalyst would care about, it's new functionality that a Catalyst developer would care about.

LLVM/MLIR. These dev packages will allow Catalyst plugin developers to build against the pre-built
libraries included therein, rather than having to build Catalyst and its dependencies from source.
[#3023](https://github.com/PennyLaneAI/catalyst/pull/3023)

<h3>Documentation 📝</h3>

* A broken link was removed in the [Compiler Core](https://docs.pennylane.ai/projects/catalyst/en/stable/modules/mlir.html) documentation page. The link referred to where precompiled decomposition rules were implemented, which has since been refactored.
Expand Down
91 changes: 90 additions & 1 deletion mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ foreach(STABLEHLO_LIB IN LISTS STABLEHLO_LIBS)
)
endforeach()

add_library(ExternalStablehloLib INTERFACE)
add_library(ExternalStablehloLib INTERFACE IMPORTED GLOBAL)

foreach(STABLEHLO_LIB IN LISTS STABLEHLO_LIBS)
target_link_libraries(ExternalStablehloLib INTERFACE ${STABLEHLO_LIB})
Expand Down Expand Up @@ -280,3 +280,92 @@ endif()
if(NOT CATALYST_DOCS_ONLY)
add_subdirectory(test)
endif()


###################################################################
Comment thread
joeycarter marked this conversation as resolved.
## Generate a Catalyst Development Package for External Projects ##
###################################################################

include(GNUInstallDirs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work fine on MacOS?
We don't need to worry about the other one just yet either, but we will soon.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, yes. GNUInstallDirs mainly provides the variables CMAKE_INSTALL_LIBDIR, which maps to lib/, CMAKE_INSTALL_BINDIR, which maps to bin/, etc. (all relative to the install prefix), so it should work on all UNIX-like systems.


# Re-fetch the exported targets and strip the same third-party ones the
# build-tree export already excludes (see cmake/modules/CMakeLists.txt).
get_property(CATALYST_INSTALL_TARGETS GLOBAL PROPERTY MLIR_EXPORTS)
set(TARGETS_TO_REMOVE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want any of these?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered this too, but opted to keep them excluded since I ran into issues with external dependencies that didn't seem worth pursuing right now. We don't need any of these libs for the internal plugin we're currently working on. Eventually we may want to include quantum-transforms, for instance, since this is a fairly core piece of the compiler, but generally the most important components for a plugin are the dialects rather than the transforms (since any plugin that depends on a Catalyst transform pass could just run it from Catalyst rather than from the plugin).

nlohmann_json
tomlplusplus_tomlplusplus
ion-transforms
CatalystCompilerDriver
PBCUtils
QuantumCAPI
pbc-transforms
quantum-transforms # depends on decompsolver, which depends on boost; exclude
decompsolver # depends on boost; exclude
)
list(REMOVE_ITEM CATALYST_INSTALL_TARGETS ${TARGETS_TO_REMOVE})

# Static archives, shared libs, and any runtime artifacts from the dialects,
# transforms and utils. INCLUDES DESTINATION records the include path in the
# exported targets so consumers get it transitively.
# We use `COMPONENT catalyst-dev` since `add_mlir_public_c_api_library(QuantumCAPI ...)
# auto-generates its own install rule that we want to bypass.
install(TARGETS ${CATALYST_INSTALL_TARGETS}
EXPORT CatalystTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT catalyst-dev
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT catalyst-dev
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT catalyst-dev
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Install license to share/doc/Catalyst/LICENSE
install(FILES "${PROJECT_SOURCE_DIR}/../LICENSE"
DESTINATION "${CMAKE_INSTALL_DOCDIR}"
COMPONENT catalyst-dev)

# Tools (binaries). These are usually not in MLIR_EXPORTS, so install by name.
# NOTE: We use the catalyst-bin component for tools to exclude from catalyst-dev.
if(NOT CATALYST_DOCS_ONLY)
# Need to wrap in `if(NOT CATALYST_DOCS_ONLY)` since `add_subdirectory(tools)`
# is also conditional on this predicate
install(TARGETS catalyst-cli quantum-opt quantum-lsp-server
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT catalyst-bin)
endif()

# Hand-written headers (*.h and the *.td that TableGen consumers may want).
install(DIRECTORY ${CATALYST_MAIN_INCLUDE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT catalyst-dev
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.td"
PATTERN "*.capi.h.inc")

# TableGen-generated headers (*.h.inc, *.cpp.inc) AND the generated
# frontend_catalyst_version_py.h all live under the build-tree include dir.
install(DIRECTORY ${CATALYST_GEN_INCLUDE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT catalyst-dev
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.h.inc"
PATTERN "*.cpp.inc"
PATTERN "CMakeFiles" EXCLUDE)

# Bundle the StableHLO static archives that Catalyst links against.
install(DIRECTORY "${STABLEHLO_BUILD_DIR}/lib/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT catalyst-dev
FILES_MATCHING PATTERN "lib*.a")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding the license file here too via CPACK_RESOURCE_FILE_LICENSE if we want to distribute this. Same with CPACK_PACKAGE_VENDOR with the name from the headers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the license file to the install targets above:

# Install license to share/doc/Catalyst/LICENSE
install(FILES "${PROJECT_SOURCE_DIR}/../LICENSE"
    DESTINATION "${CMAKE_INSTALL_DOCDIR}"
    COMPONENT catalyst-dev)

Looks like CPACK_RESOURCE_FILE_LICENSE is only relevant for some package generators:

This license file is NOT added to the installed files but is used by some CPack generators like NSIS. ... If you want to install a license file (may be the same as this one) along with your project, you must add an appropriate CMake install() command in your CMakeLists.txt.

Anyway, probably no harm in adding it, along with CPACK_PACKAGE_VENDOR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks like these variable have no effect for bare archive generators like tar or zip (but I assume they have effect for more formal system generators like DEB or RPM). Anyway, added here: 5665e29

set(CPACK_PACKAGE_NAME "catalyst-dev")
set(CPACK_PACKAGE_VERSION "${CATALYST_PACKAGE_VERSION}")
set(CPACK_PACKAGE_VENDOR "Xanadu Quantum Technologies Inc.")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/../LICENSE")
set(CPACK_GENERATOR "TGZ")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is set to ZIP_ZSTD, could we just relabel the output as whl and call it a day?
It'll be larger, but it may be installable from our own PyPI mirror if it works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can set the generator to ZIP, but we can't pip install from a bare ZIP file, no? The wheels would require the appropriate metadata files.

One option might be to create a new pyproject.toml file for the catalyst-dev package with a scikit-build backend. Do you think it's worth exploring or it's okay to stick with a simple archive for now?

set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR}_${CATALYST_PACKAGE_VERSION}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good on aarch64 too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume so, my understanding is that the CMAKE_SYSTEM_PROCESSOR variable takes the output of

uname -m

set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY ON) # extracts into catalyst-dev-<ver>/
set(CPACK_COMPONENTS_ALL catalyst-dev) # only catalyst-dev component
set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE) # single archive, no per-component split

message(STATUS "Preparing CPack package ${CPACK_PACKAGE_FILE_NAME}")
include(CPack)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables are set before the inclusion? Just wondering if there's reason to this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a funny system, but the include(CPack) has to be at the end, after setting all the cpack-related variables. From https://cmake.org/cmake/help/latest/module/CPack.html#variables-common-to-all-cpack-generators:

Before including this CPack module in your CMakeLists.txt file [my emphasis], there are a variety of variables that can be set to customize the resulting installers. The most commonly-used variables are:

CPACK_PACKAGE_NAME

The name of the package (or application). If not specified, it defaults to the project name.

...

34 changes: 34 additions & 0 deletions mlir/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ LLVM_BUILD_DIR ?= $(MK_DIR)/llvm-project/build
STABLEHLO_BUILD_DIR ?= $(MK_DIR)/stablehlo/build
ENZYME_BUILD_DIR ?= $(MK_DIR)/Enzyme/build
RT_BUILD_DIR ?= $(MK_DIR)/../runtime/build
DIST_DIR ?= $(MK_DIR)/dist
ENABLE_ASAN ?= OFF
STRICT_WARNINGS ?= ON
BUILD_TYPE ?= Release
LLVM_EXTERNAL_LIT ?= $(LLVM_BUILD_DIR)/bin/llvm-lit
LLVM_TARGETS_TO_BUILD ?= host
LLVM_INSTALL_STAGING_DIR ?= $(LLVM_BUILD_DIR)/install
LLVM_DISTRIBUTION_COMPONENTS ?= $\
"cmake-exports;llvm-headers;llvm-libraries;$\
mlir-cmake-exports;mlir-headers;mlir-libraries;$\
FileCheck;llvm-tblgen;llvm-config;mlir-tblgen;not;count"

ifeq ($(shell uname), Darwin)
DEFAULT_ENABLE_LLD := OFF
Expand Down Expand Up @@ -49,6 +55,8 @@ help:
@echo " enzyme to build Enzyme"
@echo " dialects to build custom Catalyst MLIR dialects"
@echo " dialect-docs to build custom Catalyst MLIR dialect documentation"
@echo " pack-catalyst-dev to build the catalyst-dev package"
@echo " pack-mlir-dev to build the catalyst-mlir-dev package"
@echo " test to run the Catalyst MLIR dialects test suite"
@echo " clean to delete all temporary, cache, and build files"
@echo " format [check=1] to apply C++ formatter; use with 'check=1' to check instead of modify (requires clang-format)"
Expand Down Expand Up @@ -80,6 +88,9 @@ llvm:
-DLLVM_ENABLE_PROJECTS="$(LLVM_PROJECTS)" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_DISTRIBUTION_COMPONENTS=$(LLVM_DISTRIBUTION_COMPONENTS) \
-DCMAKE_INSTALL_PREFIX=$(LLVM_INSTALL_STAGING_DIR) \
-DPython_EXECUTABLE=$(PYTHON) \
-DPython3_EXECUTABLE=$(PYTHON) \
-DPython3_NumPy_INCLUDE_DIRS=$$($(PYTHON) -c "import numpy as np; print(np.get_include())") \
Expand Down Expand Up @@ -220,6 +231,29 @@ dialect-docs:

cmake --build $(DIALECTS_DOCS_BUILD_DIR) --target mlir-doc

.PHONY: pack-catalyst-dev
pack-catalyst-dev: dialects

@echo "build the catalyst-dev package"
cd $(DIALECTS_BUILD_DIR) && cpack
mkdir -p $(DIST_DIR)
mv $(DIALECTS_BUILD_DIR)/catalyst-dev*.tar.gz $(DIST_DIR)

# Get the LLVM version as, e.g. 22.0.0git-8f264586
LLVM_VERSION := $(shell $(LLVM_INSTALL_STAGING_DIR)/bin/llvm-config --version)
LLVM_COMMIT := $(shell grep llvm ../.dep-versions | awk -F '=' '{ print $$2 }' | cut -c1-8)
LLVM_VERSION_FULL := $(LLVM_VERSION)-$(LLVM_COMMIT)

.PHONY: pack-mlir-dev
pack-mlir-dev: llvm

@echo "build the catalyst-mlir-dev package"
cmake --build $(LLVM_BUILD_DIR) --target install-distribution
tar -czf catalyst-mlir-dev_$(shell uname -s)_$(shell uname -m)_$(LLVM_VERSION_FULL).tar.gz \
-C $(LLVM_INSTALL_STAGING_DIR) bin lib include
mkdir -p $(DIST_DIR)
mv catalyst-mlir-dev*.tar.gz $(DIST_DIR)

.PHONY: test
test:
@echo "test the Catalyst MLIR dialects test suite"
Expand Down
37 changes: 36 additions & 1 deletion mlir/cmake/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)
set(TARGETS_TO_REMOVE nlohmann_json tomlplusplus_tomlplusplus ion-transforms CatalystCompilerDriver PBCUtils QuantumCAPI pbc-transforms)
list(REMOVE_ITEM MLIR_EXPORTS ${TARGETS_TO_REMOVE})
export(TARGETS ${MLIR_EXPORTS} ExternalStablehloLib FILE ${catalyst_cmake_builddir}/CatalystTargets.cmake)
export(TARGETS ${MLIR_EXPORTS} FILE ${catalyst_cmake_builddir}/CatalystTargets.cmake)

# Generate MlirConfig.cmake for the build tree.
set(CATALYST_CONFIG_CMAKE_DIR "${catalyst_cmake_builddir}")
Expand All @@ -48,3 +48,38 @@ configure_file(
set(CATALYST_CONFIG_CMAKE_DIR)
set(CATALYST_CONFIG_LLVM_CMAKE_DIR)
set(CATALYST_CONFIG_INCLUDE_DIRS)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# --- version string, reused from frontend/catalyst/_version.py ---
file(READ "${PROJECT_SOURCE_DIR}/../frontend/catalyst/_version.py" _ver_py)
string(REGEX MATCH "__version__ = \"([^\"]+)\"" _m "${_ver_py}")
set(CATALYST_PACKAGE_VERSION "${CMAKE_MATCH_1}" CACHE INTERNAL "Catalyst version")

string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" CATALYST_NUMERIC_VERSION "${CATALYST_PACKAGE_VERSION}")
Comment on lines +56 to +60

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a scrape and regex, is it possible to call Python directly to output the version string from this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably a good idea, let me try. For reference, this was some quick-and-dirty plagiarism from here:

function(make_version_header_file input_file output_file)
set(version_number "unknown")
if (NOT EXISTS ${input_file})
message(WARNING "Could not find ${input_file}")
else()
file(READ ${input_file} input_content)
if (NOT input_content MATCHES "__version__ = \"([^\"]+)\"")
message(WARNING "Could not find Catalyst version in ${input_file}")
else()
set(version_number "${CMAKE_MATCH_1}")
endif()
endif()


write_basic_package_version_file(
"${catalyst_cmake_builddir}/CatalystConfigVersion.cmake"
VERSION ${CATALYST_NUMERIC_VERSION}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've chatted about versioning the libs in the past, so I presume this handles it?

If so, is this following https://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info / https://www.gnu.org/software/libtool/manual/libtool.html#Managing-release-information ?

If not, fine for now, but we should discuss how to tag these to be versioned right for LNX/MACOS (and the other one)

@joeycarter joeycarter Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure, but I don't think so. What this command does is make a CatalystConfigVersion.cmake file containing the following (for example):

# This is a basic version file for the Config-mode of find_package().
# It is used by write_basic_package_version_file() as input file for configure_file()
# to create a version-file which can be installed along a config.cmake file.
#
# The created file sets PACKAGE_VERSION_EXACT if the current version string and
# the requested version string are exactly the same and it sets
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version,
# but only if the requested major version is the same as the current one.
# The variable CVF_VERSION must be set before calling configure_file().


set(PACKAGE_VERSION "0.16.0")

if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
  set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

  if("0.16.0" MATCHES "^([0-9]+)\\.")
    set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
    if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0)
      string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}")
    endif()
  else()
    set(CVF_VERSION_MAJOR "0.16.0")
  endif()

  if(PACKAGE_FIND_VERSION_RANGE)
    # both endpoints of the range must have the expected major version
    math (EXPR CVF_VERSION_MAJOR_NEXT "${CVF_VERSION_MAJOR} + 1")
    if (NOT PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
        OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX_MAJOR STREQUAL CVF_VERSION_MAJOR)
          OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX VERSION_LESS_EQUAL CVF_VERSION_MAJOR_NEXT)))
      set(PACKAGE_VERSION_COMPATIBLE FALSE)
    elseif(PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
        AND ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS_EQUAL PACKAGE_FIND_VERSION_MAX)
        OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MAX)))
      set(PACKAGE_VERSION_COMPATIBLE TRUE)
    else()
      set(PACKAGE_VERSION_COMPATIBLE FALSE)
    endif()
  else()
    if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR)
      set(PACKAGE_VERSION_COMPATIBLE TRUE)
    else()
      set(PACKAGE_VERSION_COMPATIBLE FALSE)
    endif()

    if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
      set(PACKAGE_VERSION_EXACT TRUE)
    endif()
  endif()
endif()


# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")
  return()
endif()

# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")
  math(EXPR installedBits "8 * 8")
  set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
  set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()

I believe its main purpose is to handle find_package(Catalyst ...) commands, not library versioning.

By the way, the files under lib/ are all static libraries, like

libcatalyst-transforms.a
libMLIRCatalyst.a
libMLIRQRef.a
libMLIRQuantum.a
...

so they wouldn't follow the shared-library versioning convention (I think?).

COMPATIBILITY SameMajorVersion)

# --- install-tree config, generated from a *separate* template ---
set(CATALYST_INSTALL_TARGETS_LIST "${MLIR_EXPORTS}") # same list, minus removals
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/CatalystConfig.install.cmake.in
"${catalyst_cmake_builddir}/install/CatalystConfig.cmake"
INSTALL_DESTINATION ${CATALYST_INSTALL_PACKAGE_DIR}
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR)

# --- install the export set + configs ---
install(EXPORT CatalystTargets
FILE CatalystTargets.cmake
DESTINATION ${CATALYST_INSTALL_PACKAGE_DIR}
COMPONENT catalyst-dev)

install(FILES
"${catalyst_cmake_builddir}/install/CatalystConfig.cmake"
"${catalyst_cmake_builddir}/CatalystConfigVersion.cmake"
DESTINATION ${CATALYST_INSTALL_PACKAGE_DIR}
COMPONENT catalyst-dev)
20 changes: 20 additions & 0 deletions mlir/cmake/modules/CatalystConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,23 @@ set(CATALYST_INCLUDE_DIRS "@CATALYST_CONFIG_INCLUDE_DIRS@")

# Provide all our library targets to users.
@CATALYST_CONFIG_INCLUDE_EXPORTS@

# --- rebuild ExternalStablehloLib for build-tree consumers ---
set(_shlo_libs ChloCAPI ChloOps StablehloAssemblyFormat StablehloBase

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this set if it is only used in the NOT pathway below? Would it be better within the if-statement?

StablehloBroadcastUtils StablehloBroadcastLowering StablehloCAPI
StablehloLinalgTransforms StablehloOps StablehloOptimizationPasses
StablehloPasses StablehloPassUtils StablehloRegister
StablehloTypeConversion StablehloTypeInference Version
VhloCAPI VhloOps VhloTypes)
if(NOT TARGET ExternalStablehloLib)
add_library(ExternalStablehloLib INTERFACE IMPORTED)
foreach(_l IN LISTS _shlo_libs)
if(NOT TARGET ${_l})
add_library(${_l} STATIC IMPORTED)
set_target_properties(${_l} PROPERTIES
IMPORTED_LOCATION "@STABLEHLO_BUILD_DIR@/lib/lib${_l}.a")
endif()
set_property(TARGET ExternalStablehloLib APPEND
PROPERTY INTERFACE_LINK_LIBRARIES ${_l})
endforeach()
endif()
32 changes: 32 additions & 0 deletions mlir/cmake/modules/CatalystConfig.install.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(MLIR)

set_and_check(CATALYST_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(CATALYST_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")

# Reconstruct the bundled StableHLO interface target.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same q as above.

Though, is this already defined somewhere that we can use, or is this the trial to define the pieces we only care about?

set(_shlo_libs ChloCAPI ChloOps StablehloAssemblyFormat StablehloBase
StablehloBroadcastUtils StablehloBroadcastLowering StablehloCAPI
StablehloLinalgTransforms StablehloOps StablehloOptimizationPasses
StablehloPasses StablehloPassUtils StablehloRegister
StablehloTypeConversion StablehloTypeInference Version
VhloCAPI VhloOps VhloTypes)
if(NOT TARGET ExternalStablehloLib)
add_library(ExternalStablehloLib INTERFACE IMPORTED)
foreach(_l IN LISTS _shlo_libs)
if(NOT TARGET ${_l})
add_library(${_l} STATIC IMPORTED)
set_target_properties(${_l} PROPERTIES
IMPORTED_LOCATION "${CATALYST_LIBRARY_DIR}/lib${_l}.a")
endif()
set_property(TARGET ExternalStablehloLib APPEND
PROPERTY INTERFACE_LINK_LIBRARIES ${_l})
endforeach()
endif()

include("${CMAKE_CURRENT_LIST_DIR}/CatalystTargets.cmake")

set(CATALYST_EXPORTED_TARGETS "@CATALYST_INSTALL_TARGETS_LIST@")
check_required_components(Catalyst)
8 changes: 5 additions & 3 deletions mlir/lib/Catalyst/Analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ set(LIBS
add_mlir_library(${LIBRARY_NAME} STATIC ${SRC} LINK_LIBS PRIVATE ${LIBS})
target_compile_features(${LIBRARY_NAME} PUBLIC cxx_std_20)
target_include_directories(${LIBRARY_NAME} PUBLIC
.
${PROJECT_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/include)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Comment thread
dime10 marked this conversation as resolved.
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
Loading
Loading