Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 27 additions & 11 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,43 @@ build --dynamic_mode=off

# Don't clobber bazel-out/[platform]/bin
build --experimental_platform_in_output_dir
build --incompatible_strict_action_env
build --compilation_mode=opt

# On Linux (targetting linux and macos) use the zig toolchain from hermetic_cc_toolchain
build:linux --platforms @zig_sdk//libc_aware/platform:linux_amd64_musl
build:linux --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:linux --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:linux --host_action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

# On Windows, use the host toolchain
# NB: after https://github.com/uber/hermetic_cc_toolchain/pull/190 is included in a release,
# this flag should no longer be needed.
build:windows --noincompatible_enable_cc_toolchain_resolution

build --incompatible_strict_action_env
# Compilation Flags for zig-cc
build:linux --copt -ffunction-sections
build:linux --copt -fdata-sections
build:linux --strip=always

build --features=thin_lto
build:linux --features=thin_lto
# ThinLTO feature doesn't exist in Zig toolchain, so we must set the flags manually.
# It also doesn't support LTO on darwin targets, so we can't set this globally.
# Instead, we configure copt/linkopt inside the toolchain itself (with a WORKSPACE patch).
#build --copt -flto=thin

# Compilation Flags for zig-cc
build --compilation_mode=opt --strip=always
build:linux --copt -ffunction-sections
build:linux --copt -fdata-sections
# On Windows, use the host toolchain
# NB: after https://github.com/uber/hermetic_cc_toolchain/pull/190 is included in a release,
# this flag should no longer be needed.
build:windows --noincompatible_enable_cc_toolchain_resolution
build:windows --copt=/W1
build:windows --copt=/WX
build:windows --copt=/external:W1
build:windows --copt=/diagnostics:column
build:windows --copt=/O2
build:windows --copt=/Ob2
build:windows --copt=/Oi
build:windows --copt=/D_MBCS
build:windows --copt=/DWIN32
build:windows --copt=/D_WINDOWS
build:windows --copt=/MD
build:windows --copt=/GS
build:windows --copt=/fp:precise
build:windows --copt=/Gd
build:windows --copt=/TC

12 changes: 12 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@ PLATFORMS = [
name = "for_" + platform.split(":")[1],
srcs = ["@libarchive//tar"],
target_platform = platform,
tags = ["manual"],
)
for platform in PLATFORMS
]

filegroup(
name = "for_all_platforms",
srcs = ["for_" + platform.split(":")[1] for platform in PLATFORMS],
target_compatible_with = [
"@platforms//os:linux",
],
)

alias(
name = "tar",
actual = "@libarchive//tar",
target_compatible_with = [
"@platforms//os:windows",
],
)
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ bazel_dep(name = "aspect_bazel_lib", version = "2.15.3")
bazel_dep(name = "libarchive", version = "3.8.1")
bazel_dep(name = "hermetic_cc_toolchain", version = "4.0.0")

# Apply patches to libarchive for Windows fixes
single_version_override(
module_name = "libarchive",
patches = [
"//patches:archive_read_support_format_mtree.patch",
],
patch_strip = 1,
)

toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
use_repo(toolchains, "zig_sdk")

Expand Down
Empty file added patches/BUILD.bazel
Empty file.
39 changes: 39 additions & 0 deletions patches/archive_read_support_format_mtree.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c
index fb0f946b..f508a8af 100644
--- a/libarchive/archive_read_support_format_mtree.c
+++ b/libarchive/archive_read_support_format_mtree.c
@@ -1073,6 +1073,8 @@ read_mtree(struct archive_read *a, struct mtree *mtree)
/* Non-printable characters are not allowed */
for (s = p;s < p + len - 1; s++) {
if (!isprint((unsigned char)*s) && *s != '\t') {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Non-printable character 0x%02X", (unsigned char)(*s));
r = ARCHIVE_FATAL;
break;
}
@@ -2130,6 +2132,13 @@ readline(struct archive_read *a, struct mtree *mtree, char **start,
for (u = mtree->line.s + find_off; *u; ++u) {
if (u[0] == '\n') {
/* Ends with unescaped newline. */
+ /* Check if preceded by '\r' for CRLF handling */
+ if (u > mtree->line.s && u[-1] == '\r') {
+ /* CRLF ending - remove the '\r' */
+ u[-1] = '\n';
+ u[0] = '\0';
+ total_size--;
+ }
*start = mtree->line.s;
return total_size;
} else if (u[0] == '#') {
@@ -2144,6 +2153,11 @@ readline(struct archive_read *a, struct mtree *mtree, char **start,
total_size -= 2;
mtree->line.s[total_size] = '\0';
break;
+ } else if (u[1] == '\r' && u[2] == '\n') {
+ /* Trim escaped CRLF. */
+ total_size -= 3;
+ mtree->line.s[total_size] = '\0';
+ break;
} else if (u[1] != '\0') {
/* Skip the two-char escape sequence */
++u;
Loading