New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protobuf3: support cross compilation #48450
Conversation
Provide a native c compiler, which, and protoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle, LGTM. Not sure I like this externalProtoc
though — it took reading almost the whole diff for me to realise it was a boolean and not a reference to some external protoc. While this could be fixed by just changing the name to e.g. useExternalProtoc
(which indicates the booleanness better) I think a better approach might be to just use (stdenv.hostPlatform != stdenv.buildPlatform)
in generic-v3.nix (maybe with a let binding if you need to use it in multiple locations) directly. This results in much less cruft in all-packages.nix
(in fact allowing it to remain completely as is) and avoids the need to thread the variables through in protobuf/3.*.nix
.
|
||
callPackage ./generic-v3.nix { | ||
version = "3.1.0"; | ||
sha256 = "0qlvpsmqgh9nw0k4zrxlxf75pafi3p0ahz99v6761b903y8qyv4i"; | ||
externalProtoc = externalProtoc; | ||
buildProtobuf = buildProtobuf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use inherit externalProtoc buildProtobuf;
instead here.
@GrahamcOfBorg build pkgsCross.aarch64-multiplatform.protobuf3_6 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I need to be able to select the specific matching version ( |
@@ -31,10 +30,10 @@ stdenv.mkDerivation rec { | |||
''; | |||
|
|||
nativeBuildInputs = [ autoreconfHook buildPackages.which buildPackages.stdenv.cc ] | |||
++ stdenv.lib.optional useExternalProtoc [ buildProtobuf ]; | |||
++ (if buildProtobuf == null then [] else [ buildProtobuf ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildInputs
entries which are null will just be ignored, so you don't need to put this condition here.
, version, sha256 | ||
, ... | ||
}: | ||
|
||
stdenv.mkDerivation rec { | ||
let | ||
mkProtobufDerivation = buildProtobuf: stdenv: stdenv.mkDerivation rec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need a function here? Can't you just do let buildProtobuf = if stdenv.hostPlatform != stdenv.buildPlatform then buildPackages.protobuf else null; in stdenv.mkDerivation rec {…}
? I'm not sure about the exact recursion implications of that, but I think it should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't do this because the host and build protobuf versions must match. buildPackages.protobuf
is defined in all-packages.nix
as protobuf = protobuf3_6;
. So using buildPackages.protobuf
, when I try to cross-compile e.g. protobuf3_1
I see that it wants to build protobuf3_6
for the build version:
these derivations will be built:
/nix/store/cszcilxncv2hhxb5n5j41y1bxbxbwcb6-protobuf-3.6.1.drv
/nix/store/lp6xfnwlli29r24vb9pmrgmnd84zbd7m-protobuf-3.1.0-aarch64-unknown-linux-gnu.drv
The protobuf docs say they want the versions to match in the cross compile: https://github.com/protocolbuffers/protobuf/blob/master/src/README.md:
Either way, you must make sure that the protoc executable you use has the same version as the protobuf source code you are trying to use it with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
@GrahamcOfBorg build pkgsCross.aarch64-multiplatform.protobuf3_6 |
Failure on x86_64-darwin (full log) Attempted: pkgsCross.aarch64-multiplatform.protobuf3_6 Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: pkgsCross.aarch64-multiplatform.protobuf3_6 Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: pkgsCross.aarch64-multiplatform.protobuf3_6 Partial log (click to expand)
|
Whoops, merged this too hastily. As lots of things depend on protobuf, this is a mass-rebuild and should be based on the staging branch. |
Pushed to staging as 7414ec1. |
Provide a native c compiler, which, and protoc
Motivation for this change
Support cross compilation for protobuf3. For this to work we need to:
which
is on the PATH (for the configure script to find the native c compiler)protoc
binary as a configure flag (used to generate code at build-time)Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)