Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ alias(
}),
)

### fuse2fs, used to mount ext filesystems in userspace
alias(
name = "fuse2fs",
actual = select({
"@bazel_tools//src/conditions:linux_x86_64": "@e2fsprogs//:fuse2fs",
"//conditions:default": "@platforms//:incompatible",
}),
)

### dosfstools, used to build (mkfs.fat) and label (fatlabel) FAT filesystem images

# Both aliases resolve to the dosfstools package, which builds the mkfs.fat and
Expand Down
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,15 @@ http_archive(
],
)

http_archive(
name = "libfuse",
build_file = "@//third_party:BUILD.libfuse.bazel",
sha256 = "f01de85717e20adf5f98aff324acd85dd73d61a5ca3834d573dcf0bd6e54a298",
strip_prefix = "fuse-3.18.2",
type = "tar.gz",
urls = ["https://github.com/libfuse/libfuse/releases/download/fuse-3.18.2/fuse-3.18.2.tar.gz"],
)

http_archive(
name = "e2fsprogs",
build_file = "@//third_party:BUILD.e2fsprogs.bazel",
Expand Down
39 changes: 39 additions & 0 deletions bazel/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Utilities for building IC replica and canisters.
"""

load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_test", "rust_test_suite")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
Expand Down Expand Up @@ -392,6 +393,44 @@ volatile_status = rule(
implementation = _volatile_status_impl,
)

def _disable_hermetic_cc_transition(_settings, _attr):
return {
"//bazel:hermetic_cc": False,
}

disable_hermetic_cc_transition = transition(
implementation = _disable_hermetic_cc_transition,
inputs = [],
outputs = [
"//bazel:hermetic_cc",
],
)

def _disable_hermetic_cc_target_impl(ctx):
dep = ctx.attr.target[0]
providers = [dep[DefaultInfo]]

if CcInfo in dep:
providers.append(dep[CcInfo])
if OutputGroupInfo in dep:
providers.append(dep[OutputGroupInfo])

return providers

disable_hermetic_cc_target = rule(
implementation = _disable_hermetic_cc_target_impl,
attrs = {
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"target": attr.label(
mandatory = True,
cfg = disable_hermetic_cc_transition,
allow_files = True,
),
},
)

def file_size_check(
name,
file,
Expand Down
45 changes: 36 additions & 9 deletions third_party/BUILD.e2fsprogs.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ e2fsprogs, built from source. The bundled libuuid/libblkid are enabled so we
don't link against system copies.
"""

load("@//bazel:defs.bzl", "disable_hermetic_cc_target")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
Expand All @@ -11,16 +12,16 @@ filegroup(
)

configure_make(
name = "mke2fs",
name = "e2fsprogs_impl",
args = ["-j"],
configure_in_place = True,
configure_options = [
# Use the bundled libuuid/libblkid rather than the host's, so the binary
# stays self-contained.
"--enable-libuuid",
"--enable-libblkid",
"--enable-fuse2fs",
# Trim optional features that would pull in extra deps or shared libs.
"--disable-fuse2fs",
"--disable-uuidd",
"--disable-nls",
"--disable-tls",
Expand All @@ -35,13 +36,16 @@ configure_make(
"--with-systemd-unit-dir=no",
],
env = {
"CFLAGS": "-g -O2 -static",
"LDFLAGS": "-static",
"CFLAGS": "-O2 -static -I$$EXT_BUILD_DEPS/include",
"LDFLAGS": "-static -L$$EXT_BUILD_DEPS/lib",
},
lib_source = ":all_srcs",
out_binaries = ["mke2fs"],
out_binaries = [
"fuse2fs",
"mke2fs",
],
# We don't ship any libs out of this build; everything is folded into the
# mke2fs binary.
# exported binaries.
out_shared_libs = [],
out_static_libs = [],
# mke2fs is installed under sbin/ by autotools (it's a sysadmin tool);
Expand All @@ -52,15 +56,38 @@ configure_make(
# as an output.
postfix_script = (
"mkdir -p $$INSTALLDIR/bin" +
" && cp $$INSTALLDIR/sbin/mke2fs $$INSTALLDIR/bin/mke2fs" +
" && find $$INSTALLDIR -mindepth 1 -maxdepth 1 ! -name bin ! -name include -exec rm -rf {} +" +
" && find $$INSTALLDIR/bin -mindepth 1 ! -name mke2fs -delete"
" && cp misc/mke2fs $$INSTALLDIR/bin/mke2fs" +
" && cp misc/fuse2fs $$INSTALLDIR/bin/fuse2fs"
),
# Static glibc linking is a Linux/glibc thing; this isn't expected to work
# elsewhere.
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
deps = [
"@libfuse",
],
)

# e2fsprogs' dependency, libfuse does not build with hermetic toolchains (meson is not happy with the zig linker),
# and building libfuse without the hermetic and e2fsprogs with the hermetic toolchain causes linking issues because of
# glibc version mismatch. So just disable the hermetic toolchain for e2fsprogs.
disable_hermetic_cc_target(
name = "e2fsprogs",
target = ":e2fsprogs_impl",
)

filegroup(
name = "fuse2fs",
srcs = [":e2fsprogs"],
output_group = "fuse2fs",
visibility = ["//visibility:public"],
)

filegroup(
name = "mke2fs",
srcs = [":e2fsprogs"],
output_group = "mke2fs",
visibility = ["//visibility:public"],
)
35 changes: 35 additions & 0 deletions third_party/BUILD.libfuse.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson")

filegroup(
name = "all_srcs",
srcs = glob(
include = ["**"],
exclude = ["*.bazel"],
),
)

# This only builds with --hermetic_cc=false or the disable_hermetic_cc transition.
meson(
name = "libfuse",
env = {
"CFLAGS": "-O2",
},
lib_source = ":all_srcs",
options = {
"default_library": "static",
"disable-mtab": "true",
"examples": "false",
"tests": "false",
"useroot": "false",
"utils": "false",
"bindir": "/bin",
},
out_shared_libs = [],
out_static_libs = ["libfuse3.a"],
postfix_script = (
"libfuse_archive=$$(find $$INSTALLDIR/lib -name libfuse3.a -print -quit)" +
" && test -n \"$$libfuse_archive\"" +
" && cp \"$$libfuse_archive\" $$INSTALLDIR/lib/libfuse3.a"
),
visibility = ["//visibility:public"],
)
Loading