package dsl import ( "maps" "slices" ) type BuildProfile int const ( ProfileUnset BuildProfile = iota ProfileRelease ProfileDebug ProfileSanitized ) func (p BuildProfile) String() string { switch p { case ProfileRelease: return "release" case ProfileDebug: return "debug" case ProfileSanitized: return "sanitized" default: return "unset" } } type WarningLevel int const ( WarningsUnset WarningLevel = iota WarningsDefault WarningsStrict WarningsPedantic ) func (w WarningLevel) String() string { switch w { case WarningsDefault: return "default" case WarningsStrict: return "strict" case WarningsPedantic: return "pedantic" default: return "unset" } } type BuildConfig struct { Name string Language string Standard string Sources []string Includes []string Output string Profile BuildProfile Warnings WarningLevel Sanitize []string Wrapper string Defines map[string]string Link []string Extra []string Platforms []string Compilers []string Linux *BuildConfig Windows *BuildConfig Darwin *BuildConfig } func (dst *BuildConfig) MergeFrom(src *BuildConfig) { if src == nil { return } if src.Language != "" { dst.Language = src.Language } if src.Standard != "" { dst.Standard = src.Standard } if src.Output != "" { dst.Output = src.Output } if src.Profile != ProfileUnset { dst.Profile = src.Profile } if src.Warnings != WarningsUnset { dst.Warnings = src.Warnings } if src.Wrapper != "" { dst.Wrapper = src.Wrapper } dst.Sources = append(dst.Sources, src.Sources...) dst.Includes = append(dst.Includes, src.Includes...) dst.Sanitize = append(dst.Sanitize, src.Sanitize...) dst.Link = append(dst.Link, src.Link...) dst.Extra = append(dst.Extra, src.Extra...) dst.Platforms = append(dst.Platforms, src.Platforms...) dst.Compilers = append(dst.Compilers, src.Compilers...) if len(src.Defines) > 0 { if dst.Defines == nil { dst.Defines = map[string]string{} } maps.Copy(dst.Defines, src.Defines) } } func (b *BuildConfig) Resolve(defaults *BuildConfig, os string) BuildConfig { var out BuildConfig out.MergeFrom(defaults) out.MergeFrom(b) out.Name = b.Name var osOverride *BuildConfig switch os { case "linux": osOverride = b.Linux case "windows": osOverride = b.Windows case "darwin": osOverride = b.Darwin } out.MergeFrom(osOverride) return out } func (b *BuildConfig) AppliesTo(os, compiler string) bool { if len(b.Platforms) > 0 && !slices.Contains(b.Platforms, os) { return false } if len(b.Compilers) > 0 && !slices.Contains(b.Compilers, compiler) { return false } return true } type ToolchainSpec struct { Name string Platforms []string Binary string Class string }