From ef6183d8e335164183036bb161320897e07f4e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Wed, 14 Jan 2026 08:53:50 +0000 Subject: [PATCH] Add `general.license` field to `build.toml` This can be used for card-filling and is added to the kernel build metadata. --- build2cmake/src/config/mod.rs | 4 ++++ build2cmake/src/config/v1.rs | 1 + build2cmake/src/config/v2.rs | 1 + build2cmake/src/config/v3.rs | 4 ++++ build2cmake/src/metadata.rs | 12 +++--------- build2cmake/src/torch/common.rs | 5 ++++- examples/silu-and-mul/build.toml | 1 + 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/build2cmake/src/config/mod.rs b/build2cmake/src/config/mod.rs index 816b4fea..a11f4e97 100644 --- a/build2cmake/src/config/mod.rs +++ b/build2cmake/src/config/mod.rs @@ -35,6 +35,10 @@ impl Build { pub struct General { pub name: String, + + /// Hugging Face Hub license identifier. + pub license: Option, + pub backends: Vec, pub hub: Option, pub python_depends: Option>, diff --git a/build2cmake/src/config/v1.rs b/build2cmake/src/config/v1.rs index 608f35d5..5bba9086 100644 --- a/build2cmake/src/config/v1.rs +++ b/build2cmake/src/config/v1.rs @@ -98,6 +98,7 @@ impl TryFrom for super::Build { Ok(Self { general: super::General { name: build.general.name, + license: None, backends, hub: None, python_depends: None, diff --git a/build2cmake/src/config/v2.rs b/build2cmake/src/config/v2.rs index 43e22117..86d4dc37 100644 --- a/build2cmake/src/config/v2.rs +++ b/build2cmake/src/config/v2.rs @@ -163,6 +163,7 @@ impl General { super::General { name: general.name, + license: None, backends, cuda, hub: general.hub.map(Into::into), diff --git a/build2cmake/src/config/v3.rs b/build2cmake/src/config/v3.rs index 770ec05a..bf3409ee 100644 --- a/build2cmake/src/config/v3.rs +++ b/build2cmake/src/config/v3.rs @@ -21,6 +21,8 @@ pub struct Build { pub struct General { pub name: String, + pub license: Option, + pub backends: Vec, pub cuda: Option, @@ -141,6 +143,7 @@ impl From for super::General { fn from(general: General) -> Self { Self { name: general.name, + license: general.license, backends: general.backends.into_iter().map(Into::into).collect(), cuda: general.cuda.map(Into::into), hub: general.hub.map(Into::into), @@ -293,6 +296,7 @@ impl From for General { fn from(general: super::General) -> Self { Self { name: general.name, + license: general.license, backends: general.backends.into_iter().map(Into::into).collect(), cuda: general.cuda.map(Into::into), hub: general.hub.map(Into::into), diff --git a/build2cmake/src/metadata.rs b/build2cmake/src/metadata.rs index a8a48601..d9f4abbc 100644 --- a/build2cmake/src/metadata.rs +++ b/build2cmake/src/metadata.rs @@ -3,13 +3,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] pub struct Metadata { - python_depends: Vec, -} - -impl Metadata { - pub fn new(python_depends: impl Into>) -> Self { - Self { - python_depends: python_depends.into(), - } - } + #[serde(skip_serializing_if = "Option::is_none")] + pub license: Option, + pub python_depends: Vec, } diff --git a/build2cmake/src/torch/common.rs b/build2cmake/src/torch/common.rs index f98a97ba..e2ba4dcd 100644 --- a/build2cmake/src/torch/common.rs +++ b/build2cmake/src/torch/common.rs @@ -42,7 +42,10 @@ pub fn write_metadata(backend: Backend, general: &General, file_set: &mut FileSe .chain(general.backend_python_depends(backend)) .collect::>>()?; - let metadata = Metadata::new(python_depends); + let metadata = Metadata { + license: general.license.clone(), + python_depends, + }; serde_json::to_writer(writer, &metadata)?; diff --git a/examples/silu-and-mul/build.toml b/examples/silu-and-mul/build.toml index c42fbecc..7f022ef5 100644 --- a/examples/silu-and-mul/build.toml +++ b/examples/silu-and-mul/build.toml @@ -1,5 +1,6 @@ [general] name = "silu-and-mul" +license = "apache-2.0" backends = [ "cpu", "cuda",