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( |
| 25 | name = "utils", |
| 26 | srcs = [ |
| 27 | "@xfsprogs_dev//:all", |
| 28 | "@musl//:all", |
| 29 | "@util_linux//:all", |
| 30 | "@linux_kernel//:all", |
| 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 | 5c80aca | 2019-10-22 15:48:58 +0200 | [diff] [blame] | 42 | make -j 8 install |
| 43 | ) > /dev/null |
| 44 | |
| 45 | echo "Installing Linux kernel headers..." |
| 46 | ( |
| 47 | cd external/linux_kernel |
| 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 |
| 66 | make -j8 libuuid.la libblkid.la |
| 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 | ( |
| 76 | cd external/xfsprogs_dev |
| 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 | |
| 83 | cp external/xfsprogs_dev/mkfs/mkfs.xfs $(RULEDIR) |
| 84 | """, |
| 85 | visibility = ["//visibility:public"], |
| 86 | ) |