| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 1 | # TODO(leo): I have not been able to figure out a clever way of separating this | 
 | 2 | # into multiple rules, particularly musl, which hardcodes sandbox paths into its | 
 | 3 | # toolchain such that a different rule cannot consume it. | 
 | 4 | # | 
 | 5 | # For now, using a single massive genrule is the least annoying way to do this. | 
 | 6 | # As soon as we build more than just mkfs.xfs, we should re-visit this. | 
 | 7 | # | 
 | 8 | # Some possibilities: | 
 | 9 | # | 
 | 10 | #  - Build the musl toolchain in the build container and use native rules | 
 | 11 | #    for headers_install and util_linux (they should, in theory, generate | 
 | 12 | #    well-defined artifacts that we can use in the build). | 
 | 13 | # | 
 | 14 | #    This would use Bazel's toolchain definition mechanism to consume the | 
 | 15 | #    external toolchain, and would be compatible with the native C rules. | 
 | 16 | # | 
 | 17 | #    Maybe we can even build the external toolchain inside Bazel somehow? | 
 | 18 | # | 
 | 19 | #  - Write a custom rule that handles the toolchain. | 
 | 20 | # | 
 | 21 | #  - Converting *everything* to native rules is probably not an option due | 
 | 22 | #    to how complex the third party build systems we touch are. | 
 | 23 |  | 
 | 24 | genrule( | 
| Serge Bazanski | 2fb13a8 | 2020-02-11 12:41:37 +0100 | [diff] [blame] | 25 |     name = "mkfs.extfs", | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 26 |     srcs = [ | 
| Serge Bazanski | 2fb13a8 | 2020-02-11 12:41:37 +0100 | [diff] [blame] | 27 |         "@xfsprogs//:all", | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 28 |         "@musl//:all", | 
 | 29 |         "@util_linux//:all", | 
| Serge Bazanski | 731d00a | 2020-02-03 19:08:07 +0100 | [diff] [blame] | 30 |         "@linux//:all", | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 31 |     ], | 
 | 32 |     outs = [ | 
 | 33 |         "mkfs.xfs", | 
 | 34 |     ], | 
 | 35 |     cmd = """ | 
 | 36 |     MUSL=$$PWD/$(RULEDIR)/musl_prefix | 
 | 37 |  | 
 | 38 |     echo "Compiling and installing musl..." | 
 | 39 |     ( | 
 | 40 |         cd external/musl | 
| Leopold Schabel | 544440b | 2019-10-23 15:47:50 +0200 | [diff] [blame] | 41 |         ./configure --prefix=$$MUSL --syslibdir=$$MUSL/lib | 
| Leopold Schabel | f08704a | 2019-11-06 12:34:53 +0000 | [diff] [blame] | 42 |         make -j $$(nproc) install | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 43 |     ) > /dev/null | 
 | 44 |  | 
 | 45 |     echo "Installing Linux kernel headers..." | 
 | 46 |     ( | 
| Serge Bazanski | 731d00a | 2020-02-03 19:08:07 +0100 | [diff] [blame] | 47 |         cd external/linux | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 48 |         make headers_install ARCH=x86_64 INSTALL_HDR_PATH=$$MUSL | 
 | 49 |     ) > /dev/null | 
 | 50 |  | 
 | 51 |     echo "Compiling util_linux..." | 
 | 52 |     ( | 
 | 53 |         cd external/util_linux | 
 | 54 |         ./autogen.sh | 
 | 55 |         ./configure \ | 
 | 56 |         CC="$$MUSL/bin/musl-gcc" \ | 
 | 57 |         --without-systemd \ | 
 | 58 |         --without-udev \ | 
 | 59 |         --without-btrfs \ | 
 | 60 |         --disable-pylibmount \ | 
 | 61 |         --without-tinfo \ | 
 | 62 |         --prefix=$$MUSL \ | 
 | 63 |         --disable-makeinstall-chown \ | 
 | 64 |         --disable-makeinstall-setuid \ | 
 | 65 |         --with-bashcompletiondir=$$MUSL/usr/share/bash-completion | 
| Leopold Schabel | f08704a | 2019-11-06 12:34:53 +0000 | [diff] [blame] | 66 |         make -j $$(nproc) libuuid.la libblkid.la | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 67 |         echo "Installing util_linux..." | 
 | 68 |         cp -v .libs/* $$MUSL/lib/ | 
 | 69 |         mkdir -p $$MUSL/include/{uuid,blkid} | 
 | 70 |         cp libuuid/src/uuid.h $$MUSL/include/uuid/ | 
 | 71 |         cp libblkid/src/blkid.h $$MUSL/include/blkid/ | 
 | 72 |     ) > /dev/null | 
 | 73 |  | 
 | 74 |     echo "Compiling mkfs.xfs..." | 
 | 75 |     ( | 
| Serge Bazanski | 2fb13a8 | 2020-02-11 12:41:37 +0100 | [diff] [blame] | 76 |         cd external/xfsprogs | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 77 |         make configure | 
 | 78 |         ./configure CC="$$MUSL/bin/musl-gcc" CFLAGS="-static" --prefix=$$MUSL | 
 | 79 |         echo COMPILERING | 
| Leopold Schabel | 043daa5 | 2019-10-28 11:48:45 +0000 | [diff] [blame] | 80 |         make mkfs -j8 | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 81 |     ) > /dev/null | 
 | 82 |  | 
| Serge Bazanski | 2fb13a8 | 2020-02-11 12:41:37 +0100 | [diff] [blame] | 83 |     cp external/xfsprogs/mkfs/mkfs.xfs $(RULEDIR) | 
| Leopold Schabel | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 84 |     """, | 
 | 85 |     visibility = ["//visibility:public"], | 
 | 86 | ) |