Skip to content

language.c: bang into shape - #102

Draft
zimbatm wants to merge 2 commits into
mainfrom
language-c-wip
Draft

language.c: bang into shape#102
zimbatm wants to merge 2 commits into
mainfrom
language-c-wip

Conversation

@zimbatm

Copy link
Copy Markdown
Member

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.

Comment threadextra/language/c.nix
name = "LD_LIBRARY_PATH";
prefix = "$DEVSHELL_DIR/lib";
name = "LIBRARY_PATH";
value = lib.concatStringsSep ":" (map (x: "${lib.getLib x}/lib") cfg.libraries);

Copy link
Copy Markdown
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.

@Mic92Mic92Mar 7, 2021

Copy link
Copy Markdown
Member

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";

Comment threadextra/language/c.nix
description = ''
Which C compiler to use.

For gcc, use pkgs.gcc-unwrapped.

Copy link
Copy Markdown
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.

Comment threadextra/language/c.nix
prefix = "$DEVSHELL_DIR/include";
})
++ (lib.optional cfg.pkg-config {
name = "PKG_CONFIG_PATH";

@Mic92Mic92Mar 7, 2021

Copy link
Copy Markdown
Member

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

Comment threadextra/language/c.nix
default = [ ];
description = "Use this when another language dependens on a dynamic library";
example = lib.literalExample ''
[ pkgs.glibc ]

Copy link
Copy Markdown
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
Copy Markdown
Member

@zimbatm

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
Member

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 freeto 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

@zimbatm@Mic92