-
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
language.c: bang into shape #102
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 |
---|---|---|
|
@@ -9,52 +9,67 @@ in | |
with lib; | ||
{ | ||
options.language.c = { | ||
compiler = mkOption { | ||
type = strOrPackage; | ||
default = pkgs.clang; | ||
defaultText = "pkgs.clang"; | ||
description = '' | ||
Which C compiler to use. | ||
|
||
For gcc, use pkgs.gcc-unwrapped. | ||
''; | ||
}; | ||
|
||
linker = mkOption { | ||
type = strOrPackage; | ||
default = pkgs.binutils; | ||
defaultText = "pkgs.binutils"; | ||
description = "Which linker package to use"; | ||
}; | ||
|
||
libraries = mkOption { | ||
type = types.listOf strOrPackage; | ||
default = [ ]; | ||
description = "Use this when another language dependens on a dynamic library"; | ||
example = lib.literalExample '' | ||
[ pkgs.glibc ] | ||
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. Does glibc in libraries have any effect when a wrapped clang is used? |
||
''; | ||
}; | ||
|
||
pkg-config = mkEnableOption "use pkg-config"; | ||
|
||
includes = mkOption { | ||
type = types.listOf strOrPackage; | ||
default = [ ]; | ||
description = "C dependencies from nixpkgs"; | ||
}; | ||
|
||
compiler = mkOption { | ||
type = strOrPackage; | ||
default = pkgs.clang; | ||
defaultText = "pkgs.clang"; | ||
description = "Which C compiler to use"; | ||
}; | ||
}; | ||
|
||
config = { | ||
devshell.packages = | ||
[ cfg.compiler ] | ||
[ cfg.compiler cfg.linker ] | ||
++ | ||
(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))) | ||
(lib.optional cfg.pkg-config pkgs.pkg-config) | ||
; | ||
|
||
env = | ||
(lib.optionals hasLibraries [ | ||
{ | ||
name = "LD_LIBRARY_PATH"; | ||
prefix = "$DEVSHELL_DIR/lib"; | ||
name = "LIBRARY_PATH"; | ||
value = lib.concatStringsSep ":" (map (x: "${lib.getLib x}/lib") cfg.libraries); | ||
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.
does not work here? Also how would programs build like this find their libraries at runtime? This is especially a problem when you run outside of devshell. 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. How about setting |
||
} | ||
]) | ||
++ lib.optionals hasIncludes [ | ||
{ | ||
name = "LD_INCLUDE_PATH"; | ||
prefix = "$DEVSHELL_DIR/include"; | ||
} | ||
{ | ||
name = "PKG_CONFIG_PATH"; | ||
prefix = "$DEVSHELL_DIR/lib/pkgconfig"; | ||
} | ||
]; | ||
++ (lib.optional hasIncludes { | ||
name = "LD_INCLUDE_PATH"; | ||
prefix = "$DEVSHELL_DIR/include"; | ||
}) | ||
++ (lib.optional cfg.pkg-config { | ||
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. You also want to set CC/CXX/LD. Otherwise many buildsystems will default to something like |
||
value = lib.concatStringsSep ":" (map (x: "${lib.getLib x}/lib/pkgconfig") cfg.libraries); | ||
}) | ||
; | ||
}; | ||
} |
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.
Having a wrapped and a unwrapped version will behave quite differently here. i.e. the wrapped version of clang will set hardening flags that the unwrapped version of gcc won't. This might be surprising for users.