Swiftc built from source fails to compile anything on Ubuntu

I apologize if this is the wrong category.

I've built Swift from source, and was using only the REPL. Only now I found out swiftc fails to compile any program at all with message:

<unknown>:0: error: unable to execute command: <unknown>

Using swiftc to emit-lllvm though works fine.

Digging at the source-code, this error seems to be thrown in method runTaskQueueToCompletion of class PerformJobsState, file Compilation.cpp:

    void runTaskQueueToCompletion() {
      do {
        using namespace std::placeholders;
        // Ask the TaskQueue to execute.
        if (TQ->execute(std::bind(&PerformJobsState::taskBegan, this, _1, _2),
                        std::bind(&PerformJobsState::taskFinished, this, _1, _2,
                                  _3, _4, _5, _6),
                        std::bind(&PerformJobsState::taskSignalled, this, _1,
                                  _2, _3, _4, _5, _6, _7))) {
          if (Result == EXIT_SUCCESS) {
            // FIXME: Error from task queue while Result == EXIT_SUCCESS most
            // likely means some fork/exec or posix_spawn failed; TaskQueue saw
            // "an error" at some stage before even calling us with a process
            // exit / signal (or else a poll failed); unfortunately the task
            // causing it was dropped on the floor and we have no way to recover
            // it here, so we report a very poor, generic error.
            Comp.getDiags().diagnose(SourceLoc(),
                                     diag::error_unable_to_execute_command,
                                     "<unknown>");
        // ...

I tried rebuilding swift but I get the same error. I built it with the command:

utils/build-script --release-debuginfo --lldb --host-cc ~/Developer/llvm/build_9/bin/clang --host-cxx ~/Developer/llvm/build_9/bin/clang++

How can I fix this? Is there some something I should do in my OS to get the compiler to work?

That's strange, are you sure the particular LLVM/clang toolchain you're using to build the Swift compiler works well? What version of Swift are you building? If you run the Swift compiler with the -v or -Xcc -v flags, they might help you figure it out.

LLVM/clang toolchain you're using to build the Swift compiler works well?

Hmm I used a clang version I built as well (llvm 9), that might be it?

What version of Swift are you building?

I tried building swift/master

If you run the Swift compiler with the -v or -Xcc -v flags, they might help you figure it out.

I'll give that a try!

I got this output with the flags you mentioned:

Swift version 5.3-dev (LLVM 898aa0b6a4, Swift 1be86adbfc)
Target: x86_64-unknown-linux-gnu
/home/augusto/Developer/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bin/swift -frontend -c -primary-file teste.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -Xcc -v -module-name teste -o /tmp/teste-954cd3.o
clang version 10.0.0 (git@github.com:apple/llvm-project.git 898aa0b6a47a7441c34aaf880d59dc0260e13f0a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: 
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/augusto/Developer/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/lib/swift
 /usr/local/include
 /home/augusto/Developer/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/lib/swift/clang/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
/home/augusto/Developer/swift/build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bin/swift-autolink-extract /tmp/teste-954cd3.o -o /tmp/teste-cd43f6.autolink
<unknown>:0: error: unable to execute command: <unknown>

I thought I specified version 9 of clang, maybe that's what causing issues...

Yeah, that's not good that yet another version of clang is popping in there. :slightly_smiling_face: More importantly, most people use one of the build presets to get all the relevant tools and libraries installed in a toolchain directory, rather than trying to construct a build-script invocation with a bunch of flags themselves. Take a look at utils/build-presets.ini for some common presets that you can try, and what flags they bundle together, if you still want to try writing your own.

You were right, it was clang that was causing the issue! I got it working now.

Thank you very much! :grin: