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

Add wkdev-setup-default-clang script #65

Merged
merged 1 commit into from
Feb 18, 2025
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
10 changes: 6 additions & 4 deletions images/wkdev_sdk/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ COPY /rootfs/usr/bin/podman-host /usr/bin/podman-host

COPY /rootfs/etc/ccache.conf /etc/ccache.conf

# Convenience symlink for clang tools, the VSCode extension doesn't find these by default.
RUN for command in clang clang++ clangd clang-format clang-tidy lld lldb lldb-server lldb-vscode; do \
ln -s "/usr/bin/${command}-18" "/usr/local/bin/${command}"; \
done && ln -s "/usr/bin/lld-18" "/usr/local/bin/ld.lld";
# Convenience symlinks for clang tools, the VSCode extension doesn't find these by default.
# FIXME: Reduce code duplication with `wkdev-set-default-clang`.
RUN bash -c 'for binary in /usr/bin/*-18; do \
binary_name="$(basename $binary)"; \
ln -s "${binary}" "/usr/local/bin/${binary_name::-3}"; \
done'

# Fix Qt6 system packages - missing symlinks in the Ubuntu-provided packages.
RUN export QT_VERSION=$(qmake6 -query QT_VERSION) && \
Expand Down
67 changes: 67 additions & 0 deletions scripts/container-only/wkdev-setup-default-clang
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
# Copyright 2024 Igalia S.L.
# SPDX-License: MIT

if [ -f "${WKDEV_SDK}/.wkdev-sdk-root" ]; then
source "${WKDEV_SDK}/utilities/application.sh"
else
echo "Please set \${WKDEV_SDK} to point to the root of the wkdev-sdk checkout."
exit 1
fi

min_clang_version=14
max_clang_version=18

init_application "${0}" "Installs and creates symlinks to set default clang executables" container-only

argsparse_use_option "=version:" "The clang version between ${min_clang_version}-${max_clang_version}" "mandatory" "type:uint"


argsparse_usage_description="$(cat <<EOF
<< Purpose >>

Provides an easy way to install and switch between clang toolchains.

<< Examples >>

$ ${application_name} --version=17
EOF
)"

run() {

argsparse_parse_options "${@}"
local version="${program_options["version"]}"

_log_ ""

# Sanity check versions Ubuntu actually has.
if (( ${version} < ${min_clang_version} )) || (( ${version} > ${max_clang_version})); then
_log_ "${version} is not a valid value (between ${min_clang_version}-${max_clang_version})."
exit 1
fi

if [ ! -f "/usr/bin/clang-${version}" ]; then
_log_ "Installing clang toolchain version ${version}"
_log_ ""
if ! sudo apt-get install "clang-tools-${version}" "clangd-${version}" "clang-format-${version}" "clang-tidy-${version}" "lld-${version}" "lldb-${version}"; then
_log_ ""
_log_ "Failed to install clang toolchain"
exit 1
fi
fi

local output_path
if [ "$EUID" -eq 0 ]; then
output_path="/usr/local/bin"
else
output_path="${HOME}/.local/bin"
fi
_log_ "Creating symlinks in ${output_path}"
for binary in /usr/bin/*-"${version}"; do
local binary_name="$(basename ${binary})"
ln --symbolic --force "${binary}" "${output_path}/${binary_name::-3}"
done
}

run "${@}"