Skip to content

Commit

Permalink
src: Support passing of Go build options
Browse files Browse the repository at this point in the history
Some downstreams (e.g., Fedora) set additional flags while building
software in their repositories. This also applies to software written in
Go. This work removes the need for manually patching the 'go build'
wrapper script, needed for integrating 'go build' into Meson, to add the
desired build options.

This introduces a new build option 'build_flags'.
  • Loading branch information
HarryMichal committed Mar 22, 2022
1 parent 635caf6 commit 531cf4b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ option(
type: 'boolean',
value: true,
)

option(
'build_flags',
description: 'Options passed to \'go build\' during build',
type: 'string',
)
10 changes: 8 additions & 2 deletions src/go-build-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
#

import os
import shlex
import subprocess
import sys

prog_name = os.path.basename(sys.argv[0])

if len(sys.argv) != 7:
if len(sys.argv) != 8:
print('{}: wrong arguments'.format(prog_name), file=sys.stderr)
print('''Usage: {} [SOURCE DIR]
[OUTPUT DIR]
[VERSION]
[C COMPILER]
[DYNAMIC LINKER]
[MIGRATION PATH FORCOREOS/TOOLBOX]'''.format(prog_name), file=sys.stderr)
[MIGRATION PATH FORCOREOS/TOOLBOX]
[BUILD FLAGS]'''.format(prog_name), file=sys.stderr)
sys.exit(1)

source_dir = sys.argv[1]
Expand All @@ -38,6 +40,7 @@
cc = sys.argv[4]
dyn_linker = sys.argv[5]
coreos_migration = sys.argv[6]
build_flags = sys.argv[7]

os.chdir(source_dir)

Expand Down Expand Up @@ -84,6 +87,9 @@
if coreos_migration:
build_cmd.extend(['-tags', 'migration_path_for_coreos_toolbox'])

if build_flags:
build_cmd.extend(shlex.split(build_flags))

build_cmd.extend([
'-ldflags',
f'-extldflags \'-Wl,-dynamic-linker,{dynamic_linker} -Wl,-rpath,{rpath}\' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion={version}'
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ custom_target(
cc.cmd_array().get(-1),
dynamic_linker,
migration_path_for_coreos_toolbox.to_string(),
get_option('build_flags'),
],
input: sources,
install: true,
Expand Down

0 comments on commit 531cf4b

Please sign in to comment.