Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove build options #1770

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 42 additions & 44 deletions docs/md/melange_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,48 @@ melange build [flags]
### Options

```
--apk-cache-dir string directory used for cached apk packages (default is system-defined cache directory)
--arch strings architectures to build for (e.g., x86_64,ppc64le,arm64) -- default is all, unless specified in config
--build-date string date used for the timestamps of the files inside the image
--build-option strings build options to enable
--cache-dir string directory used for cached inputs (default "./melange-cache/")
--cache-source string directory or bucket used for preloading the cache
--cleanup when enabled, the temp dir used for the guest will be cleaned up after completion (default true)
--cpu string default CPU resources to use for builds
--cpumodel string default memory resources to use for builds
--create-build-log creates a package.log file containing a list of packages that were built by the command
--debug enables debug logging of build pipelines
--debug-runner when enabled, the builder pod will persist after the build succeeds or fails
--dependency-log string log dependencies to a specified file
--disk string disk size to use for builds
--empty-workspace whether the build workspace should be empty
--env-file string file to use for preloaded environment variables
--generate-index whether to generate APKINDEX.tar.gz (default true)
--git-commit string commit hash of the git repository containing the build config file (defaults to detecting HEAD)
--git-repo-url string URL of the git repository containing the build config file (defaults to detecting from configured git remotes)
--guest-dir string directory used for the build environment guest
-h, --help help for build
--ignore-signatures ignore repository signature verification
-i, --interactive when enabled, attaches stdin with a tty to the pod on failure
-k, --keyring-append strings path to extra keys to include in the build environment keyring
--license string license to use for the build config file itself (default "NOASSERTION")
--lint-require strings linters that must pass (default [dev,infodir,tempdir,varempty])
--lint-warn strings linters that will generate warnings (default [object,opt,pkgconf,python/docs,python/multiple,python/test,setuidgid,srv,strip,usrlocal,usrmerge,worldwrite])
--memory string default memory resources to use for builds
--namespace string namespace to use in package URLs in SBOM (eg wolfi, alpine) (default "unknown")
--out-dir string directory where packages will be output (default "./packages/")
--overlay-binsh string use specified file as /bin/sh overlay in build environment
--override-host-triplet-libc-substitution-flavor string override the flavor of libc for ${{host.triplet.*}} substitutions (e.g. gnu,musl) -- default is gnu (default "gnu")
--package-append strings extra packages to install for each of the build environments
--pipeline-dir string directory used to extend defined built-in pipelines
-r, --repository-append strings path to extra repositories to include in the build environment
--rm clean up intermediate artifacts (e.g. container images, temp dirs) (default true)
--runner string which runner to use to enable running commands, default is based on your platform. Options are ["bubblewrap" "docker" "qemu"]
--signing-key string key to use for signing
--source-dir string directory used for included sources
--strip-origin-name whether origin names should be stripped (for bootstrap)
--timeout duration default timeout for builds
--trace string where to write trace output
--vars-file string file to use for preloaded build configuration variables
--workspace-dir string directory used for the workspace at /home/build
--apk-cache-dir string directory used for cached apk packages (default is system-defined cache directory)
--arch strings architectures to build for (e.g., x86_64,ppc64le,arm64) -- default is all, unless specified in config
--build-date string date used for the timestamps of the files inside the image
--cache-dir string directory used for cached inputs (default "./melange-cache/")
--cache-source string directory or bucket used for preloading the cache
--cleanup when enabled, the temp dir used for the guest will be cleaned up after completion (default true)
--cpu string default CPU resources to use for builds
--cpumodel string default memory resources to use for builds
--create-build-log creates a package.log file containing a list of packages that were built by the command
--debug enables debug logging of build pipelines
--debug-runner when enabled, the builder pod will persist after the build succeeds or fails
--dependency-log string log dependencies to a specified file
--disk string disk size to use for builds
--empty-workspace whether the build workspace should be empty
--env-file string file to use for preloaded environment variables
--generate-index whether to generate APKINDEX.tar.gz (default true)
--git-commit string commit hash of the git repository containing the build config file (defaults to detecting HEAD)
--git-repo-url string URL of the git repository containing the build config file (defaults to detecting from configured git remotes)
--guest-dir string directory used for the build environment guest
-h, --help help for build
--ignore-signatures ignore repository signature verification
-i, --interactive when enabled, attaches stdin with a tty to the pod on failure
-k, --keyring-append strings path to extra keys to include in the build environment keyring
--license string license to use for the build config file itself (default "NOASSERTION")
--lint-require strings linters that must pass (default [dev,infodir,tempdir,varempty])
--lint-warn strings linters that will generate warnings (default [object,opt,pkgconf,python/docs,python/multiple,python/test,setuidgid,srv,strip,usrlocal,usrmerge,worldwrite])
--memory string default memory resources to use for builds
--namespace string namespace to use in package URLs in SBOM (eg wolfi, alpine) (default "unknown")
--out-dir string directory where packages will be output (default "./packages/")
--overlay-binsh string use specified file as /bin/sh overlay in build environment
--package-append strings extra packages to install for each of the build environments
--pipeline-dir string directory used to extend defined built-in pipelines
-r, --repository-append strings path to extra repositories to include in the build environment
--rm clean up intermediate artifacts (e.g. container images, temp dirs) (default true)
--runner string which runner to use to enable running commands, default is based on your platform. Options are ["bubblewrap" "docker" "qemu"]
--signing-key string key to use for signing
--source-dir string directory used for included sources
--strip-origin-name whether origin names should be stripped (for bootstrap)
--timeout duration default timeout for builds
--trace string where to write trace output
--vars-file string file to use for preloaded build configuration variables
--workspace-dir string directory used for the workspace at /home/build
```

