OpenCL-Headers icon indicating copy to clipboard operation
OpenCL-Headers copied to clipboard

[Important] Adds advanced flake.nix for `$ nix build github:KhronosGroup/OpenCL-Headers` and more

Open izelnakri opened this issue 5 months ago • 1 comments

Hi there,

Currently I'm working on standardizing, further specifying and simplifying the build, test and release of all the GPU based software for nix: which should eventually allow all standard bodies and hardware/software vendors to further standardize their build workflows.

We already have opencl-headers on nixpkgs here: https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/op/opencl-headers/package.nix

This flake.nix serves as an additional release channel for a direct specific github branch on any machine that has nix via:

$ nix build github:KhronosGroup/OpenCL-Headers # or:
$ nix build github:KhronosGroup/OpenCL-Headers/b79b358ff6b9998d3fc65a5f55083db3d651d55d # or:
$ nix build github:KhronosGroup/OpenCL-Headers/cl_khr_unified_svm

Also serves as a further documentation as code for all the important build targets.

It also standardizes the builds under a single command:

$ nix build ".#" # Runs the unit tests as well, nix testing convention, there is doCheck = true
$ tree ./result
result
├── include
│   └── CL
│       ├── cl_d3d10.h
│       ├── cl_d3d11.h
│       ├── cl_dx9_media_sharing.h
│       ├── cl_dx9_media_sharing_intel.h
│       ├── cl_egl.h
│       ├── cl_ext.h
│       ├── cl_ext_intel.h
│       ├── cl_function_types.h
│       ├── cl_gl_ext.h
│       ├── cl_gl.h
│       ├── cl.h
│       ├── cl_half.h
│       ├── cl_icd.h
│       ├── cl_layer.h
│       ├── cl_platform.h
│       ├── cl_va_api_media_sharing_intel.h
│       ├── cl_version.h
│       └── opencl.h
└── share
    ├── cmake
    │   └── OpenCLHeaders
    │       ├── OpenCLHeadersConfig.cmake
    │       ├── OpenCLHeadersConfigVersion.cmake
    │       └── OpenCLHeadersTargets.cmake
    └── pkgconfig
        └── OpenCL-Headers.pc

7 directories, 22 files

A contributor can have standardized development environment via:

$ nix develop # Could also automatically if the developer has `direnv` installed & configured
# With the current flake.nix, then developer can see the output:
$ pkg-config --list-all --cflags
OpenCL-Headers OpenCL-Headers - Khronos OpenCL Headers

Lastly, in the future, if there is enough interest, this could enhance the existing CI workflow(with additional PRs) via:

$ nix flake check --all-systems # Runs all the checks(unit tests, pkg-config checks etc) on all CPU architectures

On a corollary note, I suggest all software developers to install and use nix for all its benefits. I think there is enough documentation online, however I currently find the documentation lacking for conventions around testing. So I documented it here for the ones interested: https://gist.github.com/izelnakri/06d7286fe9ab5f15acee9cbeace1c1b1

izelnakri avatar Aug 19 '25 14:08 izelnakri

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 19 '25 14:08 CLAassistant