Skip to main content

gen_gomod/
build_spec.rs

1//! Typed build spec for gomod — mirrors nixpkgs `buildGoModule`
2//! kwargs so substrate's Go-side lockfile-builder spreads the args
3//! verbatim into the builder.
4//!
5//! nixpkgs reference:
6//! `pkgs/build-support/go/module.nix` (`buildGoModule`).
7
8use indexmap::IndexMap;
9use serde::{Deserialize, Serialize};
10
11pub const SCHEMA_VERSION: u32 = 1;
12
13#[derive(Clone, Debug, Serialize, Deserialize, gen_macros::SpecShape)]
14#[spec(
15    args = "PackageArgs",
16    quirk = "crate::quirks::GomodQuirk",
17    args_field = "args",
18    root_field = "root_package",
19    members_field = "workspace_members",
20    crates_field = "packages"
21)]
22pub struct BuildSpec {
23    pub version: u32,
24    pub packages: IndexMap<String, PackageSpec>,
25    pub root_package: String,
26    pub workspace_members: Vec<String>,
27}
28
29#[derive(Clone, Debug, Serialize, Deserialize)]
30pub struct PackageSpec {
31    pub name: String,
32    pub version: String,
33    pub args: PackageArgs,
34    #[serde(default, skip_serializing_if = "Vec::is_empty")]
35    pub quirks: Vec<crate::quirks::GomodQuirk>,
36}
37
38/// Pre-shaped `buildGoModule` kwargs. Field names match nixpkgs'
39/// builder signature (camelCase via serde rename) so substrate
40/// spreads verbatim.
41#[derive(Clone, Debug, Default, Serialize, Deserialize)]
42pub struct PackageArgs {
43    pub pname: Option<String>,
44    pub version: Option<String>,
45    /// FOD hash of the vendored dep tarball. `null` (Nix) =
46    /// `vendor/` directory already in source; `Some("sha256-…")` =
47    /// proxy-fetched.
48    #[serde(rename = "vendorHash", skip_serializing_if = "Option::is_none")]
49    pub vendor_hash: Option<String>,
50    /// Run `go mod vendor` against the proxy (true) vs git tarballs
51    /// (false, default).
52    #[serde(rename = "proxyVendor", skip_serializing_if = "Option::is_none")]
53    pub proxy_vendor: Option<bool>,
54    /// Build tags forwarded to `go build -tags …`.
55    #[serde(skip_serializing_if = "Vec::is_empty")]
56    pub tags: Vec<String>,
57    /// `go build -ldflags …` entries.
58    #[serde(skip_serializing_if = "Vec::is_empty")]
59    pub ldflags: Vec<String>,
60    /// Subpackages to build — paths relative to the module root.
61    /// Default (empty) builds everything under `./...`.
62    #[serde(rename = "subPackages", skip_serializing_if = "Vec::is_empty")]
63    pub sub_packages: Vec<String>,
64    /// Disable check phase. nixpkgs default = true.
65    #[serde(rename = "doCheck", skip_serializing_if = "Option::is_none")]
66    pub do_check: Option<bool>,
67    /// Environment variables — e.g. `CGO_ENABLED=0`, `GOOS=linux`.
68    #[serde(skip_serializing_if = "IndexMap::is_empty")]
69    pub env: IndexMap<String, String>,
70    /// Build-time native deps (cgo headers, generators).
71    #[serde(rename = "nativeBuildInputs", skip_serializing_if = "Vec::is_empty")]
72    pub native_build_inputs: Vec<String>,
73    /// Link-time deps.
74    #[serde(rename = "buildInputs", skip_serializing_if = "Vec::is_empty")]
75    pub build_inputs: Vec<String>,
76}