### Options inherited from parent commands
Expand Down
1 change: 0 additions & 1 deletion docs/md/melange_compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ melange compile [flags]
--apk-cache-dir string directory used for cached apk packages (default is system-defined cache directory)
--arch string architectures to compile for
--build-date string date used for the timestamps of the files inside the image
--build-option strings build options to enable
--cache-dir string directory used for cached inputs (default "./melange-cache/")
--cache-source string directory or bucket used for preloading the cache
--cpu string default CPU resources to use for builds
Expand Down
54 changes: 0 additions & 54 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ type Build struct {
EmptyWorkspace bool
OutDir string
Arch apko_types.Architecture
Libc string
ExtraKeys []string
ExtraRepos []string
ExtraPackages []string
Expand Down Expand Up @@ -141,8 +140,6 @@ type Build struct {
Auth map[string]options.Auth
IgnoreSignatures bool

EnabledBuildOptions []string

// Initialized in New and mutated throughout the build process as we gain
// visibility into our packages' (including subpackages') composition. This is
// how we get "build-time" SBOMs!
Expand Down Expand Up @@ -257,17 +254,6 @@ func New(ctx context.Context, opts ...Option) (*Build, error) {
return nil, fmt.Errorf("unable to run containers using %s, specify --runner and one of %s", b.Runner.Name(), GetAllRunners())
}

// Apply build options to the context.
for _, optName := range b.EnabledBuildOptions {
log.Infof("applying configuration patches for build option %s", optName)

if opt, ok := b.Configuration.Options[optName]; ok {
if err := b.applyBuildOption(opt); err != nil {
return nil, err
}
}
}

return &b, nil
}

Expand Down Expand Up @@ -412,37 +398,6 @@ func copyFile(base, src, dest string, perm fs.FileMode) error {
return nil
}

// applyBuildOption applies a patch described by a BuildOption to a package build.
func (b *Build) applyBuildOption(bo config.BuildOption) error {
// Patch the variables block.
if b.Configuration.Vars == nil {
b.Configuration.Vars = make(map[string]string)
}

for k, v := range bo.Vars {
b.Configuration.Vars[k] = v
}

// Patch the build environment configuration.
lo := bo.Environment.Contents.Packages
b.Configuration.Environment.Contents.Packages = append(b.Configuration.Environment.Contents.Packages, lo.Add...)

for _, pkg := range lo.Remove {
pkgList := b.Configuration.Environment.Contents.Packages

for pos, ppkg := range pkgList {
if pkg == ppkg {
pkgList[pos] = pkgList[len(pkgList)-1]
pkgList = pkgList[:len(pkgList)-1]
}
}

b.Configuration.Environment.Contents.Packages = pkgList
}

return nil
}

func (b *Build) loadIgnoreRules(ctx context.Context) ([]*xignore.Pattern, error) {
log := clog.FromContext(ctx)
ignorePath := filepath.Join(b.SourceDir, b.WorkspaceIgnore)
Expand Down Expand Up @@ -1134,15 +1089,6 @@ func (b *Build) summarize(ctx context.Context) {
b.SummarizePaths(ctx)
}

// buildFlavor determines if a build context uses glibc or musl, it returns
// "gnu" for GNU systems, and "musl" for musl systems.
func (b *Build) buildFlavor() string {
if b.Libc == "" {
return "gnu"
}
return b.Libc
}

func (b *Build) buildWorkspaceConfig(ctx context.Context) *container.Config {
log := clog.FromContext(ctx)
if b.isBuildLess() {
Expand Down
7 changes: 2 additions & 5 deletions pkg/build/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ const unidentifiablePipeline = "???"
func (t *Test) Compile(ctx context.Context) error {
cfg := t.Configuration

// TODO: Make this parameter go away when we revisit subtitutions.
flavor := "gnu"

sm, err := NewSubstitutionMap(&cfg, t.Arch, flavor, nil)
sm, err := NewSubstitutionMap(&cfg, t.Arch, "gnu")
if err != nil {
return err
}
Expand Down Expand Up @@ -116,7 +113,7 @@ func (t *Test) Compile(ctx context.Context) error {
// Compile compiles all configuration, including tests, by loading any pipelines and substituting all variables.
func (b *Build) Compile(ctx context.Context) error {
cfg := b.Configuration
sm, err := NewSubstitutionMap(&cfg, b.Arch, b.buildFlavor(), b.EnabledBuildOptions)
sm, err := NewSubstitutionMap(&cfg, b.Arch, "gnu")
if err != nil {
return err
}
Expand Down
19 changes: 0 additions & 19 deletions pkg/build/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,6 @@ func WithNamespace(namespace string) Option {
}
}

// WithEnabledBuildOptions takes an array of strings representing enabled build
// options. These options are referenced in the options block of the Configuration,
// and represent patches to the configured build process which are optionally
// applied.
func WithEnabledBuildOptions(enabledBuildOptions []string) Option {
return func(b *Build) error {
b.EnabledBuildOptions = enabledBuildOptions
return nil
}
}

// WithCreateBuildLog indicates whether to generate a package.log file containing the
// list of packages that were built. Some packages may have been skipped
// during the build if , so it can be hard to know exactly which packages were built
Expand Down Expand Up @@ -397,14 +386,6 @@ func WithAuth(domain, user, pass string) Option {
}
}

// WithLibcFlavorOverride sets the libc flavor for the build.
func WithLibcFlavorOverride(libc string) Option {
return func(b *Build) error {
b.Libc = libc
return nil
}
}

// WithIgnoreIndexSignatures sets whether to ignore repository signature verification.
func WithIgnoreSignatures(ignore bool) Option {
return func(b *Build) error {
Expand Down
12 changes: 1 addition & 11 deletions pkg/build/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (sm *SubstitutionMap) Subpackage(subpkg *config.Subpackage) *SubstitutionMa
return &SubstitutionMap{nw}
}

func NewSubstitutionMap(cfg *config.Configuration, arch apkoTypes.Architecture, flavor string, buildOpts []string) (*SubstitutionMap, error) {
func NewSubstitutionMap(cfg *config.Configuration, arch apkoTypes.Architecture, flavor string) (*SubstitutionMap, error) {
pkg := cfg.Package

nw := map[string]string{
Expand Down Expand Up @@ -122,16 +122,6 @@ func NewSubstitutionMap(cfg *config.Configuration, arch apkoTypes.Architecture,
nw[k] = fmt.Sprintf("/home/build/melange-out/%s", pn)
}

for k := range cfg.Options {
nk := fmt.Sprintf("${{options.%s.enabled}}", k)
nw[nk] = "false"
}

for _, opt := range buildOpts {
nk := fmt.Sprintf("${{options.%s.enabled}}", opt)
nw[nk] = "true"
}

return &SubstitutionMap{nw}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/build/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Test_substitutionMap(t *testing.T) {
},
},
}
m, err := NewSubstitutionMap(&cfg, "", "", nil)
m, err := NewSubstitutionMap(&cfg, "", "")
require.NoError(t, err)
require.Equal(t, tt.expected, m.Substitutions["${{vars.mangled-package-version}}"])
})
Expand All @@ -92,7 +92,7 @@ func Test_MutateWith(t *testing.T) {
Epoch: tc.epoch,
},
}
sm, err := NewSubstitutionMap(&cfg, "", "", nil)
sm, err := NewSubstitutionMap(&cfg, "", "")
require.NoError(t, err)
got, err := sm.MutateWith(map[string]string{})
if err != nil {
Expand Down Expand Up @@ -128,7 +128,7 @@ func Test_substitutionNeedPackages(t *testing.T) {
pipelineDirs := []string{"pipelines"}

c := &Compiled{PipelineDirs: pipelineDirs}
sm, err := NewSubstitutionMap(&cfg, "", "", nil)
sm, err := NewSubstitutionMap(&cfg, "", "")
require.NoError(t, err)

err = c.CompilePipelines(ctx, sm, cfg.Pipeline)
Expand Down
2 changes: 2 additions & 0 deletions pkg/build/pipelines/cargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Compile an auditable rust binary with Cargo
| modroot | false | Top directory of the rust package, this is where the target package lives. Before building, the cargo pipeline wil cd into this directory. Defaults to current working directory | . |
| opts | false | Options to pass to cargo build. Defaults to release | --release |
| output | false | Filename to use when writing the binary. The final install location inside the apk will be in prefix / install-dir / output | |
| output-dir | false | Directory where the binaris will be placed after building. Defaults to target/release | target/release |
| prefix | false | Installation prefix. Defaults to usr | usr |
| rustflags | false | Rustc flags to be passed to pass to all compiler invocations that Cargo performs. In contrast with cargo rustc, this is useful for passing a flag to all compiler instances. This string is split by whitespace. | |


<!-- end:pipeline-reference-gen -->
6 changes: 0 additions & 6 deletions pkg/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func buildCmd() *cobra.Command {
var envFile string
var varsFile string
var purlNamespace string
var buildOption []string
var createBuildLog bool
var debug bool
var debugRunner bool
Expand All @@ -74,7 +73,6 @@ func buildCmd() *cobra.Command {
var cpu, cpumodel, memory, disk string
var timeout time.Duration
var extraPackages []string
var libc string
var lintRequire, lintWarn []string
var ignoreSignatures bool
var cleanup bool
Expand Down Expand Up @@ -172,7 +170,6 @@ func buildCmd() *cobra.Command {
build.WithEnvFile(envFile),
build.WithVarsFile(varsFile),
build.WithNamespace(purlNamespace),
build.WithEnabledBuildOptions(buildOption),
build.WithCreateBuildLog(createBuildLog),
build.WithDebug(debug),
build.WithDebugRunner(debugRunner),
Expand All @@ -186,7 +183,6 @@ func buildCmd() *cobra.Command {
build.WithDisk(disk),
build.WithMemory(memory),
build.WithTimeout(timeout),
build.WithLibcFlavorOverride(libc),
build.WithIgnoreSignatures(ignoreSignatures),
build.WithConfigFileRepositoryCommit(configFileGitCommit),
build.WithConfigFileRepositoryURL(configFileGitRepoURL),
Expand Down Expand Up @@ -239,8 +235,6 @@ func buildCmd() *cobra.Command {
cmd.Flags().StringVar(&overlayBinSh, "overlay-binsh", "", "use specified file as /bin/sh overlay in build environment")
cmd.Flags().StringVar(&purlNamespace, "namespace", "unknown", "namespace to use in package URLs in SBOM (eg wolfi, alpine)")
cmd.Flags().StringSliceVar(&archstrs, "arch", nil, "architectures to build for (e.g., x86_64,ppc64le,arm64) -- default is all, unless specified in config")
cmd.Flags().StringVar(&libc, "override-host-triplet-libc-substitution-flavor", "gnu", "override the flavor of libc for ${{host.triplet.*}} substitutions (e.g. gnu,musl) -- default is gnu")
cmd.Flags().StringSliceVar(&buildOption, "build-option", []string{}, "build options to enable")
cmd.Flags().StringVar(&runner, "runner", "", fmt.Sprintf("which runner to use to enable running commands, default is based on your platform. Options are %q", build.GetAllRunners()))
cmd.Flags().StringSliceVarP(&extraKeys, "keyring-append", "k", []string{}, "path to extra keys to include in the build environment keyring")
cmd.Flags().StringSliceVarP(&extraRepos, "repository-append", "r", []string{}, "path to extra repositories to include in the build environment")
Expand Down
Loading
Loading