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

mkDerivation: use __structuredAttrs to pass makeFlags/cmakeFlags/... as array of strings #58

Open
milahu opened this issue May 27, 2024 · 0 comments

Comments

@milahu
Copy link
Owner

milahu commented May 27, 2024

NixOS#114044

https://discourse.nixos.org/t/cmakeflags-and-spaces-in-option-values/20170

cmakeFlags are currently passed to CMake as follows:

pkgs/development/tools/build-managers/cmake/setup-hook.sh

cmake ${cmakeDir:-.} $cmakeFlags "${cmakeFlagsArray[@]}"

so Bash will tokenize them on spaces and there is no way to prevent it.

The only alternative is adding the flag to cmakeFlagsArray in a Bash code. For example:

preConfigure = ''
  cmakeFlagsArray+=(
    "-DSOMELIB_CXX_FLAGS=\"-O3 -march=native\""
  )
'';

In the future, this might be possible from Nix through __structuredAttrs.

NixOS#175649

workaround

{
  makeFlags = [
    # FIXME stdenv.mkDerivation fails to preserve the space after "-fcommon"
    #''EXTRA_CFLAGS="-fcommon -DTARGET_FORMAT=${targetFormat}"''
    # no. in bash, the backslash is a separate char of the string
    #"EXTRA_CFLAGS=-fcommon\\ -DTARGET_FORMAT=${targetFormat}"
  ]; 

  preConfigure = ''
    # no. gcc: error: unrecognized command-line option '-fcommon -DTARGET_FORMAT=AVM_LE'
    #makeFlagsArray+=('EXTRA_CFLAGS="-fcommon -DTARGET_FORMAT=${targetFormat}"')
    makeFlagsArray+=('EXTRA_CFLAGS=-fcommon -DTARGET_FORMAT=${targetFormat}')
  '';
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

No branches or pull requests

1 participant