1. 14
  1.  

  2. 9

    To paraphrase a recent comment: we’re supposed to know what chibicc and cproc are?

    Luckily I can use Google and it turns out they’re both small C compilers.

    1. 8

      I’m looking forward to getting Zig to bootstrap with both cproc and chibicc. Of course this will only work when creating a build that does not have LLVM extensions enabled, since LLVM is written in C++.

      The process will be: zig0 source code written in C. zig0 inputs .zig code and compiles it into .c code. This will build the entire stage1 zig compiler into a .c file, which will then get compiled and linked with the same thing that compiled and linked zig0 in the first place. Next this new binary, zig1, will recompile itself, outputting a binary instead of .c code. The resulting binary is the zig compiler, fully bootstrapped. At this point, recompiling itself again should produce an identical output.

      1. 4

        Thanks for spending the time to make this an option.

      2. 2

        Nice, I think there was a patch for chibicc that added inline asm support. The last bits are compiling a libc and kernel for either chibicc or cproc and we can have a full linux userland + kernel built without a C compiler implemented in C++.

        1. 3

          I mean, it sounds like there’s good reasons that GCC and LLVM are written in C++…

          1. 5

            Maybe it’s the same “arbitrary constraints are fun” mindset that drives a lot of stuff aroun here?

            Me, I’m working on an implementation of Doom in BCPL whose source code will not contain the letter “e”. Because reasons!

            1. 5

              To quote the cproc author:

              However, if you are asking why I’d want to be able to build the oasis userspace with a compiler written in 7000 lines of C as opposed to one written in 5 million lines of C++, then I don’t really know how to answer.

              Anyway…

              Do you regularly compile gcc or clang from source? Do you know how annoying it is to require more than 16GB of ram and 30 minutes a pop? Do you know how unnecessarily hard this makes bootstrapping a package tree/distro/architecture?

              It’s not arbitrary to want to reduce overall complexity of your computer system - especially removing projects too large for small teams to realistically maintain.

              If you can maintain your system with a small team you can side step huge amounts of bureaucracy and tailor the solutions to your own problems. I don’t think its arbitrary to want to avoid depending on projects out of your control.

              1. 3

                Those are valid points.

                However, I’d still worry whether these little compilers generate high quality code. Can they compete with all the work that goes into optimization in Clang/GCC? Saving time and/or space in the built product is worth some pain while building.

                Oh, and do they offer sanitizers? IMHO developing in C/++ these days without using address and UB sanitizers is foolhardy. Those things save my bacon so often. (Of course that only applies to the dev & test cycle, not deployment.)

                1. 4

                  However, I’d still worry whether these little compilers generate high quality code.

                  cproc generates code about on par with -O2 and sometimes -O1.

                  Oh, and do they offer sanitizers? IMHO developing in C/++ these days without using address and UB sanitizers is foolhardy.

                  I use these tools too, it would be nice to add, and there is no evidence that it would be impossible to do so in a reasonable amount of effort and code. As an example, tcc already comes with a bounds checking flag https://bellard.org/tcc/tcc-doc.html#Bounds.

                  I would also say I think having simpler options doesn’t mean I advocate throwing away the advanced options when they make sense.

              2. 1

                thats awesome!

              3. 1

                such as? The only reason I can think of is because if you already use C++, it makes sense to have your C++ compiler in C++, and a C compiler (with a lot of baggage) sort of falls out by accident when you do this.

                To quote the cproc author:

                However, if you are asking why I’d want to be able to build the oasis userspace with a compiler written in 7000 lines of C as opposed to one written in 5 million lines of C++, then I don’t really know how to answer.

              4. 3

                we can have a full linux userland + kernel built without a C compiler implemented in C++

                Already done, with tcc. And doesn’t cproc still lack its own preprocessor?

                1. 2

                  I don’t think tcc can build the linux kernel anymore.

                  1. 2

                    Indeed, due to missing asm goto. Clang had the same problem until a year or two ago.