Skip to content

Commit 88bdd17

Browse files
committed
Replace build wrapper with native meson targets
1 parent c66ddd1 commit 88bdd17

4 files changed

Lines changed: 60 additions & 216 deletions

File tree

src/go-build-wrapper

Lines changed: 0 additions & 122 deletions
This file was deleted.

src/meson.build

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
go_build_wrapper_file = files('go-build-wrapper')
2-
go_build_wrapper_program = find_program('go-build-wrapper')
3-
4-
meson_generate_completions_program = find_program('meson_generate_completions.py')
51
meson_go_fmt_program = find_program('meson_go_fmt.py')
62

73
sources = files(
8-
'toolbox.go',
94
'cmd/completion.go',
105
'cmd/create.go',
116
'cmd/enter.go',
@@ -22,120 +17,122 @@ sources = files(
2217
'cmd/utils.go',
2318
'pkg/nvidia/nvidia.go',
2419
'pkg/podman/container.go',
20+
'pkg/podman/containerInspect_test.go',
2521
'pkg/podman/errors.go',
2622
'pkg/podman/podman.go',
27-
'pkg/podman/containerInspect_test.go',
2823
'pkg/shell/shell.go',
2924
'pkg/shell/shell_test.go',
3025
'pkg/skopeo/skopeo.go',
3126
'pkg/term/term.go',
3227
'pkg/term/term_test.go',
33-
'pkg/utils/libsubid-wrappers.c',
3428
'pkg/utils/arch.go',
3529
'pkg/utils/errors.go',
3630
'pkg/utils/fedora.go',
31+
'pkg/utils/libsubid-wrappers.c',
3732
'pkg/utils/rhel.go',
3833
'pkg/utils/utils.go',
3934
'pkg/utils/utils_cgo.go',
4035
'pkg/utils/utils_test.go',
4136
'pkg/version/version.go',
4237
)
4338

44-
cpu_family = host_machine.cpu_family()
45-
endian = host_machine.endian()
39+
toolbox_go = custom_target(
40+
'toolbox',
41+
command: [
42+
go,
43+
'build',
44+
'-C', meson.current_source_dir(),
45+
'-trimpath',
46+
'-buildmode=c-archive',
47+
'-o', meson.project_build_root() + '/@OUTPUT@',
48+
'@INPUT@',
49+
],
50+
depend_files: sources,
51+
input: 'toolbox.go',
52+
output: 'toolbox.a',
53+
)
54+
55+
cc_exe = cc.cmd_array().get(-1)
56+
readlink = find_program('readlink')
57+
dirname = find_program('dirname')
4658

47-
dynamic_linker = ''
48-
if cpu_family == 'aarch64' and endian == 'little'
49-
dynamic_linker = '/lib/ld-linux-aarch64.so.1'
50-
elif cpu_family == 'arm' and endian == 'little'
51-
dynamic_linker = '/lib/ld-linux-armhf.so.3'
52-
elif cpu_family == 'loongarch64' and endian == 'little'
53-
dynamic_linker = '/lib64/ld-linux-loongarch-lp64d.so.1'
54-
elif cpu_family == 'ppc64' and endian == 'little'
55-
dynamic_linker = '/lib64/ld64.so.2'
56-
elif cpu_family == 's390x' and endian == 'big'
57-
dynamic_linker = '/lib/ld64.so.1'
58-
elif cpu_family == 'x86' and endian == 'little'
59-
dynamic_linker = '/lib/ld-linux.so.2'
60-
elif cpu_family == 'x86_64' and endian == 'little'
61-
dynamic_linker = '/lib64/ld-linux-x86-64.so.2'
62-
elif cpu_family == 'riscv64' and endian == 'little'
63-
dynamic_linker = '/lib/ld-linux-riscv64-lp64d.so.1'
64-
else
65-
host_machine_description = cpu_family + ' (' + endian + ' endian)'
66-
error('Please specify dynamic linker for:', host_machine_description)
67-
endif
59+
libc_path = run_command(cc_exe, '--print-file-name=libc.so', capture: true, check: true).stdout()
60+
libc_canon = run_command(readlink, '--canonicalize', libc_path, capture: true, check: true).stdout()
61+
libc_dir = run_command(dirname, libc_canon, capture: true, check: true).stdout().strip()
6862

69-
message('Host machine dynamic linker:', dynamic_linker)
63+
message('Host machine libc:', libc_dir)
7064

71-
toolbox_go = custom_target(
65+
rpath = '/run/host' + libc_dir
66+
message('Setting rpath:', rpath)
67+
68+
toolbox = executable(
7269
'toolbox',
73-
command: [
74-
go_build_wrapper_program,
75-
meson.current_source_dir(),
76-
meson.project_build_root(),
77-
'@OUTPUT@',
78-
meson.project_version(),
79-
cc.cmd_array().get(-1),
80-
dynamic_linker,
81-
migration_path_for_coreos_toolbox.to_string(),
70+
sources: [],
71+
link_whole: toolbox_go,
72+
link_args: [
73+
'-Wl,-z,lazy',
74+
'-Wl,--export-dynamic',
75+
'-Wl,--unresolved-symbols=ignore-in-object-files',
8276
],
83-
input: sources,
77+
build_rpath: rpath,
78+
install_rpath: rpath,
8479
install: true,
8580
install_dir: get_option('bindir'),
86-
output: 'toolbox',
8781
)
8882

8983
if bashcompletionsdir != ''
9084
custom_target(
9185
'bash-completion',
9286
capture: true,
9387
command: [
94-
meson_generate_completions_program,
95-
meson.current_source_dir(),
88+
toolbox,
89+
'completion',
9690
'bash',
9791
],
98-
depends: [toolbox_go],
9992
install: true,
10093
install_dir: bashcompletionsdir,
10194
output: 'toolbox.bash',
102-
)
95+
)
10396
endif
10497

10598
if fishcompletionsdir != ''
10699
custom_target(
107100
'fish-completion',
108101
capture: true,
109102
command: [
110-
meson_generate_completions_program,
111-
meson.current_source_dir(),
103+
toolbox,
104+
'completion',
112105
'fish',
113106
],
114-
depends: [toolbox_go],
115107
install: true,
116108
install_dir: fishcompletionsdir,
117109
output: 'toolbox.fish',
118-
)
110+
)
119111
endif
120112

121113
custom_target(
122114
'zsh-completion',
123115
capture: true,
124116
command: [
125-
meson_generate_completions_program,
126-
meson.current_source_dir(),
117+
toolbox,
118+
'completion',
127119
'zsh',
128120
],
129-
depends: [toolbox_go],
130121
install: true,
131122
install_dir: zshcompletionsdir,
132123
output: '_toolbox',
133124
)
134125

135-
if shellcheck.found()
136-
test('shellcheck src/go-build-wrapper', shellcheck, args: [go_build_wrapper_file])
137-
endif
138-
139126
test('go fmt', meson_go_fmt_program, args: [meson.current_source_dir()])
140-
test('go vet', go, args: ['vet', '-c', '3', './...'], workdir: meson.current_source_dir())
141-
test('go test', go, args: ['test', '-vet', 'off', './...'], workdir: meson.current_source_dir())
127+
test(
128+
'go vet',
129+
go,
130+
args: ['vet', '-c', '3', './...'],
131+
workdir: meson.current_source_dir(),
132+
)
133+
test(
134+
'go test',
135+
go,
136+
args: ['test', '-vet', 'off', './...'],
137+
workdir: meson.current_source_dir(),
138+
)

src/meson_generate_completions.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/toolbox.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package main
1818

19+
import "C"
20+
1921
import "github.com/containers/toolbox/cmd"
2022

23+
//export main
2124
func main() {
2225
cmd.Execute()
2326
}

0 commit comments

Comments
 (0)