Help Request: WSL Docker Build Errors

Hey all,

Currently trying to build the swift compiler (debug mode) within a docker container on WSL (Ubuntu 22.04) but am experiening some errors.

After running ./swift/utils/build-script --debug-swift --bootstrapping=hosttools --skip-build-benchmarks --skip-test-cmark from within the container, I get a ton of errors along the lines of:
CMake Error at <some_dir> (configure_file) Operation not permitted.

For example, here is one of the errors:

CMake Error at Modules/CMakeDetermineSystem.cmake:192 (configure_file):
  Operation not permitted
Call Stack (most recent call first):
  CMakeLists.txt:12 (project)

I first thought it had to be some secutity/permissions related thing with WSL and docker, so I added the --sercurity-opt flag when trying to run the container:
docker run --security-opt seccomp=unconfined -it -v <host_path>:/workspace swift-compiler-image. It was also mentioned here to do so

Not quite sure what's causing the issue as Its my first time using docker and building swift as well.

Any suggestions would be appreciated!

Where is your swift checkout located? Is it inside of WSL, inside the docker container itself, or perhaps on the host Windows machine? Definitely don’t try having the sources in your Windows file system because that’s a bad idea.

It should be fine to have it inside of your WSL distribution, just make sure that your container is running a user with the same uid/gid as the WSL distribution if you are sharing a volume to it.

If permissions are okay then another thing you can try is to run the container with —privileged and see if that helps.

1 Like

Swift checkout is located inside my WSL distribution

Passing my WSL uid/gid as args when building the docker image seemed to work solve the operation not permitted errors! Thank you for the suggestion.

Unfortunately, I'm getting hit with a new error now:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBMD_LIBRARY
    linked by target "cmTC_87ac9" in directory /workspace/build/cmake-linux-x86_64/CMakeFiles/CMakeTmp

CMake Error at Utilities/cmlibarchive/CMakeLists.txt:925 (TRY_COMPILE):
  Failed to generate test project build system.
Call Stack (most recent call first):
  Utilities/cmlibarchive/CMakeLists.txt:1993 (CHECK_CRYPTO)

This looks like you’re missing a library in your docker container that is required for building. Could it be libmd-dev, based on the error?

I have libmd-dev within the container, verified by running dpkg -l | grep libmd-dev
I also explicitly added the library to the dockerfile as well, but the error strangely persists

Could it be it cannot locate the file? Am unsure

Such fun. Have you tried to delete the build directory and launch the build again? Another thing you can try to do is skip building cmake- I usually just delete the cmake checkout dir so the scripts don’t try to build it.

1 Like

Alright so deleting the build directory and relaunching worked to resolve the above error! Thanks again. Although it turns out when I reached the 70% mark it just crashed with linker errors, which are different each time I attempt to rebuild (I kind of expected it because my pc only has 16 gb RAM, probably needs more since overhead of WSL/docker)

I initially tried builing directly on WSL only, but linker errors made me want to try experiment with using docker. So now i know that memory is actually the issue

The easy solution is probably just to work off a different system since my ram is soldered to the systemboard (non-upgradable) :sweat_smile: seoncd solution would be playing around with compiler flags to make the build take up less memory perhaps (tried this with few flags, still in process to find a flag combo that works)

Yeah I've found that 16GB is not enough if using WSL2 with Docker. You can always install Linux directly and build in that environment and then 16GB should be enough, but that's plenty of setup time just to get that in there. I've been able to build Swift on a Ubuntu 22.04 host with just 16GB of RAM (and a quad core i7) so yeah.

Yeah I've been able to build it in release mode when directly using WSL2, its just debug mode that's more challenging to build with

Gotcha, I haven’t tried debug mode (I’m only interested in release mode because I want to build for various targets). Good luck in your endeavors!

Thank you! :slightly_smiling_face: