build: Hook up the Go code with Meson
Meson doesn't support Go [1], so this is implemented by a custom target that invokes 'go build' to generate the binary. Unfortunately, when using Go modules, 'go build' insists on being invoked in the same source directory where the go.mod file lives, while Meson insists on using a build directory separate from the corresponding source directory. This is addressed by using a build script that goes into the source directory and then invokes 'go build'. Currently, the Go code is only built when a Go implementation is found, and even then, it's not installed. Non-technical end-users are supposed to continue using the POSIX shell implementation until the Go version is blessed as stable. [1] https://github.com/mesonbuild/meson/issues/123 https://github.com/containers/toolbox/pull/318
This commit is contained in:
parent
d857471aa2
commit
1b6d7d6410
3 changed files with 54 additions and 0 deletions
|
@ -5,6 +5,7 @@ project(
|
|||
meson_version: '>= 0.40.0',
|
||||
)
|
||||
|
||||
go = find_program('go', required: false)
|
||||
go_md2man = find_program('go-md2man')
|
||||
shellcheck = find_program('shellcheck', required: false)
|
||||
|
||||
|
@ -35,3 +36,4 @@ endif
|
|||
subdir('data')
|
||||
subdir('doc')
|
||||
subdir('profile.d')
|
||||
subdir('src')
|
||||
|
|
31
src/go-build-wrapper
Executable file
31
src/go-build-wrapper
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright © 2020 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "go-build-wrapper: wrong arguments" >&2
|
||||
echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! cd "$1"; then
|
||||
echo "go-build-wrapper: failed to enter source directory $1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
go build -o "$2"
|
||||
exit "$?"
|
21
src/meson.build
Normal file
21
src/meson.build
Normal file
|
@ -0,0 +1,21 @@
|
|||
go_build_wrapper_file = files('go-build-wrapper')
|
||||
go_build_wrapper_program = find_program('go-build-wrapper')
|
||||
|
||||
sources = files(
|
||||
'toolbox.go',
|
||||
'cmd/root.go',
|
||||
)
|
||||
|
||||
if go.found()
|
||||
custom_target(
|
||||
'toolbox-go',
|
||||
build_by_default: true,
|
||||
command: [go_build_wrapper_program, meson.current_source_dir(), meson.current_build_dir()],
|
||||
input: sources,
|
||||
output: 'toolbox',
|
||||
)
|
||||
endif
|
||||
|
||||
if shellcheck.found()
|
||||
test('shellcheck go-build-wrapper', shellcheck, args: [go_build_wrapper_file])
|
||||
endif
|
Loading…
Reference in a new issue