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

HaskellC2Hs fails with clang: error: no input files #1486

Closed
aherrmann opened this issue Feb 9, 2021 · 4 comments · Fixed by #1778
Closed

HaskellC2Hs fails with clang: error: no input files #1486

aherrmann opened this issue Feb 9, 2021 · 4 comments · Fixed by #1778
Labels
os:macos P4 unimportant: consider wontfix or other priority type: bug

Comments

@aherrmann
Copy link
Member

Describe the bug
The HaskellC2Hs action of c2hs_library fails on macOS in bindist mode with the error

clang: error: no input files
c2hs: Error during preprocessing custom header file

Example occurrence: CI log, BuildBuddy

To Reproduce
Run the following command on macOS in bindist mode

$ bazel build //tests/repl-targets:chs

Expected behavior
The build should succeed.

Environment

  • OS name + version: Mac OS X 10.15.7 19H114
  • Bazel version: 3.3.1
  • Version of the rules: 4d0d4e7 (based on master at 6e05343)

Additional context

I can reproduce the issue on a macOS machine locally. Jumping into the sandbox dir (bazel ... --sandbox_debug) I can boil it down to this cpp invocation that fails in the same way

/usr/bin/cpp -E -x c -DC2HS_VERSION_MAJOR=0 -DC2HS_VERSION_MINOR=28 -DC2HS_VERSION_REV=6 bazel-out/darwin-fastbuild/bin/tests/repl-targets/chs-chs/Chs.chs.h

The file exists and only contains

#define C2HS_MIN_VERSION(mj,mn,rv) ((mj)<=C2HS_VERSION_MAJOR && (mn)<=C2HS_VERSION_MINOR && (rv)<=C2HS_VERSION_REV)
@Xophmeister Xophmeister added os:macos P4 unimportant: consider wontfix or other priority labels Mar 3, 2022
@Xophmeister
Copy link
Member

Tests are explicitly skipped in 55f2c1c; that relegates it into "wontfix" territory. I'm not sure about that, but feel that it's nonetheless very low priority.

@avdv
Copy link
Member

avdv commented Jul 12, 2022

Calling the C pre-processor with -E and -x c seems weird to me. It only makes sense if you are calling the clang driver, but not if you already have the C pre-processor at hand.

Calling /usr/bin/cpp -DC2HS_VERSION_MAJOR=0 -DC2HS_VERSION_MINOR=28 -DC2HS_VERSION_REV=6 Chs.chs.h works just fine.

@aherrmann
Copy link
Member Author

Calling the C pre-processor with -E and -x c seems weird to me. It only makes sense if you are calling the clang driver, but not if you already have the C pre-processor at hand.

Good point, I think this may just be blindly copied from some place. Does changing this resolve the issue?

@avdv
Copy link
Member

avdv commented Jul 12, 2022

This is really weird:

bash-3.2$ cpp --help 2>&1 | grep '[-]x.*lang'
  -x <language>           Treat subsequent input files as having type <language>
bash-3.2$ cpp -x c /tmp/ch2s.h 
clang: error: no input files
bash-3.2$ cpp -xc /tmp/ch2s.h 
# 1 "/tmp/ch2s.h"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 399 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/tmp/ch2s.h" 2

So it seems that cpp on Darwin does not like the -x lang option form despite having it listed in its --help output.

Also interestingly, c2hs has some logic of its own: https://github.com/haskell/c2hs/blob/bb7079f4bf3ca4af00f6178d05a8da9238ddff7c/src/C2HS/Config.hs#L53-L67

So, the -x c part is actually added in by c2hs itself.

Using the cc tool instead of cpp should make this work...

avdv added a commit that referenced this issue Jul 12, 2022
Re-activate tests that had been disabled because of `c2hs` failing with `clang: error: no input files`.

Fixes #1486
avdv added a commit that referenced this issue Jul 12, 2022
The `cpp` tool on Darwin (and Windows) errors out when using the `-x c` flags:
```
$ cpp -x c /tmp/ch2s.h
clang: error: no input files
```

When using `cpp` as the tool for the `c2hs --cpp=` option, `c2hs` adds the `-x c`
flags automatically which then causes the error. (see [Config.hs])

Using the C compiler instead (with `-E`) makes this work on all systems.

Re-activate tests that had been disabled because of `c2hs` failing with `clang: error: no input files`.

Fixes #1486

[Config.hs]: https://github.com/haskell/c2hs/blob/bb7079f4bf3ca4af00f6178d05a8da9238ddff7c/src/C2HS/Config.hs#L53-L67
@mergify mergify bot closed this as completed in #1778 Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:macos P4 unimportant: consider wontfix or other priority type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants