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

Couldn't build file external/gmp/gmp_6_1_2/config.h #2

Closed
luxe opened this issue Jan 10, 2019 · 5 comments
Closed

Couldn't build file external/gmp/gmp_6_1_2/config.h #2

luxe opened this issue Jan 10, 2019 · 5 comments

Comments

@luxe
Copy link

luxe commented Jan 10, 2019

workspace:

git_repository(
    name = "gmp",
    remote = "https://github.com/robin-thomas/bazelify-gmp",
    commit = "bb4881b35e6864c90493980d035e1d984cafd093",
)

the build rule:

cc_library(
    name = "lib",
    srcs = glob(["*.cpp"]),
    hdrs = glob(["*.hpp"]),
    deps = ["@bazelify_gmp//:gmp",],
)

(accessing #include <gmpxx.h> in the source code)

build:

INFO: Invocation ID: 9224b749-a34a-4cb1-8c74-3dfbff118f62
INFO: Analysed 1563 targets (0 packages loaded, 0 targets configured).
INFO: Found 1563 targets...
ERROR: /home/thickey/.cache/bazel/_bazel_thickey/12ea4ca4c5b772e334d238b0acc653b5/external/bazelify_gmp/gmp_6_1_2/BUILD:41:1: Couldn't build file external/bazelify_gmp/gmp_6_1_2/config.h: Executing genrule @bazelify_gmp//gmp_6_1_2:gen_gmp_hdrs failed (Exit 1): bash failed: error executing command 
  (cd /home/thickey/.cache/bazel/_bazel_thickey/12ea4ca4c5b772e334d238b0acc653b5/execroot/__main__ && \
  exec env - \
    PATH=/bin:/usr/bin \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; 
        if [ ! -f bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp.h ]; then
          m4_PATH=`pwd`"/bazel-out/host/bin/external/m4_v1.4.18/bin"
          PATH=${PATH}:${m4_PATH}
          [ -d external/bazelify_gmp ] && cd external/bazelify_gmp
          cd gmp_6_1_2

          ./configure >/dev/null
          cat gmp.h | grep "#define GMP_LIMB_BITS" | tr -s [:blank:] | cut -f3 -d'\'' '\'' > gmp_limb_bits
          cat gmp.h | grep "#define GMP_NAIL_BITS" | tr -s [:blank:] | cut -f3 -d'\'' '\'' > gmp_nail_bits

          grep "CCAS =" Makefile | cut -d'\''='\'' -f2 > ccas
          hdrs_path=`pwd`"/"`dirname bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp.h`
          CPP_FLAGS_="-DHAVE_CONFIG_H -D__GMP_WITHIN_GMP -I. -I.. -I${hdrs_path}"
          CPP_FLAGS_=${CPP_FLAGS_}`grep "CFLAGS =" Makefile | sed '\''s/^[^=]*=//g'\''`
          echo ${CPP_FLAGS_} > cpp_flags

          tar -czf mpn_srcs.tar.gz mpn/*

          cd ../
          [ -d ../../external/bazelify_gmp ] && cd ../..
          if [ -d external/bazelify_gmp ]; then
            cp external/bazelify_gmp/gmp_6_1_2/config.h bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/config.h
            cp external/bazelify_gmp/gmp_6_1_2/gmp.h bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp.h
            cp external/bazelify_gmp/gmp_6_1_2/gmp_limb_bits bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp_limb_bits
            cp external/bazelify_gmp/gmp_6_1_2/gmp_nail_bits bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp_nail_bits
            cp external/bazelify_gmp/gmp_6_1_2/gmp-mparam.h bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp-mparam.h
            cp external/bazelify_gmp/gmp_6_1_2/config.m4 bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/config.m4
            cp external/bazelify_gmp/gmp_6_1_2/ccas bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/ccas
            cp external/bazelify_gmp/gmp_6_1_2/cpp_flags bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/cpp_flags
            cp external/bazelify_gmp/gmp_6_1_2/mpn_srcs.tar.gz bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/mpn_srcs.tar.gz
          else
            cp gmp_6_1_2/config.h bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/config.h
            cp gmp_6_1_2/gmp.h bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp.h
            cp gmp_6_1_2/gmp_limb_bits bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp_limb_bits
            cp gmp_6_1_2/gmp_nail_bits bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp_nail_bits
            cp gmp_6_1_2/gmp-mparam.h bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp-mparam.h
            cp gmp_6_1_2/config.m4 bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/config.m4
            cp gmp_6_1_2/ccas bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/ccas
            cp gmp_6_1_2/cpp_flags bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/cpp_flags
            cp gmp_6_1_2/mpn_srcs.tar.gz bazel-out/k8-fastbuild/genfiles/external/bazelify_gmp/gmp_6_1_2/mpn_srcs.tar.gz
          fi
        fi
    ')
Execution platform: @bazel_tools//platforms:host_platform
cat: conftest.c: No such file or directory
configure: error: could not find a working compiler, see config.log for details
ERROR: /home/thickey/.cache/bazel/_bazel_thickey/12ea4ca4c5b772e334d238b0acc653b5/external/bazelify_gmp/gmp_6_1_2/BUILD:41:1: Couldn't build file external/bazelify_gmp/gmp_6_1_2/config.h: Executing genrule @bazelify_gmp//gmp_6_1_2:gen_gmp_hdrs failed (Exit 1): bash failed: error executing command 
  (cd /home/thickey/.cache/bazel/_bazel_thickey/12ea4ca4c5b772e334d238b0acc653b5/execroot/__main__ && \
  exec env - \
    PATH=/bin:/usr/bin \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; 
        if [ ! -f bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp.h ]; then
          m4_PATH=`pwd`"/bazel-out/host/bin/external/m4_v1.4.18/bin"
          PATH=${PATH}:${m4_PATH}
          [ -d external/bazelify_gmp ] && cd external/bazelify_gmp
          cd gmp_6_1_2

          ./configure >/dev/null
          cat gmp.h | grep "#define GMP_LIMB_BITS" | tr -s [:blank:] | cut -f3 -d'\'' '\'' > gmp_limb_bits
          cat gmp.h | grep "#define GMP_NAIL_BITS" | tr -s [:blank:] | cut -f3 -d'\'' '\'' > gmp_nail_bits

          grep "CCAS =" Makefile | cut -d'\''='\'' -f2 > ccas
          hdrs_path=`pwd`"/"`dirname bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp.h`
          CPP_FLAGS_="-DHAVE_CONFIG_H -D__GMP_WITHIN_GMP -I. -I.. -I${hdrs_path}"
          CPP_FLAGS_=${CPP_FLAGS_}`grep "CFLAGS =" Makefile | sed '\''s/^[^=]*=//g'\''`
          echo ${CPP_FLAGS_} > cpp_flags

          tar -czf mpn_srcs.tar.gz mpn/*

          cd ../
          [ -d ../../external/bazelify_gmp ] && cd ../..
          if [ -d external/bazelify_gmp ]; then
            cp external/bazelify_gmp/gmp_6_1_2/config.h bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/config.h
            cp external/bazelify_gmp/gmp_6_1_2/gmp.h bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp.h
            cp external/bazelify_gmp/gmp_6_1_2/gmp_limb_bits bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp_limb_bits
            cp external/bazelify_gmp/gmp_6_1_2/gmp_nail_bits bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp_nail_bits
            cp external/bazelify_gmp/gmp_6_1_2/gmp-mparam.h bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp-mparam.h
            cp external/bazelify_gmp/gmp_6_1_2/config.m4 bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/config.m4
            cp external/bazelify_gmp/gmp_6_1_2/ccas bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/ccas
            cp external/bazelify_gmp/gmp_6_1_2/cpp_flags bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/cpp_flags
            cp external/bazelify_gmp/gmp_6_1_2/mpn_srcs.tar.gz bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/mpn_srcs.tar.gz
          else
            cp gmp_6_1_2/config.h bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/config.h
            cp gmp_6_1_2/gmp.h bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp.h
            cp gmp_6_1_2/gmp_limb_bits bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp_limb_bits
            cp gmp_6_1_2/gmp_nail_bits bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp_nail_bits
            cp gmp_6_1_2/gmp-mparam.h bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/gmp-mparam.h
            cp gmp_6_1_2/config.m4 bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/config.m4
            cp gmp_6_1_2/ccas bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/ccas
            cp gmp_6_1_2/cpp_flags bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/cpp_flags
            cp gmp_6_1_2/mpn_srcs.tar.gz bazel-out/host/genfiles/external/bazelify_gmp/gmp_6_1_2/mpn_srcs.tar.gz
          fi
        fi
    ')
Execution platform: @bazel_tools//platforms:host_platform
cat: conftest.c: No such file or directory
configure: error: could not find a working compiler, see config.log for details
INFO: Elapsed time: 5.091s, Critical Path: 1.41s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

uname -a

Linux tower 4.4.0-124-generic #148~14.04.1-Ubuntu SMP Thu May 3 07:26:53 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

any tips for me?

@robin-thomas
Copy link
Owner

robin-thomas commented Jan 10, 2019

@luxe Can you share your whole WORKSPACE file too?

Also, which bazel project is this?

@luxe
Copy link
Author

luxe commented Jan 10, 2019

I made a fork.
https://github.com/luxe/bazelify-gmp

Are you able to build?
Here's what I got:

bazel build //...:all
INFO: Analysed 38 targets (0 packages loaded).
INFO: Found 38 targets...
ERROR: /home/thickey/Desktop/bazelify-gmp/gmp_6_1_2/BUILD:41:1: Executing genrule //gmp_6_1_2:gen_gmp_hdrs failed (Exit 1)
/usr/bin/install: target '/home/thickey/.cache/bazel/_bazel_thickey/7b25718df33dafb1a6b0d455e984e547/execroot/__main__/gmp_6_1_2/conftest.dir' is not a directory
cat: conftest.c: No such file or directory
configure: error: could not find a working compiler, see config.log for details
INFO: Elapsed time: 1.607s, Critical Path: 1.06s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Interestingly, I see conftest.c as a new file after running the build for the first time.
(I pushed those files up)

	new file:   ../gmp_6_1_2/cnfm4.tmp
	new file:   ../gmp_6_1_2/cnfm4i.tmp
	new file:   ../gmp_6_1_2/cnfm4p.tmp
	new file:   ../gmp_6_1_2/config.log
	new file:   ../gmp_6_1_2/conftest.c

But I guess it didn't build the conftest.dir

@robin-thomas
Copy link
Owner

@luxe Yes. I'm able to build. I had tried it on Ubuntu 16.04 and Mac.

conftest.c and similar files are made by running the configure script (I wanted to try running it in sandbox mode, but that creates a read-only filesystem and configure fails. Also, had been using new_http_archive, but with Bazel's transitive WORKSPACE issue, thought to better put the gmp files directly in this repo).

Can you try building with the below command?

$ bazel build //:gmp

@luxe
Copy link
Author

luxe commented Jan 11, 2019

nice, bazel build //:gmp does work.

bazel build //:gmp
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
...........
INFO: Analysed target //:gmp (15 packages loaded).
INFO: Found 1 target...
INFO: From Compiling external/m4_v1.4.18/lib/c-stack.c [for host]:
external/m4_v1.4.18/lib/c-stack.c:107:1: warning: 'die' defined but not used [-Wunused-function]
 die (int signo)
 ^~~
Target //:gmp up-to-date (nothing to build)
INFO: Elapsed time: 26.316s, Critical Path: 16.04s
INFO: 407 processes: 406 linux-sandbox, 1 local.
INFO: Build completed successfully, 551 total actions

trying to building that extra target with bazel build //...:all fails:

bazel build //...:all
INFO: Analysed 38 targets (7 packages loaded).
INFO: Found 38 targets...
ERROR: /home/laptop/Desktop/bazelify-gmp/gmp_6_1_2/BUILD:41:1: Executing genrule //gmp_6_1_2:gen_gmp_hdrs failed (Exit 1)
cat: conftest.c: No such file or directory
cat: conftest.c: No such file or directory
cat: conftest.c: No such file or directory
cat: conftest.c: No such file or directory
configure: error: could not find a working compiler, see config.log for details
INFO: Elapsed time: 1.917s, Critical Path: 0.83s
INFO: 23 processes: 23 linux-sandbox.
FAILED: Build did NOT complete successfully

However, I am able to build that genrule specifically:

bazel build //gmp_6_1_2:gen_gmp_hdrs
INFO: Analysed target //gmp_6_1_2:gen_gmp_hdrs (0 packages loaded).
INFO: Found 1 target...
Target //gmp_6_1_2:gen_gmp_hdrs up-to-date:
  bazel-genfiles/gmp_6_1_2/config.h
  bazel-genfiles/gmp_6_1_2/gmp.h
  bazel-genfiles/gmp_6_1_2/gmp-mparam.h
  bazel-genfiles/gmp_6_1_2/gmp_limb_bits
  bazel-genfiles/gmp_6_1_2/gmp_nail_bits
  bazel-genfiles/gmp_6_1_2/config.m4
  bazel-genfiles/gmp_6_1_2/ccas
  bazel-genfiles/gmp_6_1_2/cpp_flags
  bazel-genfiles/gmp_6_1_2/mpn_srcs.tar.gz
INFO: Elapsed time: 0.357s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action

but then the build //...:all attempt fails again:

bazel build //...:all               
INFO: Analysed 38 targets (0 packages loaded).
INFO: Found 38 targets...
ERROR: /home/laptop/Desktop/bazelify-gmp/gmp_6_1_2/BUILD:358:1: Executing genrule //gmp_6_1_2:gen_mpn_objs failed (Exit 1)
ln: failed to create symbolic link '../config.m4': File exists
INFO: Elapsed time: 1.141s, Critical Path: 0.14s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

If I do the specific build rule again, that one succeeds:

bazel build //gmp_6_1_2:gen_mpn_objs
INFO: Analysed target //gmp_6_1_2:gen_mpn_objs (0 packages loaded).
INFO: Found 1 target...
Target //gmp_6_1_2:gen_mpn_objs up-to-date:
  bazel-genfiles/gmp_6_1_2/mpn_generated.tar.gz
  bazel-genfiles/gmp_6_1_2/libmpn_generated.a
INFO: Elapsed time: 12.546s, Critical Path: 12.28s
INFO: 1 process: 1 local.
INFO: Build completed successfully, 2 total actions

but then I'm kind of out of luck again:

bazel build //...:all
INFO: Analysed 38 targets (0 packages loaded).
INFO: Found 38 targets...
ERROR: /home/laptop/Desktop/bazelify-gmp/BUILD:3:1: SkylarkAction mpn_asm_tree.cc failed (Exit 2)
tar: bazel-out/k8-fastbuild/bin/mpn_asm_tree.cc: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
INFO: Elapsed time: 0.313s, Critical Path: 0.07s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

The problem seems to be with trying to build all-- which isn't something we necessarily have to do,
but it is a canonical thing to do when using bazel.

Because you're right, the library builds fine:

bazel build //test:lib
Starting local Bazel server and connecting to it...
.............
INFO: Analysed target //test:lib (16 packages loaded).
INFO: Found 1 target...
INFO: From Compiling external/m4_v1.4.18/lib/c-stack.c [for host]:
external/m4_v1.4.18/lib/c-stack.c:107:1: warning: 'die' defined but not used [-Wunused-function]
 die (int signo)
 ^~~
Target //test:lib up-to-date:
  bazel-bin/test/liblib.a
  bazel-bin/test/liblib.so
INFO: Elapsed time: 26.457s, Critical Path: 14.91s
INFO: 410 processes: 409 linux-sandbox, 1 local.
INFO: Build completed successfully, 556 total actions

I need to learn some more bazel foo to see if I can debug this better.
Maybe bazel's pwd is different or changing when you build with all? Not sure.

@luxe
Copy link
Author

luxe commented Jan 14, 2019

There's nothing wrong with the rules.
It's just that the rules call ./configure which can fail for any number of reasons based on the system.
So that's a much harder issue to fix:
bazelbuild/bazel#2814

I'm going to close, and try to figure out something different.

@luxe luxe closed this as completed Jan 14, 2019
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

2 participants