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

Command line option --with-gcc is ignored #4073

Closed
OlivierSohn opened this issue Jun 10, 2018 · 16 comments
Closed

Command line option --with-gcc is ignored #4073

OlivierSohn opened this issue Jun 10, 2018 · 16 comments

Comments

@OlivierSohn
Copy link

OlivierSohn commented Jun 10, 2018

The context is that I need to use a gcc supporting the C++17 standard.

When passing --with-gcc=c:\msys64\MINGW32\bin\gcc to stack invocation, I was expecting that ghc would use the given gcc to build my code, but it ignores it.

Steps to reproduce

Using a projectWithCSources.cabal (I use this one) where during c preprocessor phase, we print the compiler version like so:

#define COMPILER_VERSION0(compiler,a,b,c) "compiled with " compiler " " #a "." #b "." #c
#define COMPILER_VERSION(compiler,a,b,c) COMPILER_VERSION0(compiler,a,b,c)

#ifdef __GNUC__
#  pragma message (COMPILER_VERSION("gcc",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__))
#endif

Given a more recent gcc (located at <path-to-new-gcc>) than the one used when doing stack exec -- gcc --version

  1. Run command stack exec -- gcc --version

This gives us version1

  1. Run command stack --with-gcc=<path-to-new-gcc> build

this gives us version2, printed during the c-preprocessor phase

Note that this is a simplified version of this Appveyor script

The bug happens for ghc8.2.2 (resolver lts-11.9) and ghc8.4.3 (resolver nightly-2018-06-07)

Expected

version2 > version1

Actual

version2 == version1

The verbose output is available here (line 2030 is the command to build the project, line 2046 shows the gcc version used by ghc to compile the c sources)

Stack version

$ stack --version
Version 1.7.1, Git revision 681c800873816c022739ca7ed14755e85a579565 (5807 commits) i386 hpack-0.28.2

Method of installation

- curl -sS -ostack.zip -L --insecure https://get.haskellstack.org/stable/windows-i386.zip
- 7z x stack.zip stack.exe
@OlivierSohn
Copy link
Author

Hey there, it would be real nice to have a feedback on this!

Even a "it's too low priority for use to investigate, sorry" would be nice :)

@OlivierSohn OlivierSohn changed the title Command line option --with-gcc is ignored Command line option --with-gcc is ignored Jun 12, 2018
@dbaynard
Copy link
Contributor

Hello, this must have fallen through the cracks. I wonder if this is related to haskell/cabal#4439. @nh2 might have some idea?

@dbaynard
Copy link
Contributor

It may also relate to #3902

@OlivierSohn
Copy link
Author

@dbaynard yes it looks like these issues are related

@nh2
Copy link
Collaborator

nh2 commented Jun 22, 2018

@OlivierSohn Can you try my solution from this reddit thread which is to add to your .cabal file:

ghc-options:         -optc-std=c++14
cc-options:          -std=c++14

The bug mentioned in #4073 (comment) is certainly relevant but if you are lucky it only affects a stage in cabal where it doesn't matter what the -std flag is, and the above might be enough.

Please report back if that helps!

@OlivierSohn
Copy link
Author

@nh2 note that I use c++ 17, not C++ 14, and I already pass

cc-options: -std=c++17

Why do you think that passing

ghc-options: -std=c++17 (or 14)

would make the right gcc (i.e the one I specify using the commandline option) be selected ?

@OlivierSohn
Copy link
Author

(continued) @nh2 in your context are you using --with-gcc at all ? if not, I think your proposal is not relevant.

@nh2
Copy link
Collaborator

nh2 commented Jun 22, 2018

@OlivierSohn Ah, sorry, I misunderstood, you are right. If the compiler that's slected can't do c++17 at all, then what I said won't help.

A couple questions:

Using a projectWithCSources.cabal (I use this one)

This link 404s for me, could you make a stable link to it?

You're giving a Windows path in --with-gcc=c:\msys64\MINGW32\bin\gcc; is this issue also reproducible on Linux? That might make it much easier for people to work on it.

If yes, could you provide full instructions to trigger it?

A temporary workaround might be to simply inplace-replace the GCC it's currently picking by a newer version.

@OlivierSohn
Copy link
Author

@nh2 Ok, and I tried the suggestion, to confirm it doesn't solve the issue.

I updated the link to the .cabal (the branch was deleted in-between)

