-
Notifications
You must be signed in to change notification settings - Fork 91
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
rust: add hasLibraries and hasIncludes #119
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,10 +1,26 @@ | ||||||
{ lib, config, pkgs, ... }: | ||||||
let | ||||||
cfg = config.language.rust; | ||||||
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; | ||||||
|
||||||
hasLibraries = lib.length cfg.libraries > 0; | ||||||
hasIncludes = lib.length cfg.includes > 0; | ||||||
in | ||||||
with lib; | ||||||
{ | ||||||
options.language.rust = { | ||||||
libraries = mkOption { | ||||||
type = types.listOf strOrPackage; | ||||||
default = [ ]; | ||||||
description = "Use this when another language dependens on a dynamic library"; | ||||||
}; | ||||||
|
||||||
includes = mkOption { | ||||||
type = types.listOf strOrPackage; | ||||||
default = [ ]; | ||||||
description = "Rust dependencies from nixpkgs"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}; | ||||||
|
||||||
packageSet = mkOption { | ||||||
# FIXME: how to make the selection possible in TOML? | ||||||
type = types.attrs; | ||||||
|
@@ -30,8 +46,32 @@ with lib; | |||||
# Used by tools like rust-analyzer | ||||||
name = "RUST_SRC_PATH"; | ||||||
value = toString cfg.packageSet.rustPlatform.rustLibSrc; | ||||||
}]; | ||||||
}] | ||||||
++ | ||||||
(lib.optionals hasLibraries [ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually want to make the separation into libraries/includes? Would it not be easier to have just one package options that adds both? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since includes were for C and specifically C_INCLUDE_PATH, I don't see how it's necessary to port that to the rust options. |
||||||
{ | ||||||
name = "LD_LIBRARY_PATH"; | ||||||
prefix = "$DEVSHELL_DIR/lib"; | ||||||
} | ||||||
]) | ||||||
++ lib.optionals hasIncludes [ | ||||||
{ | ||||||
name = "LD_INCLUDE_PATH"; | ||||||
bbigras marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
prefix = "$DEVSHELL_DIR/include"; | ||||||
} | ||||||
{ | ||||||
name = "PKG_CONFIG_PATH"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't libraries also depend on PKG_CONFIG_PATH some time? |
||||||
prefix = "$DEVSHELL_DIR/lib/pkgconfig"; | ||||||
} | ||||||
]; | ||||||
|
||||||
devshell.packages = map (tool: cfg.packageSet.${tool}) cfg.tools; | ||||||
devshell.packages = | ||||||
(lib.optionals hasLibraries (map lib.getLib cfg.libraries)) | ||||||
++ | ||||||
# Assume we want pkg-config, because it's good | ||||||
(lib.optionals hasIncludes ([ pkgs.pkg-config ] ++ (map lib.getDev cfg.includes))) | ||||||
++ | ||||||
(map (tool: cfg.packageSet.${tool}) cfg.tools) | ||||||
; | ||||||
}; | ||||||
} |
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.
Typo, but I still don't understand what this means.
What would be another language? Can you make an example.
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 think "another language" isn't really necessary (and a holdover from the equivalent C option), this should really be for any non-crate library dependencies (i.e. anything that would need pkg-config).