Skip to content

Commit 531cf4b

Browse files
committed
src: Support passing of Go build options
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'.
1 parent 635caf6 commit 531cf4b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

meson_options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ option(
2424
type: 'boolean',
2525
value: true,
2626
)
27+
28+
option(
29+
'build_flags',
30+
description: 'Options passed to \'go build\' during build',
31+
type: 'string',
32+
)

src/go-build-wrapper.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@
1717
#
1818

1919
import os
20+
import shlex
2021
import subprocess
2122
import sys
2223

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

25-
if len(sys.argv) != 7:
26+
if len(sys.argv) != 8:
2627
print('{}: wrong arguments'.format(prog_name), file=sys.stderr)
2728
print('''Usage: {} [SOURCE DIR]
2829
[OUTPUT DIR]
2930
[VERSION]
3031
[C COMPILER]
3132
[DYNAMIC LINKER]
32-
[MIGRATION PATH FORCOREOS/TOOLBOX]'''.format(prog_name), file=sys.stderr)
33+
[MIGRATION PATH FORCOREOS/TOOLBOX]
34+
[BUILD FLAGS]'''.format(prog_name), file=sys.stderr)
3335
sys.exit(1)
3436

3537
source_dir = sys.argv[1]
@@ -38,6 +40,7 @@
3840
cc = sys.argv[4]
3941
dyn_linker = sys.argv[5]
4042
coreos_migration = sys.argv[6]
43+
build_flags = sys.argv[7]
4144

4245
os.chdir(source_dir)
4346

@@ -84,6 +87,9 @@
8487
if coreos_migration:
8588
build_cmd.extend(['-tags', 'migration_path_for_coreos_toolbox'])
8689

90+
if build_flags:
91+
build_cmd.extend(shlex.split(build_flags))
92+
8793
build_cmd.extend([
8894
'-ldflags',
8995
f'-extldflags \'-Wl,-dynamic-linker,{dynamic_linker} -Wl,-rpath,{rpath}\' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion={version}'

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ custom_target(
5757
cc.cmd_array().get(-1),
5858
dynamic_linker,
5959
migration_path_for_coreos_toolbox.to_string(),
60+
get_option('build_flags'),
6061
],
6162
input: sources,
6263
install: true,

0 commit comments

Comments
 (0)