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

build: Don't assume that libc.so is always in /usr/lib or /usr/lib64 #923

Merged
Merged
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
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
project(
'toolbox',
'c',
version: '0.0.99.2',
license: 'ASL 2.0',
meson_version: '>= 0.53.0',
)

cc = meson.get_compiler('c')

go = find_program('go')
go_md2man = find_program('go-md2man')
patchelf = find_program('patchelf')
Expand Down
21 changes: 18 additions & 3 deletions src/go-build-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#


if [ "$#" -ne 3 ]; then
if [ "$#" -ne 4 ]; then
echo "go-build-wrapper: wrong arguments" >&2
echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION]" >&2
echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION] [C COMPILER]" >&2
exit 1
fi

Expand All @@ -27,7 +27,22 @@ if ! cd "$1"; then
exit 1
fi

go build -trimpath -ldflags "-extldflags '-Wl,-rpath,/run/host/usr/lib -Wl,-rpath,/run/host/usr/lib64' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"
if ! libc_dir=$("$4" --print-file-name=libc.so); then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish there was a way to do this with Meson's compiler.find_library.

echo "go-build-wrapper: failed to read the path to libc.so" >&2
exit 1
fi

if ! libc_dir_canonical=$(readlink --canonicalize "$libc_dir"); then
echo "go-build-wrapper: failed to canonicalize the path to libc.so" >&2
exit 1
fi

if ! libc_dir_canonical_dirname=$(dirname "$libc_dir_canonical"); then
echo "go-build-wrapper: failed to read the dirname of the canonicalized path to libc.so" >&2
exit 1
fi

go build -trimpath -ldflags "-extldflags '-Wl,-rpath,/run/host$libc_dir_canonical_dirname' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"

if ! interpreter=$(patchelf --print-interpreter "$2/toolbox"); then
echo "go-build-wrapper: failed to read PT_INTERP from $2/toolbox" >&2
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ custom_target(
meson.current_source_dir(),
meson.current_build_dir(),
meson.project_version(),
cc.cmd_array().get(-1),
],
input: sources,
install: true,
Expand Down