Skip to content

lcalc: fix clang-19 build#370176

Merged
collares merged 1 commit intoNixOS:masterfrom
paparodeo:lcalc-clang-19
Jan 2, 2025
Merged

lcalc: fix clang-19 build#370176
collares merged 1 commit intoNixOS:masterfrom
paparodeo:lcalc-clang-19

Conversation

@paparodeo
Copy link
Contributor

@paparodeo paparodeo commented Jan 2, 2025

https://gitlab.com/sagemath/lcalc/-/issues/16

add -D_GLIBCXX_COMPLEX -D_LIBCPP_COMPLEX -D_LIBCPP___FWD_COMPLEX_H to prevent including system and use the vendored copy.

https://hydra.nixos.org/build/282766851

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jan 2, 2025
@collares
Copy link
Member

collares commented Jan 2, 2025

Scarily, the code includes a full copy of complex.h from GCC 3.5! Do you happen to know if the code was actually using Lcomplex.h's definition of complex instead of the standard library's? I think it's worth checking, but if you don't have the time I can do it later.

@paparodeo
Copy link
Contributor Author

paparodeo commented Jan 2, 2025

I believe the vendored one is getting used as just including <complex> results in a bunch of errors

invalid operands to binary expression ('int' and 'Complex' (aka 'complex<double>')

with clang-19.

probably be better to fix the errors and use <complex> tho.

@collares
Copy link
Member

collares commented Jan 2, 2025

Thanks for checking! While I agree that using <complex> would be better as a final goal, I think it would be better to have upstream review of such a big change. I will try to think if there are even less invasive alternatives than your solution.

@paparodeo
Copy link
Contributor Author

paparodeo commented Jan 2, 2025

Thanks for checking! While I agree that using <complex> would be better as a final goal, I think it would be better to have upstream review of such a big change. I will try to think if there are even less invasive alternatives than your solution.

for clang-19 I initially just added a compiler flag -D_LIBCPP___FWD_COMPLEX_H which prevented the conflicting include file from getting parsed.

https://github.com/llvm/llvm-project/blob/main/libcxx/include/__fwd/complex.h

@collares
Copy link
Member

collares commented Jan 2, 2025

Hmm, that's a good point! Does it build with -D_GLIBCXX_COMPLEX -D_LIBCPP_COMPLEX (the first one is the libstdc++ equivalent)? If it does, I think we can keep it as a workaround for now while your upstream fix is reviewed (in which case, please add a comment above the workaround linking to your upstream MR, as you currently do with the patch).

@paparodeo
Copy link
Contributor Author

this builds for both platforms:

  env.NIX_CFLAGS_COMPILE = toString [
    "-D_GLIBCXX_COMPLEX"
    "-D_LIBCPP_COMPLEX"
    "-D_LIBCPP___FWD_COMPLEX_H"
  ];

I could make the conditional on stdenv.cc.libcxx != null or just leave them both. I don't think it will hurt to just leave them all in.

https://gitlab.com/sagemath/lcalc/-/issues/16

add -D_GLIBCXX_COMPLEX -D_LIBCPP_COMPLEX -D_LIBCPP___FWD_COMPLEX_H to
prevent including system <complex> and use the vendored copy.
@collares
Copy link
Member

collares commented Jan 2, 2025

I don't think it needs to be set conditionally, leaving all is fine. Do you know if the third one is needed, given the second?

Thanks so much for the workaround and for the upstream MR!

@paparodeo
Copy link
Contributor Author

I don't think it needs to be set conditionally, leaving all is fine. Do you know if the third one is needed, given the second?

Thanks so much for the workaround and for the upstream MR!

-D_LIBCPP___FWD_COMPLEX_H is required to build. -D_LIBCPP_COMPLEX could be dropped but seems fine to leave it in for safety.

@paparodeo paparodeo marked this pull request as ready for review January 2, 2025 12:38
@collares
Copy link
Member

collares commented Jan 2, 2025

-D_LIBCPP___FWD_COMPLEX_H is required to build.

I don't really mind having the third line, but just to be sure I know how to test Clang fixes: I replaced stdenv by clangStdenv in the derivation and it built with just "-D_GLIBCXX_COMPLEX -D_LIBCPP_COMPLEX" on Linux. Should I be testing differently?

@paparodeo
Copy link
Contributor Author

-D_LIBCPP___FWD_COMPLEX_H is required to build.

I don't really mind having the third line, but just to be sure I know how to test Clang fixes: I replaced stdenv by clangStdenv in the derivation and it built with just "-D_GLIBCXX_COMPLEX -D_LIBCPP_COMPLEX" on Linux. Should I be testing differently?

that just pulls in libstd++ you need libc++ which is libcxxStdenv

@collares
Copy link
Member

collares commented Jan 2, 2025

Got it, thanks!

@collares collares merged commit 719b1e4 into NixOS:master Jan 2, 2025
@paparodeo paparodeo deleted the lcalc-clang-19 branch January 2, 2025 12:51
"-D_LIBCPP_COMPLEX"
"-D_LIBCPP___FWD_COMPLEX_H"
];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so python3Packages.sagelib includes Lcomplex.h and fails to compile. so this isn't going to work for building sage with libcxx-19.

the original PR that used https://gitlab.com/sagemath/lcalc/-/issues/16 works tho.

(FWIW I've gotten sage to build on darwin now after a few more changes and some fixes to gcc darwin build)

Copy link
Contributor Author

@paparodeo paparodeo Jan 3, 2025

Choose a reason for hiding this comment

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

so can also just replace Lcomplex.h with <complex> and add operators with complex<double> and an int. nothing seems to be doing anything with a complex and a long or long long (I added operators with no definitions and didn't get a link errors.

inline Complex operator* (const Complex &l, int r) { return l  * double(r); }
inline Complex operator/ (const Complex &l, int r) { return l  / double(r); }
inline Complex operator+ (const Complex &l, int r) { return l  + double(r); }
inline Complex operator- (const Complex &l, int r) { return l  - double(r); }
inline bool    operator==(const Complex &l, int r) { return l == double(r); }
inline bool    operator!=(const Complex &l, int r) { return l != double(r); }

inline Complex operator*(int l, const Complex &r) { return r * l; }
inline Complex operator+(int l, const Complex &r) { return r + l; }

inline Complex operator/(int l, const Complex &r) { return double(l) / r; }
inline Complex operator-(int l, const Complex &r) { return double(l) - r; }

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's go with 166b3cd then. Sorry for not testing Sage!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it only breaks with clang / libc++ so gcc / libstd++ is fine. will setup a PR in a little bit.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, good to know. If it's clang only I will wait for your PR instead of reverting now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants