Skip to content

Add conan files#1184

Draft
codingwithmagga wants to merge 5 commits into
NVIDIA:mainfrom
codingwithmagga:codingwithmagga/fix-359-package-manager-support
Draft

Add conan files#1184
codingwithmagga wants to merge 5 commits into
NVIDIA:mainfrom
codingwithmagga:codingwithmagga/fix-359-package-manager-support

Conversation

@codingwithmagga
Copy link
Copy Markdown

Conan

Add conan files to create a matx conan package.

Workflow

In the main folder run

conan create .

This creates the matx conan package on your system.

Test

After creating the conan package create a new folder with a conanfile.py.

import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout

class TestPackageConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeDeps", "VirtualRunEnv"
    test_type = "explicit"

    def requirements(self):
        self.requires('matx/1.0.0')

    def layout(self):
        cmake_layout(self)

    def generate(self):
        tc = CMakeToolchain(self)
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()        

    def test(self):
        if can_run(self):
            bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
            self.run(bin_path, env="conanrun")

I added a CMakeLists.txt and a folder src where I copied the examples from this repo to.

cmake_minimum_required(VERSION 3.25.2)

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
    set(CMAKE_CUDA_ARCHITECTURES "native")
    message(STATUS "Using native GPU architecture since CMAKE_CUDA_ARCHITECTURES not defined")
endif()

project(test_package LANGUAGES CXX CUDA)

find_package(matx CONFIG REQUIRED)

add_subdirectory(src)

Now you can run conan build . to create the examples using conan and the matx conan package.

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 20, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cliffburdick cliffburdick marked this pull request as ready for review May 29, 2026 15:53
@cliffburdick cliffburdick marked this pull request as draft May 29, 2026 15:53
@cliffburdick
Copy link
Copy Markdown
Collaborator

Thanks for doing this! One comment I have is that the version number is hard-coded in many places making it a maintenance burden to update all the right places. Would it be possible to grab the source version from CMakeLists.txt, which is our current source of truth? Also, what would be required to make this present in the public conan repo?

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 29, 2026

Greptile Summary

This PR adds Conan 2 packaging support for MatX, introducing a root-level conanfile.py recipe, a test_package/ directory with a consumer test recipe and a CUDA smoke test, and corresponding documentation updates in README.md and docs_input/build.rst.

  • conanfile.py: Declares package_type = \"header-library\", exports sources, configures and installs via CMake, and exposes the installed cmake config directory through cpp_info.builddirs. Missing no_copy_source = True, which causes Conan to unnecessarily copy the large source tree (including cmake/rapids-cmake/) to the build folder. Additionally, cmake.configure() internally triggers CPM/FetchContent to download CCCL from GitHub, so conan create . silently requires internet access without declaring CCCL as a Conan dependency.
  • test_package/: Correctly uses self.tested_reference_str for the requirement, uses CMakeDeps + CMakeToolchain for dependency resolution, and builds a minimal CUDA executable to verify the package works end-to-end.

Confidence Score: 4/5

Safe to merge as a first-cut Conan packaging addition; no changes to library code or existing build infrastructure.

The core recipe logic is sound and follows Conan 2 conventions. The main gap is that conan create . silently downloads CCCL via CPM without declaring it as a Conan dependency, which breaks in offline environments. Missing no_copy_source = True causes unnecessary large file copies on every packaging run. Neither issue prevents the package from working in a standard online developer environment, but both are worth fixing before this recipe is widely distributed.

conanfile.py — the recipe's missing no_copy_source and undeclared CPM-based CCCL download are the items that warrant a follow-up look.

Important Files Changed

Filename Overview
conanfile.py New Conan 2 recipe for the matx header-only library; correctly uses package_type = "header-library" and installs via cmake, but is missing no_copy_source = True and implicitly depends on internet access during packaging (CCCL fetched via CPM)
test_package/conanfile.py Standard Conan 2 test package recipe; correctly uses self.tested_reference_str instead of hardcoding the version, missing trailing newline
test_package/test_package.cu Minimal CUDA smoke test that creates a tensor and prints it; has an unused using namespace matx declaration alongside explicit matx:: qualifiers, and is missing a trailing newline
test_package/CMakeLists.txt Clean CMake configuration for the test package; correctly uses find_package(matx CONFIG REQUIRED) and links against matx::matx
README.md Adds documentation for the new Conan workflow under a numbered section; content is accurate and consistent with the recipe
docs_input/build.rst RST documentation for Conan support added cleanly with correct code-block directives and accurate workflow description
.gitignore Adds CMakeUserPresets.json to gitignore (generated by some CMake/IDE workflows)

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant Conan as Conan CLI
    participant CMake as CMake
    participant CPM as CPM/FetchContent
    participant GitHub as GitHub (CCCL)
    participant Cache as Local Conan Cache

    Dev->>Conan: conan create .
    Conan->>CMake: cmake.configure()
    CMake->>CPM: rapids_cpm_cccl()
    CPM->>GitHub: Download CCCL (requires internet)
    GitHub-->>CPM: CCCL source
    CMake-->>Conan: Configure done
    Conan->>CMake: cmake.install()
    CMake-->>Conan: Headers + cmake config files
    Conan->>Cache: Store matx/1.0.0 package

    Dev->>Conan: conan build . (test_package)
    Conan->>CMake: Generate CMakeDeps + CMakeToolchain
    CMake->>Cache: find_package(matx CONFIG REQUIRED)
    Cache-->>CMake: matx::matx target
    CMake-->>Dev: test_package binary built
Loading

Reviews (1): Last reviewed commit: "Merge branch 'codingwithmagga/fix-359-pa..." | Re-trigger Greptile

Comment thread conanfile.py
Comment on lines +11 to +12
package_type = "header-library"
description = (
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.

P2 For a header-library package, setting no_copy_source = True is recommended. Without it, Conan copies all exports_sources (including the large cmake/rapids-cmake/ tree) into the build folder before calling cmake.configure(). This is unnecessary for a header-only library and can significantly slow down the packaging step.

Suggested change
package_type = "header-library"
description = (
package_type = "header-library"
no_copy_source = True
description = (

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment thread conanfile.py
Comment on lines +22 to +24
def package(self):
cmake = CMake(self)
cmake.configure()
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.

P2 CCCL fetched via CPM during package() step

The main CMakeLists.txt calls rapids_cpm_cccl() during configure, which triggers CPM/FetchContent to download CCCL from GitHub. Because CCCL is not declared as a Conan dependency in this recipe, conan create . silently requires internet access — it will fail in offline or air-gapped environments. Ideally CCCL would be expressed as a requires() or tool_requires() in the recipe, but at a minimum this dependency on network access during packaging should be documented.

Comment on lines +7 to +15
using namespace matx;

int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{
auto a = matx::make_tensor<float>({10});
a.SetVals({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});

matx::print(a);
} No newline at end of file
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.

P2 The using namespace matx; declaration is never actually relied upon — every call below still uses explicit matx:: qualification. Either remove the using declaration or drop the redundant qualifiers.

Suggested change
using namespace matx;
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{
auto a = matx::make_tensor<float>({10});
a.SetVals({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
matx::print(a);
}
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
{
auto a = matx::make_tensor<float>({10});
a.SetVals({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
matx::print(a);
return 0;
}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment thread test_package/conanfile.py
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun") No newline at end of file
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.

P2 File is missing a trailing newline, which can cause issues with some POSIX tools and linters.

Suggested change
self.run(bin_path, env="conanrun")
self.run(bin_path, env="conanrun")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants