Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit 4f0b96a

Browse files
committed
Support setting version in build.toml
This change adds the `version` option to the `general` section in `build.toml`. The version will be written to the build metadata and will be used by `kernels upload` to upload builds to a versioned branch.
1 parent b61370a commit 4f0b96a

7 files changed

Lines changed: 21 additions & 13 deletions

File tree

build2cmake/src/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl Build {
3535

3636
pub struct General {
3737
pub name: String,
38+
pub version: Option<usize>,
3839
pub backends: Vec<Backend>,
3940
pub hub: Option<Hub>,
4041
pub python_depends: Option<Vec<String>>,

build2cmake/src/config/v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl TryFrom<Build> for super::Build {
9898
Ok(Self {
9999
general: super::General {
100100
name: build.general.name,
101+
version: None,
101102
backends,
102103
hub: None,
103104
python_depends: None,

build2cmake/src/config/v2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl General {
163163

164164
super::General {
165165
name: general.name,
166+
version: None,
166167
backends,
167168
cuda,
168169
hub: general.hub.map(Into::into),

build2cmake/src/config/v3.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub struct Build {
2121
pub struct General {
2222
pub name: String,
2323

24+
pub version: Option<usize>,
25+
2426
pub backends: Vec<Backend>,
2527

2628
pub cuda: Option<CudaGeneral>,
@@ -141,6 +143,7 @@ impl From<General> for super::General {
141143
fn from(general: General) -> Self {
142144
Self {
143145
name: general.name,
146+
version: general.version,
144147
backends: general.backends.into_iter().map(Into::into).collect(),
145148
cuda: general.cuda.map(Into::into),
146149
hub: general.hub.map(Into::into),
@@ -293,6 +296,7 @@ impl From<super::General> for General {
293296
fn from(general: super::General) -> Self {
294297
Self {
295298
name: general.name,
299+
version: general.version,
296300
backends: general.backends.into_iter().map(Into::into).collect(),
297301
cuda: general.cuda.map(Into::into),
298302
hub: general.hub.map(Into::into),

build2cmake/src/metadata.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ use serde::{Deserialize, Serialize};
33
#[derive(Debug, Deserialize, Serialize)]
44
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
55
pub struct Metadata {
6-
python_depends: Vec<String>,
7-
}
8-
9-
impl Metadata {
10-
pub fn new(python_depends: impl Into<Vec<String>>) -> Self {
11-
Self {
12-
python_depends: python_depends.into(),
13-
}
14-
}
6+
#[serde(skip_serializing_if = "Option::is_none")]
7+
pub version: Option<usize>,
8+
pub python_depends: Vec<String>,
159
}

build2cmake/src/torch/common.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ pub fn write_metadata(backend: Backend, general: &General, file_set: &mut FileSe
4242
.chain(general.backend_python_depends(backend))
4343
.collect::<Result<Vec<_>>>()?;
4444

45-
let metadata = Metadata::new(python_depends);
45+
let metadata = Metadata {
46+
version: general.version,
47+
python_depends,
48+
};
4649

47-
serde_json::to_writer(writer, &metadata)?;
50+
serde_json::to_writer_pretty(writer, &metadata)?;
4851

4952
Ok(())
5053
}

docs/writing-kernels.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ depends = [ "torch" ]
9393

9494
- `name` (required): the name of the kernel. The Python code for a Torch
9595
extension must be stored in `torch-ext/<name>`.
96+
- `version` (int, **experimental**): the major version of the kernel.
97+
The version is written to the kernel's `metadata.json` and is used
98+
by the `kernels upload` command to upload the kernel to a version
99+
branch named `v<version>`.
96100
- `backends` (required): a list of supported backends. Must be one or
97101
more of `cpu`, `cuda`, `metal`, `rocm`, or `xpu`.
98102
- `python-depends` (**experimental**): a list of additional Python dependencies
@@ -124,9 +128,9 @@ options:
124128
- `include` (optional): include directories relative to the project root.
125129
Default: `[]`.
126130
- `maxver` (optional): only build for this Torch version and earlier. Use cautiously, since this option produces
127-
non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md).
131+
non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md).
128132
- `minver` (optional): only build for this Torch version and later. Use cautiously, since this option produces
129-
non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md).
133+
non-compliant kernels if the version range does not correspond to the [required variants](build-variants.md).
130134

131135
### `kernel.<name>`
132136

0 commit comments

Comments
 (0)