Bazel: Compilation error on 32 bit machine

Created on 30 Aug 2017  Â·  5Comments  Â·  Source: bazelbuild/bazel

When i run ./compile.sh in Ubuntu 16.04 32bit i got this error("./src/tools/singlejar/mapped_file.h:40:2: error: #error This code for 64 bit Unix"),how can i do?
i follow #3382 to modify src/main/java/com/google/devtools/build/lib/util/CPU.java (line 23-29)and
tools/cpp/lib_cc_configure.bzl (line 106)like this

# Use uname to figure out whether we are on x86_32 or x86_64
  result = repository_ctx.execute(["uname", "-m"])
  if result.stdout.strip() in ["power", "ppc64le", "ppc", "ppc64"]:
    return "ppc"
  if result.stdout.strip() in ["arm", "armv7l", "aarch64"]:
    return "arm"
  if result.stdout.strip() in ["i386", "i486", "i586", "i686", "i786", "x86"]:
    return "piii"
public enum CPU {
  X86_32("piii", ImmutableSet.of("i386", "i486", "i586", "i686", "i786", "x86")),
  X86_64("x86_64", ImmutableSet.of("amd64", "x86_64", "x64")),
  PPC("ppc", ImmutableSet.of("ppc", "ppc64", "ppc64le")),
  ARM("arm", ImmutableSet.of("aarch64", "arm", "armv7l")),
  S390X("s390x", ImmutableSet.of("s390x", "s390")),
  UNKNOWN("unknown", ImmutableSet.<String>of());

but it's not work...

Bazel version : 0.5.4
my machine information is :

$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK Server VM (build 25.131-b11, mixed mode)
$ uname -a
Linux ubuntu 4.10.0-32-generic #36~16.04.1-Ubuntu SMP Wed Aug 9 09:18:53 UTC 2017 i686 i686 i686 GNU/Linux
$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

All 5 comments

If you know you're on a 32-bit machine, generally the best approach is to completely ignore the C-implementation of singlejar: https://svnweb.freebsd.org/ports/head/devel/bazel/files/extra-i386_src_BUILD?revision=447714&view=markup (the type fix also in that patch is upstream, but didn't make it into 0.5.4).

I seem to have solved this problem,
I just delete this line (./src/tools/singlejar/mapped_file.h:40: error: #error This code for 64 bit Unix)
i don't konw why and whether it is affected,but at present it's no error.

@aehlig thank you very much ,I'll have a try :)

I'm closing the issue as you've solved the problem and the proper fix has been submitted already, feel free to reopen if you have any questions.

The fix of replacing "//src/tools/singlejar:singlejar" with "//src/java_tools/singlejar:SingleJar_deploy.jar" doesn't work. It makes the ./compile.sh succeeds, but the resulting bazel can't be used to build scripts/packages:with-jdk/install.sh.

[xyz@xyz-mac-fc-x86 bazel]$ output/bazel build scripts/packages:with-jdk/install.sh                                                                               
Extracting Bazel installation...         
...........                              
ERROR: /home/xyz/.cache/bazel/_bazel_xyz/97cdd804d556cb3de47debcf86f945f6/external/bazel_tools/tools/jdk/BUILD:187:17: in singlejar attribute of java_toolchain rule @bazel_tools//tools/jdk:toolchain: '@bazel_tools//tools/jdk:singlejar' must produce a single file.                                                                 
ERROR: Analysis of target '//scripts/packages:with-jdk/install.sh' failed; build aborted.                                                                             
INFO: Elapsed time: 2.894s    

On the other hand, if I try another approach of deleting the line #error This code for 64 bit Unix, ./compile.sh succeeds, and output/bazel build //scripts/packages:with-jdk/install.sh also succeeds, but when executing the result install.sh, it fails. The root cause is the generated java toolchain is 64-bits, therefore can't run on 32-bit system:

[xyz@xyz-mac-fc-x86 bazel]$ bazel-bin/scripts/packages/with-jdk/install.sh --user
Bazel installer
---------------

Bazel is bundled with software licensed under the GPLv2 with Classpath exception.
You can find the sources next to the installer on our release page:
   https://github.com/bazelbuild/bazel/releases

# Binary package at HEAD (@)
   - [Commit](https://github.com/bazelbuild/bazel/commit/)
Uncompressing......Java version not detected while at least 1.8 is needed.
Please set JAVA_HOME.
[xyz@xyz-mac-fc-x86 bazel]$ /home/xyz/.cache/bazel/_bazel_xyz/install/6358169ca9a2dc5154b3959c34d0533b/_embedded_binaries/embedded_tools/jdk/bin/javac -version                                        
-bash: /home/xyz/.cache/bazel/_bazel_xyz/install/6358169ca9a2dc5154b3959c34d0533b/_embedded_binaries/embedded_tools/jdk/bin/javac: cannot execute binary file: Exec format error                           
[xyz@xyz-mac-fc-x86 bazel]$ readelf -h /home/xyz/.cache/bazel/_bazel_xyz/install/6358169ca9a2dc5154b3959c34d0533b/_embedded_binaries/embedded_tools/jdk/bin/javac
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x400530
  Start of program headers:          64 (bytes into file)
  Start of section headers:          3312 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         8
  Size of section headers:           64 (bytes)
  Number of section headers:         34
  Section header string table index: 31

Was this page helpful?
0 / 5 - 0 ratings