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

language.c: bang into shape #102

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

language.c: bang into shape #102

wants to merge 2 commits into from

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Mar 6, 2021

A few learning:

ld uses LIBRARY_PATH, not LD_LIBRARY_PATH to find object files. Link to the
libraries directly to minimize rebuilds.

pkgs.gcc doesn't expose the gcov binary. pkgs.gcc is heavily tweaked to
work with the nixpkgs stdenv so use pkgs.gcc-unwrapped instead.

Made pkg-config optional, it's not used all the time.

name = "LD_LIBRARY_PATH";
prefix = "$DEVSHELL_DIR/lib";
name = "LIBRARY_PATH";
value = lib.concatStringsSep ":" (map (x: "${lib.getLib x}/lib") cfg.libraries);
Copy link
Member

Choose a reason for hiding this comment

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

value = "$DEVSHELL_DIR/lib";

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.

Copy link
Member

@Mic92 Mic92 Mar 7, 2021

Choose a reason for hiding this comment

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

How about setting NIX_LDFLAGS="-rpath $DEVSHELL_DIR/lib";

description = ''
Which C compiler to use.

For gcc, use pkgs.gcc-unwrapped.
Copy link
Member

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.

prefix = "$DEVSHELL_DIR/include";
})
++ (lib.optional cfg.pkg-config {
name = "PKG_CONFIG_PATH";
Copy link
Member

@Mic92 Mic92 Mar 7, 2021

Choose a reason for hiding this comment

The 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 CC = /usr/bin/gcc

libraries = mkOption {
type = types.listOf strOrPackage;
default = [ ];
description = "Use this when another language dependens on a dynamic library";
example = lib.literalExample ''
[ pkgs.glibc ]
Copy link
Member

Choose a reason for hiding this comment

The 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?

@Mic92
Copy link
Member

Mic92 commented Mar 11, 2021

For testing: https://github.com/Mic92/build-system-koans

@zimbatm
Copy link
Member Author

zimbatm commented Dec 13, 2021

I'm a bit overwhelmed by the complexity of this work and don't think I can do a good job at it. If somebody wants to take over, I would be happy.

@Mic92
Copy link
Member

Mic92 commented Dec 13, 2021

I'm a bit overwhelmed by the complexity of this work and don't think I can do a good job at it. If somebody wants to take over, I would be happy.

Maybe we can talk about this next year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants