News for hackers. Stuff that matters.
Re:Mk: A Successor to Make [pdf] by vmsp on Sunday July 16, 2023 @07:00AM (#36745572)
For those curious, Mk is available in Plan 9 from User Space

https://9fans.github.io/plan9port/

Re:Mk: A Successor to Make [pdf] by jacobvosmaer on Sunday July 16, 2023 @09:57AM (#36747054)
I tried plan9port's mk for a moment out of curiosity. I quickly ran into an annoying usability problem: it compares file mtimes with second accuracy.

https://github.com/9fans/plan9port/blob/cc4571fec67407652b03...

With sub-second build times for individual targets, this causes mk to needlessly recompile files because the target may have the same mtime as the prerequisites.

Re:Mk: A Successor to Make [pdf] by jmrjmr on Monday July 17, 2023 @04:50AM (#36755660)
That looks like it would be relatively straightforward to fix. Attempted nerd snipe?
Re:Mk: A Successor to Make [pdf] by jylam on Sunday July 16, 2023 @07:09AM (#36745632)
Funny how building tools are reinvented again and again, with all the same culprits. I'm a programmer since the mid-90's, there are countless tools to do the job, and they are just as cumbersome and complicated the more they evolve. I'm personally sticking to the good old configure/make for my own C projects, but I understand that's a matter of taste and habits. I've written some CMakeLists.txt from time to time, anything you want to do requires some digging in some sort of stackoverflow answers (thanks to those who answer) for "not so common but yet I need them" weird features.

I'm not criticizing anyone or any tool, just that we can't seem to find some good way to tool the compilation of both trivial and very complex projects, without taking an hour or two off.

I also understand that I do not want to work on such an endeavor, that seems boring AF and kudos for people that like that. You are not enough it seem :)

Re:Mk: A Successor to Make [pdf] by mananaysiempre on Sunday July 16, 2023 @07:53AM (#36745957)
Plan 9’s mk isn’t really a radical departure from Make, it is more of an adaptation of it to the (decidedly non-POSIX) Plan 9 shell, rc, with modest extensions. One design mistake in make that mk fixes is variables in recipes: those are now passed as environment variables, with no prior substitution, so no more writing $$$$ to get the current PID in a recipe (and it’s written $pid in rc anyway).

Unfortunately, mk inherits from rc the principle of having the list of strings as the fundamental datatype (also used by Jam). That works, but it’s noticeably more limiting than Tcl’s route of having everything be strings but with robust quoting and unquoting procedures for putting lists inside them—at which point Tcl starts to look like a Lisp-2 with a slight propensity for stringiness and a mildly unusual syntax.

Re:Mk: A Successor to Make [pdf] by mort96 on Sunday July 16, 2023 @08:39AM (#36746312)
Ohhh, passing variables as env vars is a good idea. That means things like "$foo" in a recipe just works even if 'foo' contains quotes.
Re:Mk: A Successor to Make [pdf] by throwawaaarrgh on Sunday July 16, 2023 @01:06PM (#36749220)
Actually it doesn't really solve the $$foo problem. If your make target has an inline shell script with a variable reference, is it referring to a make variable or a shell variable? Is it set in make? If not, what will make do with that variable reference in the inline shell - nothing? Make it an empty string? Keep the literal '$foo' string? And what if both make and inline script have the variable set but they need to be different?
Re:Mk: A Successor to Make [pdf] by mananaysiempre on Sunday July 16, 2023 @02:17PM (#36749972)
It does solve the $$foo problem in that mk just doesn’t do any variable substitution, at all. For each recipe, it adds the values of mk variables it has computed to its initial environment, then execs a shell, passing it the entire recipe verbatim.
Re:Mk: A Successor to Make [pdf] by rollcat on Sunday July 16, 2023 @07:18PM (#36752387)
> at which point Tcl starts to look like a Lisp-2 with a slight propensity for stringiness and a mildly unusual syntax.

I always saw Tcl as a bastard child of Lisp and sh. It's beautiful in its own quirky way.

Re:Mk: A Successor to Make [pdf] by nsajko on Sunday July 16, 2023 @09:21PM (#36753062)
Both Mk and Rc started out with Research Unix, some years before Plan 9.
Re:Mk: A Successor to Make [pdf] by smorrow on Wednesday July 19, 2023 @07:06AM (#36784531)
I've been seeing people, never ones who were actually there, make this claim in the last five to ten years. Rc was on tenth edition Unix. I've seen no evidence that it originated on Unix. The manual calls it the Plan 9 shell.
Re:Mk: A Successor to Make [pdf] by nsajko on Friday July 21, 2023 @11:45AM (#36815180)
I was going by the fact that tenth edition Unix was released on 1989, while Plan 9 was first released in 1992: https://en.wikipedia.org/wiki/Research_Unix

Pehaps this is misleading.

Re:Mk: A Successor to Make [pdf] by smorrow on Tuesday July 25, 2023 @11:47AM (#36864080)
Some clues:

The mk paper (and Unix man page) doesn't mention rc.

Plan 9 existed since the mid-80s.

This sentence in the Unix rc(1) sure makes it seem like rc was Plan 9-first:

Environment entries for variables are kludgy for UNIX compatibility.

Re:Mk: A Successor to Make [pdf] by smorrow on Saturday July 29, 2023 @04:05AM (#36917999)
The first paragraph of https://archive.org/details/rc-shell/

So rc was made for Plan 9. The examples in that paper are definitely on tenth edition Unix, I think this would be because

A fairly complete version of Plan 9 was built in 1987 and 1988, but development was abandoned. In May of 1989 work was begun on a completely new system

from https://doc.cat-v.org/plan_9/1st_edition/designing_plan_9 (1990).

Re:Mk: A Successor to Make [pdf] by TheLocehiliosan on Sunday July 16, 2023 @08:54AM (#36746466)
An alternative I quite like is “just”.

https://github.com/casey/just

Re:Mk: A Successor to Make [pdf] by DanHulton on Sunday July 16, 2023 @10:50AM (#36747631)
Was going to mention this. I've recently started converting my Makefiles to justfiles, and it's just nicer. Even being able to inline scripts to clean up "loose" files is a big win.
Re:Mk: A Successor to Make [pdf] by packetlost on Sunday July 16, 2023 @11:36AM (#36748190)
Just isn't really a replacement for make outside of the "simple command/task runner". Make is really a lot more powerful and has things like files system driven dependency handling.
Re:Mk: A Successor to Make [pdf] by zokier on Sunday July 16, 2023 @02:53PM (#36750271)
Of course that is the whole point of just, to be simpler and more focused tool because a task runner is what people commonly want and the bloat/complexity of make is more of hindrance. This is clearly mentioned in the readme too

> just has a ton of useful features, and many improvements over make:

> • just is a command runner, not a build system, so it avoids much of make's complexity and idiosyncrasies. No need for .PHONY recipes!

Re:Mk: A Successor to Make [pdf] by dimator on Sunday July 16, 2023 @02:41PM (#36750163)
I've been using 'just' for running a set of commands that I can't be bothered to remember.

It makes it easier to come back to a project after a few weeks, because you don't have to remember the N commands you were using to iterate/test, you only have to remember the 'just' invocation.

For some reason, it feels like a more natural fit for this than 'make'

Re:Mk: A Successor to Make [pdf] by raddan on Sunday July 16, 2023 @10:02AM (#36747114)
Here’s another make alternative. You do not need to specify dependencies at all.

https://www.usenix.org/conference/atc22/presentation/curtsin...

(full disclosure: I am one of the authors)

Re:Mk: A Successor to Make [pdf] by imran-iq on Sunday July 16, 2023 @12:02PM (#36748473)
There's also tup: https://gittup.org/tup/
Re:Mk: A Successor to Make [pdf] by nmz on Sunday July 16, 2023 @01:17PM (#36749336)
Woah, what was that about erasing files and use a vcs just in case? yeah no thanks, I build first (test) and then commit, not the other way around.
Re:Mk: A Successor to Make [pdf] by vimax on Sunday July 16, 2023 @03:12PM (#36750447)
I agree with you about that statement, but why don’t you commit to an unstable branch? Why risk losing something or pass up having a better development history?
Re:Mk: A Successor to Make [pdf] by nemetroid on Sunday July 16, 2023 @04:10PM (#36750955)
The way the warning is worded suggests that any invocation of tup has a risk of deleting your files, implying that to be entirely safe you should commit before every single build, which would be ludicrous.
Re:Mk: A Successor to Make [pdf] by rollcat on Sunday July 16, 2023 @07:26PM (#36752439)
git commit --amend, rebase with squash/fixup, etc. I easily make a dozen commits per hour, it's like undo on steroids and you can always clean it up later.
Re:Mk: A Successor to Make [pdf] by nmz on Sunday July 16, 2023 @04:43PM (#36751217)
Because I like having an unstable branch that still builds. not an unstable branch that doesn't build and is full of tryouts and just unhelpful commits on the log.
Re:Mk: A Successor to Make [pdf] by ripe on Sunday July 16, 2023 @10:35AM (#36747475)
I like simple Makefiles. Keeping them POSIX compliant makes them portable, including on cygwin-type environments on Windows.

I used this tutorial:

https://nullprogram.com/blog/2017/08/20/

Re:Mk: A Successor to Make [pdf] by throwawaaarrgh on Sunday July 16, 2023 @01:09PM (#36749257)
It seems to me that all build systems are just DAGs with syntactic sugar and functions. You could do away with build systems entirely if there were some Unix commands that manage an arbitrary DAG, where the state is kept out of band (in a file, in a database, etc) so you can operate on the DAG from any process. That way the shell (or any program, really) becomes your build system and you can compose any kind of logic that requires walking or manipulating a tree of dependencies. This could apply to anything where you need to execute arbitrary jobs with a DAG, not just builds.
Re:Mk: A Successor to Make [pdf] by chriswarbo on Sunday July 16, 2023 @01:53PM (#36749746)
Nix represents its builds in a way that's similar: each "derivation" is a text file like /nix/store/XXXXXXX-foo.drv, where XXXXXX is a hash of that file's content. This way each file can reference any others by their path, and there can never be cycles (unless we brute-forced SHA256 to find a pair of files which contain each others hashes!). This uses of hashing requires the files to be immutable, but that's good for caching/validation/reuse/etc. anyway.

Note that Nix doesn't use a shell to execute things, it uses raw `exec` calls (each .drv file specifies the absolute path to an executable, a list of argument strings, and a set of environment variable strings). Though in practice, most .drv files specify a bash executable ;)

Re:Mk: A Successor to Make [pdf] by klysm on Sunday July 16, 2023 @02:44PM (#36750197)
I didn’t realize that content addressing girls like that prevented circular deps by construction (with very high probability). That’s a super cool property to get as a bonus
Re:Mk: A Successor to Make [pdf] by ur-whale on Sunday July 16, 2023 @01:57PM (#36749782)
> It seems to me that all build systems are just DAGs

Yeah, well, it's a little bit more than that.

Two things come to mind that don't neatly fit the DAG mental framework:

    - dynamically generated dependencies (e.g. when you compile a C++ file only to discover that it #includes something and therefore has a dependency on that thing, and therefore the DAG has to be updated on the fly). Creating them by hand is horribly tedious, and/or borderline impossible (#includes that #include other #include ad infinitum)

    - reproducible builds, where a build system is capable of rebuilding a binary from scratch down to having not a single different bit in the final output assuming the leaves of the DAG haven't changed. A desirable feature that is darn near impossible to do unless you pair the DAG with something else.
Re:Mk: A Successor to Make [pdf] by mike_hock on Sunday July 16, 2023 @02:07PM (#36749885)
- detection/management of external dependencies

- defining different build types (debug/release)

- optionally building and running tests

- incremental builds (detecting what has changed)

That doesn't necessarily run counter to the concept of a DAG, but the organizational structures to manage this is what makes the build system. Topologically sorting the dependencies isn't the hard part. That's why make isn't a build system. It is the generic DAG runner, but that's not sufficient.

Re:Mk: A Successor to Make [pdf] by mananaysiempre on Sunday July 16, 2023 @03:32PM (#36750602)
> It seems to me that all build systems are just DAGs with syntactic sugar and functions.

True in the broadest sense, but there are choices to be done regarding the possibility of discovering what the graph is or has become on the fly and the propagation directions. See “Build systems à la carte”[1,2] for a systematic exploration.

(See also a neighbouring comment[3] re how the discourse structure[4] of the build script might be important in a way orthogonal to these execution-engine issue. The boundary between the build system and the build tool can be drawn in very different places here.)

[1] https://dx.doi.org/10.1145/3236774

[2] https://youtu.be/BQVT6wiwCxM

[3] https://news.ycombinator.com/item?id=36749885

[4] https://brenocon.com/blog/2009/09/dont-mawk-awk-the-fastest-...

Re:Mk: A Successor to Make [pdf] by wahern on Sunday July 16, 2023 @04:08PM (#36750920)
> if there were some Unix commands that manage an arbitrary DAG

There is: tsort. It's a POSIX utility, even, not just a GNU or BSD utility.

Re:Mk: A Successor to Make [pdf] by nsajko on Sunday July 16, 2023 @09:24PM (#36753074)
It's from Seventh Edition Unix, actually. So a decade before Mk, for example.
Re:Mk: A Successor to Make [pdf] by throwawaaarrgh on Monday July 17, 2023 @10:09AM (#36758450)
Wow, that's awesome!
Re:Mk: A Successor to Make [pdf] by duped on Sunday July 16, 2023 @05:35PM (#36751619)
Programs are just DAGS with syntactic sugar
Re:Mk: A Successor to Make [pdf] by kdmccormick on Sunday July 16, 2023 @05:45PM (#36751706)
Not sure I follow.

  0001 GOTO 0002
  0002 GOTO 0001
How would that be a DAG?
Re:Mk: A Successor to Make [pdf] by Zambyte on Sunday July 16, 2023 @07:11PM (#36752354)
I think they meant more the syntactic representation, rather than the control flow. If you rewrite the program using s-expressions, the DAG becomes a little more clear

    (begin
        (0001 GOTO 0002)
        (0002 GOTO 0001))
The DAG has two branches, each with three leaves. There are no cycles in the syntax, even if there is in the execution.
Re:Mk: A Successor to Make [pdf] by kdmccormick on Monday July 17, 2023 @09:58PM (#36766817)
Sure, but I would imagine that GGP would have said been more specific and said "tree" instead of "DAG" if they were talking about the AST.
Re:Mk: A Successor to Make [pdf] by duped on Sunday July 16, 2023 @07:20PM (#36752397)
More of just a graph like:

V: (0001, 0002) E: ([0001, 0002], [0002, 0001])

But really I was just being sarcastic. Builds are "just" DAGs with syntactic sugar just like programs are "just" DAGs with syntactic sugar. That's one possible abstraction and one that is inherently lossy, because what "sugar" is available is the actual meat that makes one build system useful and another terrible. And one actually awful limitation is acylicity, since any build system will eventually deal with it (and outright forbidding of it makes your build system incapable of representing certain builds, just like acyclicity fundamentally limits a program's execution)

You can represent pretty much any data model as a graph, that doesn't really address the problem.

Re:Mk: A Successor to Make [pdf] by kdmccormick on Monday July 17, 2023 @09:56PM (#36766811)
Right, I understand the graph metaphor, my objection is that programs in a turing complete language do not seem like they can exhaustively modeled as DAGs. Graphs, sure; but AFAICT DAGs fail due to the halting problem (in some abstract sense).

A build system modelling itself as a DAG, on the other hand, is very consciously taking on acyclicity as a feature.

I am curious what builds would need to be cyclic. Artifact A is built from B and C, where C is built from D and A? Does that happen in any well-designed build?

Re:Mk: A Successor to Make [pdf] by duped on Wednesday July 19, 2023 @09:51AM (#36786337)
A syntax tree is also a DAG.

> I am curious what builds would need to be cyclic.

Compilers, interpreters, kernels, and the things that depend on them. So lots.

> Does that happen in any well-designed build?

Whether or not it's 'well designed' is irrelevant, the question is 'does it need to be possible' because even if it's rare it's still present in a lot of foundational software, notably GCC.

Re:Mk: A Successor to Make [pdf] by AceJohnny2 on Sunday July 16, 2023 @07:16PM (#36752379)
There are a few more components. In particular, how the build system decides what needs to be done, and how tasks are ordered, are significant.

For an excellent synthesis of what Makes a build system, I can't recommend the 2018 paper "Build Systems A La Carte" enough:

https://www.microsoft.com/en-us/research/uploads/prod/2018/0...

By Andrey Mokhov, Neil Mitchell (now working at Meta on the Buck2 build system) and Simon Peyton Jones (one of the founders of Haskell)

Re:Mk: A Successor to Make [pdf] by AceJohnny2 on Monday July 17, 2023 @05:49PM (#36764546)
oh, and Andrey Mokhov since works at Jane Street on the build system Dune:

https://blogs.ncl.ac.uk/andreymokhov/moving-to-jane-street/

Re:Mk: A Successor to Make [pdf] by smorrow on Wednesday July 19, 2023 @07:26AM (#36784680)
Re:Mk: A Successor to Make [pdf] by adamgordonbell on Sunday July 16, 2023 @02:54PM (#36750276)
Here is my silly alternative. You just write bash, with preconditions and annotations to describe what can run in parallel.

https://github.com/adamgordonbell/job-runner/blob/main/tests...

Re:Mk: A Successor to Make [pdf] by gigatexal on Sunday July 16, 2023 @03:49PM (#36750759)
I like the simplified syntax of this mk, anyone know why it didn't catch on?
Re:Mk: A Successor to Make [pdf] by nsajko on Sunday July 16, 2023 @09:28PM (#36753096)
Research Unix wasn't easily available, AFAIK Bell Labs were trying to sell it as a product, so it lost to more free alternatives. It only got open-sourced recently AFAIK, years after being abandoned.
Re:Mk: A Successor to Make [pdf] by ggm on Sunday July 16, 2023 @09:42PM (#36753169)
Also, and with no implied criticism, the people involved set the bar higher to capture their mindshare. I know, because I failed the bar (amicably I might add)

Which meant they cared less about "winning" in some non-valuable game of "whose code is winning" and had less irritating conversations, "no thats not how it works, no I don't have to explain this idea called the plumber to you, yes rc is very different to other shells no thats not how it works"... ad infinitum.

Re:Mk: A Successor to Make [pdf] by vladxyz on Monday July 17, 2023 @12:05AM (#36753949)
To add to the pile of task runners here, I made this one: https://code.ofvlad.xyz/v/lightning-runner . I like it, and currently use it for all personal projects. Mainly, posting here for some feedback!
Re:Mk: A Successor to Make [pdf] by whiteinge on Monday July 17, 2023 @02:17AM (#36754736)
I own a couple books on Make and it's a great tool, but I learned how to use Mk by just reading the manpage. It's a huge improvement and simplification at the same time.

There's a solid, stand-alone implementation of mk in golang. No plan9 environment needed.

https://github.com/henesy/mk