News for hackers. Stuff that matters.
Re:SQLite is easy to compile by thomascgalvin on Monday October 28, 2019 @12:36PM (#21378519)
> All the code is in one file (sqlite.c), and there are no weird dependencies! It’s amazing.

This is because the author of SQLite publishes it this way as a convenience to integrators; the actual day-to-day coding is not done in a single C file.

In fact, the README[1] calls out twelve "key files", and explicitly warns that SQLite "will not be the easiest library in the world to hack."

https://sqlite.org/src/doc/trunk/README.md

Re:SQLite is easy to compile by mhd on Monday October 28, 2019 @02:21PM (#21379917)
There's quite a bit of build management going on with sqlite. Apart from that script, Dr. Hipp wrote his own source code management system[1] to fit his need and if I'm not mistaken they don't write headers by hand[2].

[1]: https://www.fossil-scm.org/

[2]: https://www.hwaci.com/sw/mkhdr/

Re:SQLite is easy to compile by thomascgalvin on Monday October 28, 2019 @03:01PM (#21380320)
Fossil intrigues me every time I see it mentioned. I've never found a sue for it, but it's so neat that I want to find a use for it.
Re:SQLite is easy to compile by j88439h84 on Monday October 28, 2019 @05:31PM (#21381926)
The main features could be emulated with a small wrapper around git, no?
Re:SQLite is easy to compile by phamilton on Monday October 28, 2019 @06:09PM (#21382256)
A full web ui with issue tracker is a bit more than a small wrapper.
Re:SQLite is easy to compile by zabzonk on Monday October 28, 2019 @12:49PM (#21378677)
> the actual day-to-day coding is not done in a single C file.

That's true - but in order for it be able to be reduced to a single C file, a lot of thought had to go into the process.

Re:SQLite is easy to compile by jstimpfle on Monday October 28, 2019 @02:21PM (#21379912)
You just don't depend on weird libraries that mess up your preprocessor state. Then you make sure that even your static (file local) variables have unique names. And then you concatenate all the header and source files.

It shouldn't be very hard, but most projects fail already at the dependency stage.

Re:SQLite is easy to compile by bch on Monday October 28, 2019 @02:51PM (#21380229)
And also as a gift to optimizing compilers, from discussions I’ve had w him. The idea is that a single compilation unit (the “amalgamation”) is easy for the compiler to reason about.
Re:SQLite is easy to compile by cozzyd on Monday October 28, 2019 @02:59PM (#21380298)
Sure, but now we have -flto, somewhat negating that advantage?
Re:SQLite is easy to compile by bch on Monday October 28, 2019 @03:07PM (#21380384)
Perhaps. Assumes all compilers support it, but otherwise, a testable case.
Re:SQLite is easy to compile by Glacia on Tuesday October 29, 2019 @07:06AM (#21385786)
Except LTO is slow to compile and SCU is fast.
Re:SQLite is easy to compile by akhilcacharya on Monday October 28, 2019 @02:55PM (#21380258)
I'm not a C/C++ developer, but why can't more C/C++ projects be distributed as source amalgamations? What prevents this from happening?

As in, source to source amalgamation rather than a more complicated build system to generate a binary.

Re:SQLite is easy to compile by paulddraper on Monday October 28, 2019 @05:10PM (#21381712)
> why can't more C/C++ projects be distributed as source amalgamations

* Build time and memory increases.

* Debugger locations are less clear. MSVC debugging doesn't even work past 64KB lines.

* You still need to link it anyway when using as a library.

* Linker optimization has improved (especially clang).

* It's more difficult to modify.

SQLite has some decent reasons for it especially historically; I'm not sure those reasons are as strong for other projects.

For applications, distributing binaries is even more convenient than source code (assuming they exist for your platform).

And for libraries, "header-only" can be more of a convenience than "single-file".

Re:SQLite is easy to compile by akhilcacharya on Monday October 28, 2019 @05:21PM (#21381824)
Interesting, thank you!

Are there any ways of doing that sort of distribution header-only then, rather than single file?

Re:SQLite is easy to compile by wkz on Monday October 28, 2019 @04:52PM (#21381528)
For one, I think this would be cumbersome from a debugging perspective. All of the address-to-source-mappings in your DWARF section would point to things like "lib.c:237652" instead of "lib-module.c:347".

It also means that you're effectively linking all you dependencies statically. In some cases this can be a plus, in some cases a minus. I think having the choice is important though.

I imagine there are lots of other parts of the toolchain that would have to be updated to support this workflow. Seems like a lot of hassle for something that, though at times complicated, mostly works.

Re:SQLite is easy to compile by Mikhail_Edoshin on Tuesday October 29, 2019 @04:34AM (#21385121)
There's the #line directive that can keep the original file names and line numbers.
Re:SQLite is easy to compile by jandrese on Monday October 28, 2019 @03:30PM (#21380627)
For larger projects there is a danger of blowing out the memory on older machines when you combine everything into one monstrous C/CPP file.

It's already impossible to compile Firefox on a machine with 1GB of RAM because some of the files are just too big. Even with swapping enabled the build process crapped out for me last time I tried it. While 1GB machines are pretty rare these days outside of SBCs, you could easily blow out a 4GB machine if you tried to compile the whole damn thing at once, and 4GB machines are still commonly found.

Re:SQLite is easy to compile by planteen on Monday October 28, 2019 @04:21PM (#21381197)
Is that much of a problem though? For SBCs like the Raspberry Pi you can do builds on the SBC itself. While this is neat, it is far from optimal because builds are very slow. It's much more typical for embedded systems to do you build on a host PC with a cross-compiler.
Re:SQLite is easy to compile by jandrese on Monday October 28, 2019 @04:45PM (#21381451)
Sometimes getting that cross compiler environment set up properly, especially with all of the dependencies and build tools, is more hassle than just letting the build run overnight on the SBC itself. Especially when it has a configure script that wants to check on various properties of the target architecture as part of the build.
Re:SQLite is easy to compile by BubRoss on Monday October 28, 2019 @12:45PM (#21378616)
I'm not sure anyone thought that it was made that way, this is very explicitly for distribution and it works very well.
Re:SQLite is easy to compile by eximius on Monday October 28, 2019 @02:39PM (#21380106)
In a vacuum, reading that statement, that was the assumption I made. Certainly strikes me as a bit odd, but then, SQLite is a bit of an odd project. And sometimes odd projects do things differently in a way that works out well because they have the discipline to pull it off.

But it does make much more sense that it is worked on in pieces and then put back together.