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

Broken Clang on MacOS (nix-darwin) #951

Closed
alecandido opened this issue Jan 23, 2024 · 11 comments
Closed

Broken Clang on MacOS (nix-darwin) #951

alecandido opened this issue Jan 23, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@alecandido
Copy link

Describe the bug
Trying to compile a simple hello.cpp program is failing, because of c++abi not found.

To reproduce
I'm actually using a flake

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    systems.url = "github:nix-systems/default";
    devenv.url = "github:cachix/devenv";
  };

  outputs = {
    self,
    nixpkgs,
    devenv,
    systems,
    ...
  } @ inputs: let
    forEachSystem = nixpkgs.lib.genAttrs (import systems);
  in {
    devShells =
      forEachSystem
      (system: let
        pkgs = nixpkgs.legacyPackages.${system};
      in {
        # ----------------------------------------------------
        default = pkgs.mkShell {
          buildInputs = with pkgs; [clang];
        };
        # ----------------------------------------------------
        # default = devenv.lib.mkShell {
        #   inherit inputs pkgs;
        #
        #   modules = [
        #     {
        #       packages = with pkgs; [clang];
        #     }
        #   ];
        # };
        # ----------------------------------------------------
        # default = devenv.lib.mkShell {
        #   inherit inputs pkgs;
        #
        #   modules = [
        #     {
        #       languages.cplusplus.enable = true;
        #     }
        #   ];
        # };
        # ----------------------------------------------------
      });
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-substituters = "https://devenv.cachix.org";
  };
}

I defined three shells (uncommenting each one of the subdivided sections), and run

nix develop --impure
clang++ hello.cpp

with the customary hello.cpp:

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}

In the first case (no devenv) everything works smoothly (even without --impure, of course), and running ./a.out I obtain the usual Hello, World! output.
In the other two cases, I'm unable to compile. The result is:

❯ nix develop --impure
(devenv) bash-5.2$ clang++ hello.cpp
ld: warning: directory not found for option '-L/nix/store/qfdj687ndydj5mfd60y5ip43d1jgqb6j-devenv-profile/lib'
ld: library not found for -lc++abi
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

(the hash may change, I tried with multiple versions of nixpkgs, including nixos-23.11 and `nixpkgs-23.11-darwin, on top of the two options in the flake)

I'm not sure what is actually happening...

Version

I attach the whole flake.lock.

flake.zip

I'm on MacOS, with ARM architecture (Apple Silicon).

❯ sw_vers
ProductName:            macOS
ProductVersion:         14.2.1
BuildVersion:           23C71
@alecandido alecandido added the bug Something isn't working label Jan 23, 2024
@domenkozar
Copy link
Member

I think we have a clang option somewhere that you have to enable, but I might be wrong.

@alecandido
Copy link
Author

alecandido commented Jan 30, 2024

The only references to Clang in the devenv.nix docs are:

**` clang-format `**
Format your code using ` clang-format `.
**` clang-tidy `**
Static analyzer for C++ code.

EDIT: and those are actually the only references to Clang in the whole repo, other than the explicit dependency on pkgs.clang in the c and cplusplus language presets
https://github.com/search?q=repo%3Acachix%2Fdevenv+clang&type=code

@DaniruKun
Copy link

My workaround was adding pkgs.libcxxabi

@mrfelton
Copy link

mrfelton commented Feb 2, 2024

I've found that clang breaks in this way if I have multiple languages enabled.

For example if I have the following then I get problems with clang when using golang.

languages.ruby.enable = true;
languages.rust.enable = true;
languages.go.enable = true;

But with only go enabled as below, it works just fine.

languages.go.enable = true;

@hurricanehrndz
Copy link

I can confirm the issue.

@hurricanehrndz
Copy link

My workaround was adding pkgs.libcxxabi

This didn't work for me

@domenkozar
Copy link
Member

Does it also happen on #745

@domenkozar
Copy link
Member

Could someone try with 1.0.1 that was released yesterday?

@alecandido
Copy link
Author

I am going to test it immediately

@alecandido
Copy link
Author

All the examples above are now working, so I'd close the issue if there are no further comments

(to be completely honest: I didn't test with 1.0.1, but I left the flake locking the dependency on its own, and it happened to be fixed to rev 984707a, that is 3 commits ahead...)

@domenkozar
Copy link
Member

Closing, please reopen if still broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants