diff --git a/devops/containers/release_build.Dockerfile b/devops/containers/release_build.Dockerfile index 3d59cb7aeea36..bb678d5781b50 100644 --- a/devops/containers/release_build.Dockerfile +++ b/devops/containers/release_build.Dockerfile @@ -20,6 +20,10 @@ RUN dnf -y install https://repo.radeon.com/amdgpu-install/6.4.1/rhel/8.10/amdgpu dnf -y install rocm && \ dnf clean all && rm -rf /var/cache/dnf +# Build zstd static library from sources +COPY scripts/build_zstd.sh /build_zstd.sh +RUN /build_zstd.sh + COPY scripts/docker_entrypoint.sh /docker_entrypoint.sh USER sycl diff --git a/devops/containers/ubuntu2404_base.Dockerfile b/devops/containers/ubuntu2404_base.Dockerfile index 6890a42dcc95a..8223cd03a0aa5 100644 --- a/devops/containers/ubuntu2404_base.Dockerfile +++ b/devops/containers/ubuntu2404_base.Dockerfile @@ -17,8 +17,8 @@ RUN /install.sh # This causes linking errors when building SYCL runtime. # Bug: https://github.com/intel/llvm/issues/15935 # Workaround: build zstd from sources with -fPIC flag. -COPY scripts/build_zstd_1_5_6_ub24.sh /build_zstd_1_5_6_ub24.sh -RUN /build_zstd_1_5_6_ub24.sh +COPY scripts/build_zstd.sh /build_zstd.sh +RUN /build_zstd.sh COPY scripts/create-sycl-user.sh /user-setup.sh RUN /user-setup.sh diff --git a/devops/containers/ubuntu2404_build.Dockerfile b/devops/containers/ubuntu2404_build.Dockerfile index c659eabbced51..15ecf1ec4434f 100644 --- a/devops/containers/ubuntu2404_build.Dockerfile +++ b/devops/containers/ubuntu2404_build.Dockerfile @@ -12,8 +12,8 @@ RUN /install.sh # This causes linking errors when building SYCL runtime. # Bug: https://github.com/intel/llvm/issues/15935 # Workaround: build zstd from sources with -fPIC flag. -COPY scripts/build_zstd_1_5_6_ub24.sh /build_zstd_1_5_6_ub24.sh -RUN /build_zstd_1_5_6_ub24.sh +COPY scripts/build_zstd.sh /build_zstd.sh +RUN /build_zstd.sh SHELL ["/bin/bash", "-ec"] diff --git a/devops/scripts/build_zstd.sh b/devops/scripts/build_zstd.sh new file mode 100755 index 0000000000000..90b221d15169c --- /dev/null +++ b/devops/scripts/build_zstd.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Script to build and install zstd on Ubuntu 24, with -fPIC flag. +# The default installation of zstd on Ubuntu 24 does not have -fPIC flag +# enabled, which is required for building DPC++ in shared libraries mode. + +# OR on Rocky Linux 8.10 (used for nightly release builds). There is no static +# library (libzstd.a) in available packages, therefore it is necessary to build +# it from source. + +# Function to check OS +check_os() { + local expected_name="$1" + local expected_version="$2" + . /etc/os-release + if [[ "$NAME" == "$expected_name" && "$VERSION_ID" == "$expected_version" ]]; then + return 0 + else + return 1 + fi +} + +# Function to install packages with or without sudo +install_packages() { + if [ "$USE_SUDO" = true ]; then + sudo apt-get update + sudo apt-get install -y build-essential wget + else + apt-get update + apt-get install -y build-essential wget + fi +} + +# Function to uninstall libzstd-dev if installed +uninstall_libzstd_dev() { + if dpkg -l | grep -q libzstd-dev; then + if [ "$USE_SUDO" = true ]; then + sudo apt-get remove -y libzstd-dev + else + apt-get remove -y libzstd-dev + fi + fi +} + +# Function to build a shared library by linking zstd static lib. +# This is used to verify that zstd is built correctly, with -fPIC flag. +build_test_program() { + cat < test_zstd.c + #include + int main() { + ZSTD_CCtx* cctx = ZSTD_createCCtx(); + ZSTD_freeCCtx(cctx); + return 0; + } +EOF + + # Try to use zstd's static library with -fPIC + gcc test_zstd.c -lzstd -fPIC -shared + if [ $? -ne 0 ]; then + echo "zstd installation verification failed." + else + echo "zstd installation verification passed." + fi + + # There won't be a.out file if verification failed. + rm test_zstd.c a.out || true +} + +# Check the OS +if ! check_os "Ubuntu" "24.04" && ! check_os "Rocky Linux" "8.10"; then + echo "Warning: This script has only been tested with Ubuntu 24.04 and Rocky Linux 8.10." +fi + +# Set USE_SUDO to true or false based on your preference +USE_SUDO=true + +# Install necessary build tools & uninstall libzstd-dev package if installed +if check_os "Ubuntu" "24.04"; then + install_packages + uninstall_libzstd_dev +fi + +# Define the version and URL for zstd +ZSTD_VERSION="1.5.7" +ZSTD_URL="https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-$ZSTD_VERSION.tar.gz" + +# Create a directory for the source code +mkdir -p zstd_build +cd zstd_build + +# Download and extract zstd source code +wget $ZSTD_URL +tar -xzf zstd-$ZSTD_VERSION.tar.gz +cd zstd-$ZSTD_VERSION + +# Build zstd with -fPIC flag. +CFLAGS="-fPIC" CXXFLAGS="-fPIC" make +if [ $? -ne 0 ]; then + echo "Error: make failed." + exit 1 +fi + +# Install zstd. +if [ "$USE_SUDO" = true ]; then + sudo make install +else + make install +fi +if [ $? -ne 0 ]; then + echo "Error: make install failed." + exit 1 +fi + +# Verify zstd installation. +build_test_program + +# Clean up +rm -rf zstd_build diff --git a/devops/scripts/build_zstd_1_5_6_ub24.sh b/devops/scripts/build_zstd_1_5_6_ub24.sh index 68a947dfb43a0..d2d4dd73f84f6 100755 --- a/devops/scripts/build_zstd_1_5_6_ub24.sh +++ b/devops/scripts/build_zstd_1_5_6_ub24.sh @@ -1,5 +1,9 @@ #!/bin/bash +# The actual version of this script is build_zstd.sh. +# This one is needed for jenkins precommit to pass, since jenkins still uses the +# old name. Will be removed when Jenkins is updated. + # Script to build and install zstd 1.5.6 on Ubuntu 24, with -fPIC flag. # The default installation of zstd on Ubuntu 24 does not have -fPIC flag # enabled, which is required for building DPC++ in shared libraries mode. diff --git a/sycl/doc/GetStartedGuide.md b/sycl/doc/GetStartedGuide.md index 06642c08e07b8..85d3db3256a1e 100644 --- a/sycl/doc/GetStartedGuide.md +++ b/sycl/doc/GetStartedGuide.md @@ -351,7 +351,7 @@ You can install zstd using the package manager of your distribution. For example ```sh sudo apt-get install libzstd-dev ``` -Note that the libzstd-dev package provided on Ubuntu 24.04 has a bug ([link](https://bugs.launchpad.net/ubuntu/+source/libzstd/+bug/2086543)) and the zstd static library is not built with the `-fPIC` flag. Linking to this library will result in a build failure. For example: [Issue#15935](https://github.com/intel/llvm/issues/15935). As an alternative, zstd can be built from source either manually or by using the [build_zstd_1_5_6_ub24.sh](https://github.com/intel/llvm/blob/sycl/devops/scripts/build_zstd_1_5_6_ub24.sh) script. +Note that the libzstd-dev package provided on Ubuntu 24.04 has a bug ([link](https://bugs.launchpad.net/ubuntu/+source/libzstd/+bug/2086543)) and the zstd static library is not built with the `-fPIC` flag. Linking to this library will result in a build failure. For example: [Issue#15935](https://github.com/intel/llvm/issues/15935). As an alternative, zstd can be built from source either manually or by using the [build_zstd.sh](https://github.com/intel/llvm/blob/sycl/devops/scripts/build_zstd.sh) script (it works on Rocky Linux 8.10 / RHEL 8.10 as well). **Windows**