Skip to content
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

rustPlatform.defaultCrateOverrides: adding native support for PyO3 and mlua-sys #381161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pkgs/build-support/rust/default-crate-overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
, libtool
, linux-pam
, llvmPackages
, luajit
, luau
, lua5_1
, lua5_2
, lua5_3
, lua5_4
, nettle
, openssl
, pango
Expand Down Expand Up @@ -229,6 +235,32 @@ in
buildInputs = [ webkitgtk_4_1 ];
};

mlua-sys = attrs:
let hasLuajit = builtins.elem "luajit" attrs.features;
hasLuau = builtins.elem "luau" attrs.features;
hasLua51 = builtins.elem "lua51" attrs.features;
hasLua52 = builtins.elem "lua52" attrs.features;
hasLua53 = builtins.elem "lua53" attrs.features;
hasLua54 = builtins.elem "lua54" attrs.features;
in
{
# `crate2nix` may enable the "vendored" feature if not run
# with the proper Lua packages in the path. This is especially
# likely to happen on the first run, when we haven't generated
# the Cargo.nix to import these in the scope. Therefore, we
# choose to disable the feature by default, as it can still be
# overriden by consumers of these overrides.
features = lib.lists.filter (k: k != "vendored") attrs.features;
nativeBuildInputs = [ pkg-config ];
buildInputs =
lib.optional hasLuajit luajit ++
lib.optional hasLuau luau ++
lib.optional hasLua51 lua5_1 ++
lib.optional hasLua52 lua5_2 ++
lib.optional hasLua53 lua5_3 ++
lib.optional hasLua54 lua5_4;
};

nettle-sys = attrs: {
nativeBuildInputs = [ pkg-config ];
buildInputs = [ nettle clang ];
Expand Down Expand Up @@ -270,6 +302,11 @@ in
nativeBuildInputs = [ protobuf ];
};

pyo3 = attrs: {
nativeBuildInputs = [ pkg-config ];
extraLinkFlags = [ "-L${python3}/lib" "-l${python3.libPrefix}" ];
Copy link
Member

Choose a reason for hiding this comment

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

It needs pkg-config, but then also needs you to manually specify the link flags rather than getting them from pkg-config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because different versions and feature sets complain about different things. This does work though. PyO3 is a bit special, I'd like to also add a variant of buildRustCrate specifically to produce Python wheel from dependents of PyO3.

Copy link
Member

Choose a reason for hiding this comment

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

If it changed in some version, might be clearer to handle the before/after separately.

};

rdkafka-sys = attr: {
nativeBuildInputs = [ pkg-config ];
buildInputs = [ rdkafka ];
Expand Down