TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ninja: A simple way to do builds

122 pointsby Bella-Xiangover 4 years ago

16 comments

chrismorganover 4 years ago
For comparison, here’s a makefile for the trivial example (though you’ll have to fix the indentation):<p><pre><code> all: $(patsubst ${things_to_convert},%.svg,%.pdf) %.pdf: %.svg inkscape $&lt; --export-text-to-path --export-pdf=$@ </code></pre> ${things_to_convert} is left undefined, as in the source article. It might be something like $(wildcard [STAR].svg) or $(shell find src -name &#x27;[STAR].svg&#x27;). [Turn each [STAR] into *; HN formatting idiosyncrasies are in play.]<p>I like makefiles in substantial part because there’s a very high probability of Make already being installed. I’m comfortable enough with them that I didn’t need to look anything up to write any of what I wrote above. It’s a bit of a pity about the sigils; though would people really find $first_prerequisite and $target better than $&lt; and $@? No idea. Ninja uses $in and $out, but it’s simpler in a way that lets it reasonably get away with that. Make, on the other hand, is complex in a way that is pretty powerful if you know what you’re doing, but generally more manual (e.g. Ninja looks like it tracks dependencies roughly automatically, whereas dependencies are manual in Make, as many have found to their sorrow) and it makes it fairly easy to shoot yourself in the foot if you do the wrong thing, which is easy to do if you’re not expert, which not many are.
评论 #24909477 未加载
评论 #24910774 未加载
评论 #24910010 未加载
nsmover 4 years ago
The ninja author has a (relatively) recent blog post about design decisions and lessons learned:<p>* The success and failure of ninja <a href="http:&#x2F;&#x2F;neugierig.org&#x2F;software&#x2F;blog&#x2F;2020&#x2F;05&#x2F;ninja.html" rel="nofollow">http:&#x2F;&#x2F;neugierig.org&#x2F;software&#x2F;blog&#x2F;2020&#x2F;05&#x2F;ninja.html</a>
评论 #24911712 未加载
gravypodover 4 years ago
I wish more people were taking a look at Bazel, and the Bazel-family, of build systems. I&#x27;ve looked at Meson&#x2F;Ninja&#x2F;Make and it works but it&#x27;s truely very complicated and very difficult to get hermetic &amp; reproducible builds from these systems. In my opinion, Bazel will be the future once the currently ongoing external dependency management design doc is implemented. I&#x27;ve migrated quite a few builds to bazel at work and I&#x27;ve seen a dramatic reduction in compile times - not even from compiling source code! Doing things like packaging zips, generating code, generating docs (swagger), etc all adds up in CI time and automating, and caching, absolutely all of it is astonishingly useful.
评论 #24911849 未加载
评论 #24913311 未加载
评论 #24911159 未加载
评论 #24911454 未加载
评论 #24911066 未加载
评论 #24914102 未加载
评论 #24913689 未加载
antoinealbover 4 years ago
If you don&#x27;t know it, CMake can use ninja instead of make for compilation so instead of &quot;mkdir build &amp;&amp; cd build &amp;&amp; cmake .. &amp;&amp; make&quot; you can run &quot;mkdir build &amp;&amp; cd build &amp;&amp; cmake -GNinja &amp;&amp; ninja&quot;.<p>It feels faster on my side projects (haven&#x27;t benchmarked it really), but most importantly, when running a parallel build it does not interleave the output of the different steps, making it much easier to read warnings and errors.
评论 #24909962 未加载
评论 #24910151 未加载
评论 #24910082 未加载
评论 #24909099 未加载
评论 #24925349 未加载
ncmncmover 4 years ago
It is a mistake to imagine Ninja just replacing Make.<p>Ninja is the &quot;rebuild-it&quot; part of Make, made really, really fast and clean, a joy to use. The Ninja config file is not something you write or, even, look at. It&#x27;s an intermediate file generated by your build-dependency tool such as CMake, Meson, or even (gods forbid) SCons.<p>Those are smarter than Make in various ways, but are really not very good at all at actually running builds, so you get them to just make a ninja file, instead, and then get the hell out of your way.<p>This is good because you don&#x27;t want to analyze the dependency tree on every build when you haven&#x27;t changed any of it. So, you just run ninja in your edit-build-test loop.<p>Ninja is smart enough to rerun Meson or whatever if you <i>do</i> change the build configuration. It understands build directories separate from sources, and ccache compiler wrappers to cache build targets, things you don&#x27;t want your build-configuation infrastructure to bother with.<p>Besides being fantastic to use, ninja is worthy of study as a truly superb example of a program that does one thing really, really well, and integrates cleanly with other programs that do other stuff: build analyzers on one side, compilers on the other. It demonstrates a design discipline that we would all be better off if everyone were to follow it.
评论 #24914187 未加载
griveover 4 years ago
I&#x27;ve only worked on one project (<a href="https:&#x2F;&#x2F;www.dpdk.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.dpdk.org&#x2F;</a>) using meson+ninja. Overall it seems to be an improvement, barring the make idiosyncrasies that needs to be forgotten.<p>That being said, <i>if</i> the project had used make properly from the beginning (i.e. avoid recursive calls), it would not have been plagued by such latency for incremental builds. But then, make should not have made it so easy to fall for such mistake.<p>I&#x27;m still not a fan of having two steps (meson + ninja), but I guess it&#x27;s always needed for multi-platform projects.<p>I&#x27;m wondering if there is a make rewrite project that tried to make the recursive make antipattern less painful? Maybe trying to recognize sub-calls and avoid creating a sub-process? I guess it would take creating a small internal shell with only make as a builtin command...
评论 #24909674 未加载
desineover 4 years ago
I&#x27;ve been compiling some libraries and projects on my raspberry pi, and I&#x27;ve been having to invoke meson and ninja quite a bit. If nothing else, they&#x27;ve been getting it right on the first try more often than the cmake &amp;&amp; make projects. That may be biased though, with newer&#x2F;more active projects using newer build systems supporting newer hardware.<p>Anyways, it&#x27;s been enough that I&#x27;m looking into it, but still working (hacking? copy&#x2F;pasting?) in make
inglorover 4 years ago
I don&#x27;t know I did a few things in Chromium and admittedly it&#x27;s a really big project BUT ninja and autoninja get really cryptic and complex pretty fast.<p>To be fair it&#x27;s better than make or the older gyp setup BUT for non trivial workloads ninja is pretty fast but leaves a lot to be desired in terms of DX.
评论 #24909686 未加载
pierrebaiover 4 years ago
Of note, meson is mentioned to optionally use ninja as a build system, but the same is true of CMake.<p>On thing to note is that the simplicity of ninja means that a lot of things need to be repeated. For a project I&#x27;m working on, the input build.ninja file is 142MB. Just generating that files takes a few minutes.<p>I think an improvement would be to be able to split it in sub-trees and have ninja produce a &quot;mark&quot; file that has a date that represent when the last time the sub-tree was touched and to not even read any sub-tree files, even the sub-ninja file if an entire sub-tree date is older than the mark file.
评论 #24916084 未加载
runiqover 4 years ago
The one thing that&#x27;s keeping me from using Ninja for the use-case Julia is describing is lacking support for reading environment variables in build.ninja. I understand why that&#x27;s not part of Ninja, but it does stunt its usefulness.
评论 #24910002 未加载
cb321over 4 years ago
She missed the step where you just say [ &quot;$dst&quot; -nt &quot;$i&quot; ] || svg2pdf &quot;$i&quot; &quot;$dst&quot; in her for-loop. That is about as much extra typing&#x2F;text as her comment and makes that build script about as fast as alternatives for that simple scenario. { This is not to say there isn&#x27;t maybe more motivation for grander designs..or various failure modes..just that she missed a step. :-) }
hinkleyover 4 years ago
&gt; for filename in things_to_convert:<p>Undeclared variables and random indentation levels. Is it safe to assume these examples are abridged? Or is it a case of magic?
评论 #24909292 未加载
junonover 4 years ago
Meson still doesn&#x27;t get submodules right. So far, CMake gets the closest. The Meson developer is a bit of a jerk about this subject, too - he has a very dogmatic view of how a project should be structured and has designed meson around that.<p>For example, you cannot have nested subprojects with Meson.
chovyfuover 4 years ago
That&#x27;s just BASH with extra steps.
评论 #24908920 未加载
评论 #24908862 未加载
评论 #24905576 未加载
ur-whaleover 4 years ago
The article keeps on saying that make is &quot;complicated&quot; ... make is an abomination in many, many ways, but claiming that Makefile language is complicated is just sheer ignorance.
评论 #24913561 未加载
ribaldevover 4 years ago
We use task management apps to save us time and give more visibility over the work. However, the app can become so complicated to use by itself, that we may choose to go for very basic note-taking apps to avoid the complexity.<p>I was looking for a minimal, simple and user-friendly app for daily task management, so I developed Renoj.<p>Fast to-do task management in Desktop for ultimate productivity.<p>Website: <a href="https:&#x2F;&#x2F;ribal.dev&#x2F;renoj" rel="nofollow">https:&#x2F;&#x2F;ribal.dev&#x2F;renoj</a>