I don't know if the issue is reproducible on linux : I didn't need --with-gcc on linux (I managed to upgrade the compilers in a way that doesn't require to use --with-gcc)

What do you mean by "inplace-replace the GCC it's currently picking" exactly?

@nh2
Copy link
Collaborator

nh2 commented Jun 22, 2018

What do you mean by "inplace-replace the GCC it's currently picking" exactly?

@OlivierSohn That you would replace whatever gcc cabal/ghc are picking now by a newer version on your file system.

@OlivierSohn
Copy link
Author

@nh2 ok, maybe that could work, but I prefer waiting for this bug to be fixed. Thanks for the suggestion.

cdepillabout added a commit to cdepillabout/hasktorch that referenced this issue Jun 13, 2020
This commit is a first attempt at getting the stack.yaml actually
working and building successfully with nix.

Currently this is hard-coded to use the non-cuda CPU build, but this
should be changed in the future.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch get-stack.yaml-working
# Changes to be committed:
#	new file:   nix/stack-shell.nix
#	modified:   stack.yaml
#
# Untracked files:
#	shell-hoogle.nix
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/nix/stack-shell.nix b/nix/stack-shell.nix
new file mode 100644
index 00000000..72fe20d5
--- /dev/null
+++ b/nix/stack-shell.nix
@@ -0,0 +1,56 @@
+
+let
+  sources = import ./sources.nix;
+
+  haskellNix = import sources.haskell-nix {
+    sourcesOverride = sources;
+  };
+
+  haskellNixOverlays = pkgsNew: pkgsOld: {
+    haskell-nix = pkgsOld.haskell-nix // { hackageSrc = sources.hackage-nix; };
+  };
+
+  nixpkgsSrc = haskellNix.sources.nixpkgs-2003;
+
+  libtorchSrc = pkgs:
+    pkgs.callPackage "${sources.pytorch-world}/libtorch/release.nix" { };
+
+  libtorchOverlayCpu = pkgsNew: pkgsOld:
+    let
+      libtorch = (libtorchSrc pkgsOld).libtorch_cpu;
+    in {
+      c10 = libtorch;
+      torch = libtorch;
+      torch_cpu = libtorch;
+    };
+
+  pkgs =
+    import
+      nixpkgsSrc
+      (haskellNix.nixpkgsArgs // {
+        overlays = haskellNix.overlays ++ [ haskellNixOverlays libtorchOverlayCpu ];
+      });
+in
+
+{ withHoogle ? false
+}@Args:
+
+pkgs.haskell.lib.buildStackProject {
+  name = "stack-build-hasktorch";
+  ghc = pkgs.haskell.compiler.ghc883;
+  extraArgs = [
+    "--extra-include-dirs=${pkgs.torch}/include/torch/csrc/api/include"
+  ];
+  buildInputs = with pkgs; [
+    # caffe2
+    # eigen
+    # git
+    # glog
+    # google-gflags
+    # libffi
+    # protobuf
+    torch
+    zlib
+  ];
+  inherit withHoogle;
+}
diff --git a/stack.yaml b/stack.yaml
index 62fc111b..23b680d1 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -8,14 +8,6 @@ packages:
 - examples
 - experimental

-extra-include-dirs:
-  - deps/libtorch/include/torch/csrc/api/include
-  - deps/libtorch/include
-
-extra-lib-dirs:
-  - deps/libtorch/lib
-  - deps/mklml/lib
-
 # see commercialhaskell/stack#4073
 # with-gcc: /usr/local/bin/gcc-7

@@ -34,6 +26,6 @@ extra-deps:
 - streaming-attoparsec-1.0.0.1@sha256:fe9b878072423d3f075534fe8af24722d9ded1a1129e9a6ed5b71c4a29681b39,1146
 - streaming-cassava-0.1.0.1@sha256:2d1dfeb09af62009e88311fe92f44d06dafb5cdd38879b437ea6adb3bc40acfe,1739

-
 nix:
-  packages: [zlib.dev, zlib.out]
+  enable: true
+  shell-file: nix/stack-shell.nix
@Mikolaj
Copy link

Mikolaj commented Dec 22, 2021

Hi! Heads up about haskell/cabal#7874, which is a PR solving this ticket that @jberryman has kindly just rebased and we are desperate to merge before it bitrots.

We need to add a small test for that or at least test the branch on the examples you have. Please help!

[edit: was wrong cabal ticket number]

@Mikolaj
Copy link

Mikolaj commented Jan 11, 2022

Please kindly also have a look (and review) at #7900, which provides a test and discusses its result. Last chance to provide feedback before we merge. Thank you!

@OlivierSohn
Copy link
Author

@Mikolaj Hello, I am afraid I won't have the time to test the fix. If someone has time to do it, they can follow the steps in the description to verify that the issue is fixed.

@Mikolaj
Copy link

Mikolaj commented Jan 12, 2022

@OlivierSohn: understood. Thank you for reporting. Should we close this issue (and re-open if anything is amiss)?

@jberryman: thank you for haskell/cabal#7900, which is now merged, which ends the saga! Please, everybody, test the fix and report if anything is still missing. The feature should be released in cabal 3.8 (no release date planned yet).

@mpilgrem
Copy link
Member

I am closing this issue given the passage of time and the comment above about the resolution of the upstream issue.

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

No branches or pull requests

5 participants