Skip to content

cross-compilation.chapter.md: give examples of all depFooBar cases#166991

Merged
siraben merged 2 commits intomasterfrom
unknown repository
Apr 3, 2022
Merged

cross-compilation.chapter.md: give examples of all depFooBar cases#166991
siraben merged 2 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Apr 3, 2022

This commit describes the "->" notation for dependency types in
greater detail, and uses g++ to provide examples of all six cases
(although the host->target and target->target examples are a bit
artificial).

It also adds three more rows to the table for the "->*" dependency
types for non-compiler-like packages; these dependency types were
already present in the documentation but the "*" was not really
explained.

Lastly, this commit adds a hyperlink to the table from the place where
it is mentioned in the "specifying dependencies" chapter.

@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Apr 3, 2022
This commit describes the "->" notation for dependency types in
greater detail, and uses g++ to provide examples of all six cases
(although the host->target and target->target examples are a bit
artificial).

It also adds three more rows to the table for the "->*" dependency
types for non-compiler-like packages; these dependency types were
already present in the documentation but the "*" was not really
explained.

Lastly, this commit adds a hyperlink to the table from the place where
it is mentioned in the "specifying dependencies" chapter.
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Apr 3, 2022
@FRidh FRidh added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Apr 3, 2022
@FRidh FRidh requested a review from Ericson2314 April 3, 2022 07:05
Copy link
Copy Markdown
Member

@symphorien symphorien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for contributing to documentation!

@siraben
Copy link
Copy Markdown
Member

siraben commented Apr 3, 2022

@a-m-joseph thanks for the contribution! You might be interested in #127115 as well.

Co-authored-by: Ben Siraphob <bensiraphob@gmail.com>
@siraben siraben merged commit 1510ef3 into NixOS:master Apr 3, 2022
@ghost ghost deleted the doc-dependency-type-examples branch April 3, 2022 18:06
| target → * | target | (none) |
| target → target | target | target |

Let's use `g++` as an example to make this table clearer. `g++` is a C++ compiler written in C. Suppose we are building `g++` with a `(build, host, target)` platform triple of `(foo, bar, baz)`. This means we are using a `foo`-machine to build a copy of `g++` which will run on a `bar`-machine and emit binaries for the `baz`-machine.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say "was", because recent versions do use C++!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes. Yeah, it's been a long long long time since I worked on GCC. My first draft of this PR used gcj (the java frontend) as an example, and then I found out that it had been removed six years ago.

I'll find another example of a gcc frontend that isn't writing in its own language and submit a follow-up PR. I think the go frontend (gccgo) has this property. The Rust frontend is (AFAICT) out-of-tree. Let me know if you can think of a better frontend, especially if there is one that links a JIT to its output.


* Since `g++` is written in C, the `gcc` compiler used to compile it is a "build→ host" dependency of `g++` with a triple of `(foo, foo, bar)`. This compiler runs on the build platform and emits code for the host platform.

* `gcc` links against the build platform's `glibc` C library, which is a "build→ *" dependency with a triple of `(foo, foo, *)`. Since it is a library, not a compiler, it has no "target".
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could even go into more detail and say (?, foo, *) because the build platform doesn't matter. Afterwards, then say it is also foo by convention.

If you call https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/booter.nix manually, you can in fact do more complicated bootstraps with more than 3 total platforms.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could even go into more detail and say (?, foo, *) because the build platform doesn't matter. Afterwards, then say it is also foo by convention.

Thanks, I'll include that in the follow-up PR.

Also, would you be offended if I changed foo, bar, and baz to B, H, and T respectively? The example is already very complicated and I feel like having to remember that "foo is the build, bar is the host, and T is the target" without some kind of mnemonic is an extra burden on the reader.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you call https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/booter.nix manually, you can in fact do more complicated bootstraps with more than 3 total platforms.

Cool, I'm still working my way through the fine details of that and the {#ssec-stdenv-dependencies} chapter of the manual. If I come across any documentation quirks there I'll submit a PR, but if so it will certainly be much smaller than this one.

Copy link
Copy Markdown
Member

@Ericson2314 Ericson2314 Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, would you be offended if I changed foo, bar, and baz to B, H, and T respectively? The example is already very complicated and I feel like having to remember that "foo is the build, bar is the host, and T is the target" without some kind of mnemonic is an extra burden on the reader.

Mmm so my idea with foo bar and baz was that they are (stand-ins for) concrete platforms. Whereas "build", "host" and "target" I really want to make sure people understand are just local names from the perspective of a single derivation, relative to it.

A lot of build systems fall in the trap of their being a global "build", "host" and "target", and then mistakes of various sorts happen.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the slides linked below, I used some humorous concrete platforms: i386-linux, powerpc-illlumos, sparc-windows, mips-darwin, riscv-sel4.

Perhaps something like that might be better than foo, bar, baz while continuing to not imply there are is "global" build, host, and target?

@Ericson2314
Copy link
Copy Markdown
Member

Thank you for doing this! I like this going to detail on the reference. BTW from https://github.com/ClangBuiltLinux/llvm-distributors-conf-2021 @sternenseemann and I have some slides https://github.com/ClangBuiltLinux/llvm-distributors-conf-2021/blob/main/slides/llvm-toolchains-in-nixpkgs.pdf expanded from my nix con 2017 that could be useful if we want to add SVGs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: cross-compilation Building packages on a different platform than they will be used on 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants