Base: codex-main originale (prima del fork aKode)
This commit is contained in:
27
third_party/powershell/BUILD.bazel
vendored
Normal file
27
third_party/powershell/BUILD.bazel
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
exports_files(["pwsh.exe"])
|
||||
|
||||
filegroup(
|
||||
name = "pwsh",
|
||||
srcs = ["pwsh.exe"],
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
# The executable is also a stable marker whose parent is the runtime root.
|
||||
filegroup(
|
||||
name = "runtime_marker",
|
||||
srcs = ["pwsh.exe"],
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "runtime",
|
||||
srcs = glob(
|
||||
["**"],
|
||||
# This BUILD file is also loaded from the source tree, where the
|
||||
# archive-only paths are intentionally absent.
|
||||
allow_empty = True,
|
||||
),
|
||||
tags = ["manual"],
|
||||
)
|
||||
813
third_party/v8/BUILD.bazel
vendored
Normal file
813
third_party/v8/BUILD.bazel
vendored
Normal file
@@ -0,0 +1,813 @@
|
||||
load("@@//third_party/v8:artifact_profile.bzl", "v8_artifact_files")
|
||||
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
||||
load("@rules_cc//cc:cc_static_library.bzl", "cc_static_library")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("@rules_rs//rs:rules_rust_bindgen.bzl", "rust_bindgen")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
exports_files([
|
||||
"abseil.BUILD.bazel",
|
||||
"abseil_repository.bzl",
|
||||
"artifact_profile.bzl",
|
||||
"dependencies.bzl",
|
||||
"dependency_config.bzl",
|
||||
"dragonbox.BUILD.bazel",
|
||||
"engine.BUILD.bazel",
|
||||
"engine_repository.bzl",
|
||||
"engine_rules.bzl",
|
||||
"fast_float.BUILD.bazel",
|
||||
"fp16.BUILD.bazel",
|
||||
"highway.BUILD.bazel",
|
||||
"icu.BUILD.bazel",
|
||||
"libcxx_rules.bzl",
|
||||
"native_windows.bzl",
|
||||
"push_registers_gnullvm.S",
|
||||
"simdutf.BUILD.bazel",
|
||||
"v8_defs.patch",
|
||||
])
|
||||
|
||||
config_setting(
|
||||
name = "platform_windows_msvc",
|
||||
constraint_values = [
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "use_rusty_v8_custom_libcxx",
|
||||
flag_values = {
|
||||
"@v8//:v8_use_rusty_v8_custom_libcxx": "True",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "use_rusty_v8_custom_libcxx_native_windows",
|
||||
constraint_values = [
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
flag_values = {
|
||||
"@v8//:v8_use_rusty_v8_custom_libcxx": "True",
|
||||
},
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "v8_152_2_0_x86_64_pc_windows_msvc",
|
||||
actual = "@rusty_v8_152_2_0_x86_64_pc_windows_msvc_archive//file",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "v8_152_2_0_aarch64_pc_windows_msvc",
|
||||
actual = "@rusty_v8_152_2_0_aarch64_pc_windows_msvc_archive//file",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "v8_152_2_0_aarch64_pc_windows_gnullvm",
|
||||
# `rusty_v8` only ships prebuilt Windows archives for MSVC. Build the
|
||||
# GNU-flavored archive in-tree so windows-gnullvm consumers can link
|
||||
# against a matching ABI instead of trying to reuse the MSVC release.
|
||||
actual = ":v8_152_2_0_aarch64_pc_windows_gnullvm_bazel",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "v8_152_2_0_x86_64_pc_windows_gnullvm",
|
||||
actual = ":v8_152_2_0_x86_64_pc_windows_gnullvm_bazel",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "rusty_v8_archive_for_target",
|
||||
actual = ":rusty_v8_source_archive_for_target",
|
||||
)
|
||||
|
||||
# Use LLVM's libc-aware Linux selectors for archives and bindings: LLVM musl
|
||||
# platforms omit rules_rs' separate libc constraint, which defaults to glibc.
|
||||
alias(
|
||||
name = "rusty_v8_prebuilt_archive_for_target",
|
||||
actual = select({
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": ":v8_152_2_0_aarch64_pc_windows_msvc",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": ":v8_152_2_0_x86_64_pc_windows_msvc",
|
||||
"@rules_rs//rs/platforms/config:aarch64-apple-darwin": "@rusty_v8_152_2_0_aarch64_apple_darwin_archive//file",
|
||||
"@llvm//platforms/config:linux_aarch64_gnu": ":v8_152_2_0_aarch64_unknown_linux_gnu_prebuilt",
|
||||
"@rules_rs//rs/platforms/config:x86_64-apple-darwin": "@rusty_v8_152_2_0_x86_64_apple_darwin_archive//file",
|
||||
"@llvm//platforms/config:linux_x86_64_gnu": ":v8_152_2_0_x86_64_unknown_linux_gnu_prebuilt",
|
||||
"@llvm//platforms/config:linux_aarch64_musl": ":v8_152_2_0_aarch64_unknown_linux_musl_prebuilt",
|
||||
"@llvm//platforms/config:linux_x86_64_musl": ":v8_152_2_0_x86_64_unknown_linux_musl_prebuilt",
|
||||
"//conditions:default": ":rusty_v8_source_archive_for_target",
|
||||
}),
|
||||
)
|
||||
|
||||
# A Linux Codex release archive carries Chromium's namespaced libc++ runtime.
|
||||
# Bazel also links its own libc++. Both keep their exception classes in std::,
|
||||
# so prefer the toolchain definitions of just those shared ABI entry points.
|
||||
# Inputs remain checksum-verified and immutable; only the Bazel output changes.
|
||||
[
|
||||
genrule(
|
||||
name = "v8_152_2_0_%s_unknown_linux_%s_prebuilt" % (arch, libc),
|
||||
srcs = [
|
||||
":gnu_libcxx_shared_exception_symbols.txt",
|
||||
"@rusty_v8_152_2_0_%s_unknown_linux_%s_archive//file" % (arch, libc),
|
||||
],
|
||||
outs = ["libv8_152_2_0_%s_unknown_linux_%s_prebuilt.a" % (arch, libc)],
|
||||
cmd = """
|
||||
gzip -dc "$(location @rusty_v8_152_2_0_%s_unknown_linux_%s_archive//file)" > "$@.unadjusted"
|
||||
$(location @llvm//tools:llvm-objcopy) \
|
||||
--weaken-symbols="$(location :gnu_libcxx_shared_exception_symbols.txt)" \
|
||||
"$@.unadjusted" "$@"
|
||||
rm "$@.unadjusted"
|
||||
""" % (arch, libc),
|
||||
tools = ["@llvm//tools:llvm-objcopy"],
|
||||
)
|
||||
for arch in [
|
||||
"aarch64",
|
||||
"x86_64",
|
||||
]
|
||||
for libc in [
|
||||
"gnu",
|
||||
"musl",
|
||||
]
|
||||
]
|
||||
|
||||
alias(
|
||||
name = "rusty_v8_source_archive_for_target",
|
||||
actual = select({
|
||||
"@rules_rs//rs/platforms/config:aarch64-apple-darwin": ":v8_152_2_0_aarch64_apple_darwin_bazel",
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-gnullvm": ":v8_152_2_0_aarch64_pc_windows_gnullvm",
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": ":v8_152_2_0_aarch64_pc_windows_msvc_bazel",
|
||||
"@llvm//platforms/config:linux_aarch64_gnu": ":v8_152_2_0_aarch64_unknown_linux_gnu_bazel",
|
||||
# Rust's compiler-builtins archive does not supply V8's __clear_cache.
|
||||
# Use the merged archive containing the ARM64 compiler-rt builtins.
|
||||
"@llvm//platforms/config:linux_aarch64_musl": ":v8_152_2_0_aarch64_unknown_linux_musl_release",
|
||||
"@rules_rs//rs/platforms/config:x86_64-apple-darwin": ":v8_152_2_0_x86_64_apple_darwin_bazel",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-gnullvm": ":v8_152_2_0_x86_64_pc_windows_gnullvm",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": ":v8_152_2_0_x86_64_pc_windows_msvc_bazel",
|
||||
"@llvm//platforms/config:linux_x86_64_gnu": ":v8_152_2_0_x86_64_unknown_linux_gnu_bazel",
|
||||
"@llvm//platforms/config:linux_x86_64_musl": ":v8_152_2_0_x86_64_unknown_linux_musl_release",
|
||||
"//conditions:default": ":v8_152_2_0_x86_64_unknown_linux_gnu_bazel",
|
||||
}),
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "rusty_v8_binding_for_target",
|
||||
actual = ":rusty_v8_source_binding_for_target",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "rusty_v8_prebuilt_binding_for_target",
|
||||
actual = select({
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": "@rusty_v8_152_2_0_aarch64_pc_windows_msvc_binding//file",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": "@rusty_v8_152_2_0_x86_64_pc_windows_msvc_binding//file",
|
||||
"@rules_rs//rs/platforms/config:aarch64-apple-darwin": "@rusty_v8_152_2_0_aarch64_apple_darwin_binding//file",
|
||||
"@llvm//platforms/config:linux_aarch64_gnu": "@rusty_v8_152_2_0_aarch64_unknown_linux_gnu_binding//file",
|
||||
"@rules_rs//rs/platforms/config:x86_64-apple-darwin": "@rusty_v8_152_2_0_x86_64_apple_darwin_binding//file",
|
||||
"@llvm//platforms/config:linux_x86_64_gnu": "@rusty_v8_152_2_0_x86_64_unknown_linux_gnu_binding//file",
|
||||
"@llvm//platforms/config:linux_aarch64_musl": "@rusty_v8_152_2_0_aarch64_unknown_linux_musl_binding//file",
|
||||
"@llvm//platforms/config:linux_x86_64_musl": "@rusty_v8_152_2_0_x86_64_unknown_linux_musl_binding//file",
|
||||
"//conditions:default": ":rusty_v8_source_binding_for_target",
|
||||
}),
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "rusty_v8_source_binding_for_target",
|
||||
actual = select({
|
||||
"@rules_rs//rs/platforms/config:aarch64-apple-darwin": ":src_binding_aarch64_apple_darwin_152_2_0_bazel",
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-gnullvm": ":src_binding_aarch64_pc_windows_gnullvm_152_2_0_bazel",
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": ":src_binding_aarch64_pc_windows_msvc_152_2_0_bazel",
|
||||
"@llvm//platforms/config:linux_aarch64_gnu": ":src_binding_aarch64_unknown_linux_gnu_152_2_0_bazel",
|
||||
"@llvm//platforms/config:linux_aarch64_musl": ":src_binding_aarch64_unknown_linux_musl_152_2_0_bazel",
|
||||
"@rules_rs//rs/platforms/config:x86_64-apple-darwin": ":src_binding_x86_64_apple_darwin_152_2_0_bazel",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-gnullvm": ":src_binding_x86_64_pc_windows_gnullvm_152_2_0_bazel",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": ":src_binding_x86_64_pc_windows_msvc_152_2_0_bazel",
|
||||
"@llvm//platforms/config:linux_x86_64_gnu": ":src_binding_x86_64_unknown_linux_gnu_152_2_0_bazel",
|
||||
"@llvm//platforms/config:linux_x86_64_musl": ":src_binding_x86_64_unknown_linux_musl_152_2_0_bazel",
|
||||
"//conditions:default": ":src_binding_x86_64_unknown_linux_gnu_152_2_0_bazel",
|
||||
}),
|
||||
)
|
||||
|
||||
V8_COPTS = select({
|
||||
":platform_windows_msvc": [
|
||||
"/std:c++20",
|
||||
"/Zc:__cplusplus",
|
||||
],
|
||||
"//conditions:default": ["-std=c++20"],
|
||||
})
|
||||
|
||||
V8_CUSTOM_LIBCXX_COPTS = select({
|
||||
":use_rusty_v8_custom_libcxx_native_windows": [
|
||||
"/D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
"/D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
"/D_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
],
|
||||
":use_rusty_v8_custom_libcxx": [
|
||||
"-nostdinc++",
|
||||
"-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
"-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
"-D_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
"-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
V8_STATIC_LIBRARY_FEATURES = [
|
||||
"-symbol_check",
|
||||
"-validate-static-library",
|
||||
]
|
||||
|
||||
alias(
|
||||
name = "rusty_v8_llvm_libc_headers",
|
||||
actual = "@rusty_v8_llvm_libc//:v8_headers",
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rusty_v8_custom_libcxx_headers",
|
||||
defines = select({
|
||||
"@llvm//platforms/config:linux_aarch64_musl": ["ANDROID_HOST_MUSL"],
|
||||
"@llvm//platforms/config:linux_x86_64_musl": ["ANDROID_HOST_MUSL"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@rusty_v8_libcxx//:headers"] + select({
|
||||
":use_rusty_v8_custom_libcxx_native_windows": [],
|
||||
"//conditions:default": ["@rusty_v8_libcxxabi//:headers"],
|
||||
}),
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rusty_v8_custom_libcxx_runtime",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@rusty_v8_libcxx//:libcxx"] + select({
|
||||
":use_rusty_v8_custom_libcxx_native_windows": [],
|
||||
"//conditions:default": ["@rusty_v8_libcxxabi//:libcxxabi"],
|
||||
}),
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "binding_cc_152_2_0",
|
||||
srcs = ["@v8_crate_152_2_0//:binding_cc"],
|
||||
outs = ["binding_152_2_0.cc"],
|
||||
cmd = " ".join([
|
||||
"sed",
|
||||
"-e '/#include \"v8\\/src\\/flags\\/flags.h\"/d'",
|
||||
"-e 's|\"v8/src/libplatform/default-platform.h\"|\"src/libplatform/default-platform.h\"|'",
|
||||
"-e 's|#include \"support.h\"|#include \"support_152_2_0.h\"|'",
|
||||
"-e 's| namespace i = v8::internal;| (void)usage;|'",
|
||||
"-e '/using HelpOptions = i::FlagList::HelpOptions;/d'",
|
||||
"-e '/HelpOptions help_options = HelpOptions(HelpOptions::kExit, usage);/d'",
|
||||
"-e 's| i::FlagList::SetFlagsFromCommandLine(argc, argv, true, help_options);| v8::V8::SetFlagsFromCommandLine(argc, argv, true);|'",
|
||||
"$(location @v8_crate_152_2_0//:binding_cc)",
|
||||
">",
|
||||
'"$@"',
|
||||
]),
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "crdtp_binding_cc_152_2_0",
|
||||
srcs = ["@v8_crate_152_2_0//:crdtp_binding_cc"],
|
||||
outs = ["crdtp_binding_152_2_0.cc"],
|
||||
cmd = " ".join([
|
||||
"sed",
|
||||
"-e 's|#include \"support.h\"|#include \"support_152_2_0.h\"|'",
|
||||
"-e 's|\"v8/third_party/inspector_protocol/|\"third_party/inspector_protocol/|g'",
|
||||
"$(location @v8_crate_152_2_0//:crdtp_binding_cc)",
|
||||
">",
|
||||
'"$@"',
|
||||
]),
|
||||
)
|
||||
|
||||
copy_file(
|
||||
name = "support_h_152_2_0",
|
||||
src = "@v8_crate_152_2_0//:support_h",
|
||||
out = "support_152_2_0.h",
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "v8_152_2_0_binding",
|
||||
srcs = [
|
||||
":binding_cc_152_2_0",
|
||||
":crdtp_binding_cc_152_2_0",
|
||||
],
|
||||
hdrs = [":support_h_152_2_0"],
|
||||
copts = V8_COPTS + V8_CUSTOM_LIBCXX_COPTS,
|
||||
deps = [
|
||||
"@v8//:core_lib_icu",
|
||||
"@v8//:rusty_v8_crdtp_headers",
|
||||
"@v8//:rusty_v8_internal_headers",
|
||||
] + select({
|
||||
":use_rusty_v8_custom_libcxx": [
|
||||
":rusty_v8_custom_libcxx_headers",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "native_windows_compiler_builtins",
|
||||
actual = "@v8_native_windows_llvm//:builtins",
|
||||
tags = ["manual"],
|
||||
target_compatible_with = select({
|
||||
":platform_windows_msvc": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
)
|
||||
|
||||
# Compile the pinned Chromium libc++ into V8 with the Microsoft CRT.
|
||||
cc_static_library(
|
||||
name = "v8_152_2_0_native_windows_objects",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
tags = ["manual"],
|
||||
target_compatible_with = select({
|
||||
":platform_windows_msvc": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
deps = [
|
||||
":rusty_v8_custom_libcxx_runtime",
|
||||
":v8_152_2_0_binding",
|
||||
],
|
||||
)
|
||||
|
||||
# cc_static_library only collects object files, not prebuilt libraries.
|
||||
# The Rust build script receives one .lib without Bazel's CcInfo/linkdeps, so
|
||||
# merge compiler-rt into the staged artifact explicitly.
|
||||
genrule(
|
||||
name = "v8_152_2_0_native_windows_library",
|
||||
srcs = [
|
||||
":v8_152_2_0_native_windows_objects",
|
||||
"@v8_native_windows_llvm//:builtins_archive",
|
||||
],
|
||||
outs = ["rusty_v8_native_windows.lib"],
|
||||
cmd_bat = '""$(location @v8_native_windows_llvm//:llvm-lib)" /NOLOGO /OUT:"$@" "$(location :v8_152_2_0_native_windows_objects)" "$(location @v8_native_windows_llvm//:builtins_archive)""',
|
||||
tags = ["manual"],
|
||||
target_compatible_with = [
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
tools = ["@v8_native_windows_llvm//:llvm-lib"],
|
||||
)
|
||||
|
||||
[
|
||||
v8_artifact_files(
|
||||
name = "v8_152_2_0_%s_pc_windows_msvc_bazel" % arch,
|
||||
srcs = [":v8_152_2_0_native_windows_library"],
|
||||
profile = "sandbox_release",
|
||||
tags = ["manual"],
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:%s" % arch,
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
v8_cpu = cpu,
|
||||
)
|
||||
for arch, cpu in [
|
||||
("x86_64", "x64"),
|
||||
("aarch64", "arm64"),
|
||||
]
|
||||
]
|
||||
|
||||
# Producer selectors never fall back to published inputs. Keep them separate
|
||||
# from the consumer aliases so a version upgrade can build before publishing.
|
||||
alias(
|
||||
name = "rusty_v8_native_windows_archive_for_target",
|
||||
actual = select({
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": ":v8_152_2_0_aarch64_pc_windows_msvc_bazel",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": ":v8_152_2_0_x86_64_pc_windows_msvc_bazel",
|
||||
}),
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
# Bindgen reads the same CcInfo as the C++ archive. Pass local libc++ options
|
||||
# explicitly because CcInfo propagates defines and headers, but not copts.
|
||||
cc_library(
|
||||
name = "binding_headers_152_2_0",
|
||||
hdrs = [
|
||||
"@v8_crate_152_2_0//:binding_hpp",
|
||||
"@v8_crate_152_2_0//:support_h",
|
||||
],
|
||||
tags = ["manual"],
|
||||
# Bindgen asks the toolchain for C flags, which omit its C++ header search
|
||||
# paths. Source profiles use the workspace headers; release profiles get
|
||||
# their pinned Chromium headers from the profiled binding dependency.
|
||||
deps = [":v8_152_2_0_binding"] + select({
|
||||
":use_rusty_v8_custom_libcxx": [],
|
||||
"@platforms//os:osx": [],
|
||||
"//conditions:default": [
|
||||
"@llvm-project//libcxx:headers",
|
||||
"@llvm-project//libcxxabi:headers",
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
rust_bindgen(
|
||||
name = "binding_generated_152_2_0",
|
||||
bindgen_flags = [
|
||||
"--generate-cstr",
|
||||
"--rustified-enum=.*UseCounterFeature",
|
||||
"--rustified-enum=.*ModuleImportPhase",
|
||||
"--rustified-enum=.*Intercepted",
|
||||
"--bitfield-enum=.*GCType",
|
||||
"--bitfield-enum=.*GCCallbackFlags",
|
||||
"--allowlist-item=v8__.*",
|
||||
"--allowlist-item=cppgc__.*",
|
||||
"--allowlist-item=RustObj",
|
||||
"--allowlist-item=memory_span_t",
|
||||
"--allowlist-item=const_memory_span_t",
|
||||
"--allowlist-item=ExternalConstOneByteStringResource",
|
||||
"--blocklist-item=cppgc.*Visitor",
|
||||
"--blocklist-item=RustObj.*Trace",
|
||||
],
|
||||
cc_lib = ":binding_headers_152_2_0",
|
||||
clang_flags = [
|
||||
"-x",
|
||||
"c++",
|
||||
"-std=c++20",
|
||||
] + V8_CUSTOM_LIBCXX_COPTS + select({
|
||||
# Match the C++ toolchain. Bindgen asks for C flags and otherwise
|
||||
# enables C++20 modules, for which the macOS SDK's types are cyclic.
|
||||
"@platforms//os:osx": [
|
||||
"-Xclang",
|
||||
"-fno-cxx-modules",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@rules_rs//rs/platforms/config:aarch64-apple-darwin": ["--target=arm64-apple-darwin"],
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-gnullvm": ["--target=aarch64-w64-windows-gnu"],
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": ["--target=aarch64-pc-windows-msvc"],
|
||||
"@llvm//platforms/config:linux_aarch64_gnu": ["--target=aarch64-unknown-linux-gnu"],
|
||||
"@llvm//platforms/config:linux_aarch64_musl": ["--target=aarch64-unknown-linux-musl"],
|
||||
"@rules_rs//rs/platforms/config:x86_64-apple-darwin": ["--target=x86_64-apple-darwin"],
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-gnullvm": ["--target=x86_64-w64-windows-gnu"],
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": ["--target=x86_64-pc-windows-msvc"],
|
||||
"@llvm//platforms/config:linux_x86_64_gnu": ["--target=x86_64-unknown-linux-gnu"],
|
||||
"@llvm//platforms/config:linux_x86_64_musl": ["--target=x86_64-unknown-linux-musl"],
|
||||
}),
|
||||
header = "@v8_crate_152_2_0//:binding_hpp",
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_aarch64_pc_windows_msvc_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "sandbox_release",
|
||||
tags = ["manual"],
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:aarch64",
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_x86_64_pc_windows_msvc_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "sandbox_release",
|
||||
tags = ["manual"],
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_aarch64_pc_windows_gnullvm_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "source",
|
||||
tags = ["manual"],
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:aarch64",
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:gnullvm",
|
||||
],
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_x86_64_pc_windows_gnullvm_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "source",
|
||||
tags = ["manual"],
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@llvm//constraints/windows/abi:gnullvm",
|
||||
],
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_aarch64_apple_darwin_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "source",
|
||||
tags = ["manual"],
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_x86_64_apple_darwin_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "source",
|
||||
tags = ["manual"],
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_aarch64_unknown_linux_gnu_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "source",
|
||||
tags = ["manual"],
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_x86_64_unknown_linux_gnu_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "source",
|
||||
tags = ["manual"],
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_aarch64_unknown_linux_musl_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "source",
|
||||
tags = ["manual"],
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "src_binding_x86_64_unknown_linux_musl_152_2_0_bazel",
|
||||
srcs = [":binding_generated_152_2_0"],
|
||||
profile = "source",
|
||||
tags = ["manual"],
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "rusty_v8_native_windows_binding_for_target",
|
||||
actual = select({
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": ":src_binding_aarch64_pc_windows_msvc_152_2_0_bazel",
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": ":src_binding_x86_64_pc_windows_msvc_152_2_0_bazel",
|
||||
}),
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "_v8_152_2_0_aarch64_apple_darwin_bazel",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":rusty_v8_custom_libcxx_runtime",
|
||||
":v8_152_2_0_binding",
|
||||
],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "_v8_152_2_0_aarch64_unknown_linux_gnu_bazel_base",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":rusty_v8_custom_libcxx_runtime",
|
||||
":v8_152_2_0_binding",
|
||||
],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "_v8_152_2_0_aarch64_pc_windows_gnullvm_bazel",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [":v8_152_2_0_binding"],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "_v8_152_2_0_aarch64_unknown_linux_musl_release_base",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":rusty_v8_custom_libcxx_runtime",
|
||||
":v8_152_2_0_binding",
|
||||
],
|
||||
)
|
||||
|
||||
# Rust's compiler-builtins omit __clear_cache on ARM64 Linux, while V8 calls
|
||||
# it to flush generated code. Carry compiler-rt in both native archive inputs.
|
||||
# llvm-ar's L modifier merges archive members; s writes the symbol index.
|
||||
genrule(
|
||||
name = "_v8_152_2_0_aarch64_unknown_linux_gnu_bazel",
|
||||
srcs = [
|
||||
":_v8_152_2_0_aarch64_unknown_linux_gnu_bazel_base",
|
||||
"@llvm//runtimes/compiler-rt:clang_rt.builtins.static",
|
||||
],
|
||||
outs = ["libv8_152_2_0_aarch64_unknown_linux_gnu.a"],
|
||||
cmd = '$(location @llvm//tools:llvm-ar) qcsL "$@" $(SRCS)',
|
||||
tools = ["@llvm//tools:llvm-ar"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "_v8_152_2_0_aarch64_unknown_linux_musl_release",
|
||||
srcs = [
|
||||
":_v8_152_2_0_aarch64_unknown_linux_musl_release_base",
|
||||
"@llvm//runtimes/compiler-rt:clang_rt.builtins.static",
|
||||
],
|
||||
outs = ["libv8_152_2_0_aarch64_unknown_linux_musl.a"],
|
||||
cmd = '$(location @llvm//tools:llvm-ar) qcsL "$@" $(SRCS)',
|
||||
tools = ["@llvm//tools:llvm-ar"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "_v8_152_2_0_x86_64_apple_darwin_bazel",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":rusty_v8_custom_libcxx_runtime",
|
||||
":v8_152_2_0_binding",
|
||||
],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "_v8_152_2_0_x86_64_unknown_linux_gnu_bazel",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":rusty_v8_custom_libcxx_runtime",
|
||||
":v8_152_2_0_binding",
|
||||
],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "_v8_152_2_0_x86_64_pc_windows_gnullvm_bazel",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [":v8_152_2_0_binding"],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "_v8_152_2_0_x86_64_unknown_linux_musl_release",
|
||||
features = V8_STATIC_LIBRARY_FEATURES,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":rusty_v8_custom_libcxx_runtime",
|
||||
":v8_152_2_0_binding",
|
||||
],
|
||||
)
|
||||
|
||||
# Local source producers match the Rust consumer's sandbox ABI, and use the
|
||||
# workspace C++ runtime. Release pairs below select pinned Chromium libc++ and
|
||||
# build the private source nodes directly under their own profiles.
|
||||
[
|
||||
v8_artifact_files(
|
||||
name = name,
|
||||
srcs = [":_" + name],
|
||||
profile = "source",
|
||||
v8_cpu = cpu,
|
||||
)
|
||||
for name, cpu in [
|
||||
("v8_152_2_0_aarch64_apple_darwin_bazel", "arm64"),
|
||||
("v8_152_2_0_aarch64_unknown_linux_gnu_bazel", "arm64"),
|
||||
("v8_152_2_0_aarch64_pc_windows_gnullvm_bazel", "arm64"),
|
||||
("v8_152_2_0_aarch64_unknown_linux_musl_release", "arm64"),
|
||||
("v8_152_2_0_x86_64_apple_darwin_bazel", "x64"),
|
||||
("v8_152_2_0_x86_64_unknown_linux_gnu_bazel", "x64"),
|
||||
("v8_152_2_0_x86_64_pc_windows_gnullvm_bazel", "x64"),
|
||||
("v8_152_2_0_x86_64_unknown_linux_musl_release", "x64"),
|
||||
]
|
||||
]
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_release_pair_x86_64_apple_darwin",
|
||||
srcs = [
|
||||
":_v8_152_2_0_x86_64_apple_darwin_bazel",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "release",
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_release_pair_aarch64_apple_darwin",
|
||||
srcs = [
|
||||
":_v8_152_2_0_aarch64_apple_darwin_bazel",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "release",
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_release_pair_x86_64_unknown_linux_gnu",
|
||||
srcs = [
|
||||
":_v8_152_2_0_x86_64_unknown_linux_gnu_bazel",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "release",
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_release_pair_aarch64_unknown_linux_gnu",
|
||||
srcs = [
|
||||
":_v8_152_2_0_aarch64_unknown_linux_gnu_bazel",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "release",
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_release_pair_x86_64_unknown_linux_musl",
|
||||
srcs = [
|
||||
":_v8_152_2_0_x86_64_unknown_linux_musl_release",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "release",
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_release_pair_aarch64_unknown_linux_musl",
|
||||
srcs = [
|
||||
":_v8_152_2_0_aarch64_unknown_linux_musl_release",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "release",
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "rusty_v8_release_pair_x86_64_pc_windows_msvc",
|
||||
srcs = [
|
||||
":v8_152_2_0_x86_64_pc_windows_msvc",
|
||||
"@rusty_v8_152_2_0_x86_64_pc_windows_msvc_binding//file",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "rusty_v8_release_pair_aarch64_pc_windows_msvc",
|
||||
srcs = [
|
||||
":v8_152_2_0_aarch64_pc_windows_msvc",
|
||||
"@rusty_v8_152_2_0_aarch64_pc_windows_msvc_binding//file",
|
||||
],
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_sandbox_release_pair_x86_64_apple_darwin",
|
||||
srcs = [
|
||||
":_v8_152_2_0_x86_64_apple_darwin_bazel",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "sandbox_release",
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_sandbox_release_pair_aarch64_apple_darwin",
|
||||
srcs = [
|
||||
":_v8_152_2_0_aarch64_apple_darwin_bazel",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "sandbox_release",
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_sandbox_release_pair_x86_64_unknown_linux_gnu",
|
||||
srcs = [
|
||||
":_v8_152_2_0_x86_64_unknown_linux_gnu_bazel",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "sandbox_release",
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_sandbox_release_pair_aarch64_unknown_linux_gnu",
|
||||
srcs = [
|
||||
":_v8_152_2_0_aarch64_unknown_linux_gnu_bazel",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "sandbox_release",
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_sandbox_release_pair_x86_64_unknown_linux_musl",
|
||||
srcs = [
|
||||
":_v8_152_2_0_x86_64_unknown_linux_musl_release",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "sandbox_release",
|
||||
v8_cpu = "x64",
|
||||
)
|
||||
|
||||
v8_artifact_files(
|
||||
name = "rusty_v8_sandbox_release_pair_aarch64_unknown_linux_musl",
|
||||
srcs = [
|
||||
":_v8_152_2_0_aarch64_unknown_linux_musl_release",
|
||||
":binding_generated_152_2_0",
|
||||
],
|
||||
profile = "sandbox_release",
|
||||
v8_cpu = "arm64",
|
||||
)
|
||||
271
third_party/v8/README.md
vendored
Normal file
271
third_party/v8/README.md
vendored
Normal file
@@ -0,0 +1,271 @@
|
||||
# `rusty_v8` Consumer Artifacts
|
||||
|
||||
This directory wires the `v8` crate to exact-version Bazel inputs. Bazel
|
||||
consumers build V8 archives from source and generate matching Rust bindings on
|
||||
Darwin, GNU/musl Linux, and Windows MSVC/GNU. `MODULE.bazel` wires
|
||||
`RUSTY_V8_ARCHIVE` and `RUSTY_V8_SRC_BINDING_PATH` to the `@v8_targets` copy of
|
||||
these consumer-facing selectors:
|
||||
|
||||
- `//third_party/v8:rusty_v8_archive_for_target`
|
||||
- `//third_party/v8:rusty_v8_binding_for_target`
|
||||
|
||||
The Bazel `v8` crate and its native source targets enable V8's in-process
|
||||
sandbox and pointer compression.
|
||||
|
||||
Local Cargo builds still use upstream prebuilt `rusty_v8` archives by default.
|
||||
Selected Cargo CI, release, and package builds override
|
||||
`RUSTY_V8_ARCHIVE`/`RUSTY_V8_SRC_BINDING_PATH` with Codex release assets.
|
||||
|
||||
Source targets enforce the workspace runtime and sandbox/pointer-compression
|
||||
ABI. Release-pair targets enforce either the legacy or sandbox ABI plus
|
||||
Chromium's pinned runtime. Target CPU follows the named artifact. These V8
|
||||
settings are internal; callers do not pass separate V8 feature or libc++ flags.
|
||||
|
||||
Current pinned versions:
|
||||
|
||||
- Rust crate: `v8 = =152.2.0`
|
||||
- Embedded upstream V8 source for Bazel builds: `15.2.124.1`
|
||||
|
||||
## Updating to a new `v8` release
|
||||
|
||||
Use this as the maintainer flow for a version bump:
|
||||
|
||||
1. Bump the `v8` crate version and refresh `codex-rs/Cargo.lock`.
|
||||
2. Update the Bazel versioned inputs in `MODULE.bazel` and the source pins
|
||||
in `third_party/v8/dependencies.bzl` and `abseil_repository.bzl` using
|
||||
[the source dependency update procedure](#updating-source-dependencies).
|
||||
Verify the imported source groups by querying the source archive and generating Torque
|
||||
and snapshots for each supported platform. If V8 changes its BUILD section
|
||||
layout, the importer fails instead of silently using an old inventory;
|
||||
update that boundary and review its fixed feature and CPU selections.
|
||||
Then refresh the matching checksum manifest and generated checksums below.
|
||||
3. Publish a release-candidate PR and validate that `v8-canary` passes.
|
||||
4. If the canary is green, publish the release tag and release build.
|
||||
5. Independently verify the published Codex-built checksum manifests and record
|
||||
their SHA-256 digests in
|
||||
`third_party/v8/rusty_v8_<version>_release_manifests.sha256`.
|
||||
6. Once the release build completes, rerun the build on the candidate branch
|
||||
and verify that the final artifact builds and tests pass.
|
||||
|
||||
When changing the prebuilt `rusty_v8` `http_file` inputs, keep the
|
||||
checked-in checksum manifest and `MODULE.bazel` in sync:
|
||||
|
||||
```bash
|
||||
python3 .github/scripts/rusty_v8_bazel.py update-module-bazel
|
||||
python3 .github/scripts/rusty_v8_bazel.py check-module-bazel
|
||||
```
|
||||
|
||||
For all eight published pairs, verify each published
|
||||
`rusty_v8_ptrcomp_sandbox_release_<target>.sha256` against the committed
|
||||
`rusty_v8_<version>_release_manifests.sha256` first. Copy the verified archive
|
||||
and binding checksums into `rusty_v8_<version>.sha256`, then run these
|
||||
commands. They validate every matching `http_file` entry, and CI blocks
|
||||
checksum drift.
|
||||
|
||||
Published release assets are expected at the tag:
|
||||
|
||||
- `rusty-v8-v<crate_version>`
|
||||
|
||||
with these raw asset names:
|
||||
|
||||
- `librusty_v8_release_<target>.a.gz`
|
||||
- `src_binding_release_<target>.rs`
|
||||
|
||||
During the sandbox rollout, sandbox-enabled assets are published alongside those
|
||||
current assets on the same tag, with the Rust crate's sandbox feature suffix in
|
||||
their raw names:
|
||||
|
||||
- `librusty_v8_ptrcomp_sandbox_release_<target>.a.gz`
|
||||
- `rusty_v8_ptrcomp_sandbox_release_<target>.lib.gz` on Windows MSVC
|
||||
- `src_binding_ptrcomp_sandbox_release_<target>.rs`
|
||||
|
||||
The dedicated publishing workflow is `.github/workflows/rusty-v8-release.yml`.
|
||||
Tagged runs build release artifacts from the Bazel graph itself:
|
||||
|
||||
- `//third_party/v8:rusty_v8_release_pair_x86_64_apple_darwin`
|
||||
- `//third_party/v8:rusty_v8_release_pair_aarch64_apple_darwin`
|
||||
- `//third_party/v8:rusty_v8_release_pair_x86_64_unknown_linux_gnu`
|
||||
- `//third_party/v8:rusty_v8_release_pair_aarch64_unknown_linux_gnu`
|
||||
- `//third_party/v8:rusty_v8_release_pair_x86_64_unknown_linux_musl`
|
||||
- `//third_party/v8:rusty_v8_release_pair_aarch64_unknown_linux_musl`
|
||||
|
||||
The same run also builds the matching sandbox pair targets:
|
||||
|
||||
- `//third_party/v8:rusty_v8_sandbox_release_pair_x86_64_apple_darwin`
|
||||
- `//third_party/v8:rusty_v8_sandbox_release_pair_aarch64_apple_darwin`
|
||||
- `//third_party/v8:rusty_v8_sandbox_release_pair_x86_64_unknown_linux_gnu`
|
||||
- `//third_party/v8:rusty_v8_sandbox_release_pair_aarch64_unknown_linux_gnu`
|
||||
- `//third_party/v8:rusty_v8_sandbox_release_pair_x86_64_unknown_linux_musl`
|
||||
- `//third_party/v8:rusty_v8_sandbox_release_pair_aarch64_unknown_linux_musl`
|
||||
|
||||
The workflow also builds sandbox-enabled
|
||||
`x86_64-pc-windows-msvc` and `aarch64-pc-windows-msvc` archive/binding pairs
|
||||
from upstream `rusty_v8` source. Those ABI-specific outputs cannot be produced
|
||||
by Codex's Bazel Windows GNU toolchain.
|
||||
|
||||
The Bazel graph pins the same libc++, libc++abi, and llvm-libc source revisions
|
||||
used by `rusty_v8 v152.2.0`. The named release and sandbox-release pair targets
|
||||
select those headers and fold the matching runtime objects into the final static
|
||||
archive so consumers can link it with the `v8` crate's default
|
||||
`use_custom_libcxx` feature. The profile keeps the object files and the bundled
|
||||
runtime on Chromium's `std::__Cr` ABI namespace instead of mixing those objects
|
||||
with the toolchain libc++ default namespace. Selected Cargo release and package
|
||||
builds use these published archives. The explicit Bazel prebuilt archive targets
|
||||
remain available; on Linux, they decompress to a private output and weaken
|
||||
the ten shared `std::logic_error` and `std::runtime_error` constructors and
|
||||
assignment entry points listed in `gnu_libcxx_shared_exception_symbols.txt`.
|
||||
libc++ keeps these exception functions in `std::` across inline ABI namespaces;
|
||||
the toolchain's definitions then take precedence if both runtimes are linked.
|
||||
Constructors accepting Chromium's `std::__Cr::string` remain strong in the V8
|
||||
archive. The verified input and the producer's archive are never mutated.
|
||||
This depends on libc++'s shared exception-object ABI; updates to either libc++
|
||||
revision must keep the native GNU link/runtime checks passing. The Bazel pair
|
||||
targets above point directly to source targets so a new release or canary never
|
||||
depends on an older published copy.
|
||||
|
||||
Native Windows x64 and ARM64 hosts can build sandbox archives and matching
|
||||
Rust bindings with pinned clang-cl and the installed Microsoft SDK using
|
||||
`//third_party/v8:v8_152_2_0_x86_64_pc_windows_msvc_bazel` and
|
||||
`//third_party/v8:v8_152_2_0_aarch64_pc_windows_msvc_bazel`.
|
||||
The producer selectors `//third_party/v8:rusty_v8_native_windows_archive_for_target`
|
||||
and `//third_party/v8:rusty_v8_native_windows_binding_for_target` select source
|
||||
outputs directly. Both use the same sandbox, pointer compression, target CPU,
|
||||
and Chromium libc++ profile. The bindings use V8's compiled headers and defines
|
||||
so their sizes follow the archive, including CppGC members. Bazel MSVC consumers
|
||||
use the newly built archive and bindings together.
|
||||
|
||||
The owned engine policy preserves the GN MSVC defaults for GC-managed microtask
|
||||
queues, random Wasm module generation, disabled imminent-deprecation warnings,
|
||||
and external TypedArray backing stores. Other source targets retain the published
|
||||
Unix policy, including a 64-byte inline TypedArray threshold. Generated Rust
|
||||
bindings use that same threshold; never pair a native 64-byte threshold with
|
||||
GN's size-zero binding constant. These are fixed platform choices, not additional
|
||||
developer build switches.
|
||||
|
||||
Use a native Visual Studio Developer PowerShell with the C++ tools and Windows
|
||||
SDK available. The SDK supplies headers, libraries, `dumpbin.exe`, and the
|
||||
assembler. From the repo root, build the archive for that host:
|
||||
|
||||
```powershell
|
||||
bazel build --config=ci-windows-msvc `
|
||||
--host_platform=//:local_windows_msvc --platforms=//:local_windows_msvc `
|
||||
//third_party/v8:rusty_v8_native_windows_archive_for_target `
|
||||
//third_party/v8:rusty_v8_native_windows_binding_for_target
|
||||
```
|
||||
|
||||
Bazel fetches and verifies LLVM 22.1.8 for the host, the same major and patch
|
||||
version as the libclang that generates bindings. The V8 artifact profile selects
|
||||
clang-cl, lld-link, llvm-lib and compiler-rt only for its Windows MSVC source
|
||||
archive and bindings, together with the installed SDK. Bazel consumers now
|
||||
cross this same boundary automatically. Other C++
|
||||
dependencies in the same `ci-windows-msvc` build keep the installed MSVC
|
||||
compiler; no whole-build V8 compiler flag is needed.
|
||||
|
||||
This is a native Windows build, not an x64-to-ARM64 or remote Linux build:
|
||||
V8's snapshot generator must execute on the target architecture. The repository
|
||||
inputs pinned in #4009 are MSVC/SDK files, not a registered clang-cl toolchain;
|
||||
making them replace the installed SDK is the separate hermetic MSVC migration.
|
||||
|
||||
Release and CI Cargo builds for Darwin and Linux use `RUSTY_V8_ARCHIVE` plus a
|
||||
downloaded `RUSTY_V8_SRC_BINDING_PATH` to point at those `openai/codex` release
|
||||
assets directly. We do not use `RUSTY_V8_MIRROR` because the upstream `v8` crate
|
||||
hardcodes a `v<crate_version>` tag layout, while our artifacts are published
|
||||
under `rusty-v8-v<crate_version>`.
|
||||
|
||||
Do not mix artifacts across crate versions. The archive and binding must match
|
||||
the exact resolved `v8` crate version in `codex-rs/Cargo.lock`.
|
||||
|
||||
## Source dependency ownership
|
||||
|
||||
The Darwin, Linux GNU/musl and Windows source targets consume Codex-owned
|
||||
Abseil, Highway, simdutf, ICU, fast_float, dragonbox and fp16 repositories.
|
||||
`dependencies.bzl` declares the pinned imports; the `*.BUILD.bazel` overlays
|
||||
here declare the targets V8 uses. Abseil, Highway and simdutf apply their C++ runtime
|
||||
settings through `dependency_config.bzl`; ICU defines its settings in its own
|
||||
overlay.
|
||||
|
||||
`engine_repository.bzl` fetches the V8 source pin and installs Codex's engine
|
||||
BUILD into `@v8`. Source filegroups are read from the pinned upstream BUILD
|
||||
each fetch, including added, removed or reordered groups. The importer rejects
|
||||
missing boundaries, malformed or empty sections, and new compiled targets. Only
|
||||
the two known Dragonbox and FP16 declarations are skipped, since the dependency
|
||||
overlays already supply them. `v8_binary` is valid V8 syntax, but compiled targets
|
||||
must be reviewed against the owned engine BUILD on an upgrade.
|
||||
The upstream `bazel/config` platform and CPU package is reused; only the CPU
|
||||
setting changes from a CLI flag to an internal setting. `v8_defs.patch` records
|
||||
that change and the Codex differences to upstream's `bazel/defs.bzl`:
|
||||
internal ABI/runtime settings, their visibility, libc++ headers/runtime, Windows
|
||||
compiler and linker settings, and snapshot generation. All engine rules,
|
||||
including Torque and V8's test configuration helpers, load from that file.
|
||||
The engine BUILD owns feature policy and dependency targets. ABI, runtime and
|
||||
CPU settings are selected together by `artifact_profile.bzl` for source and
|
||||
release-pair targets.
|
||||
|
||||
V8's private Abseil is built from the pinned 20250814.1 sources and uses
|
||||
`codex_v8_lts_20250814` for its supported inline-namespace option. Protobuf
|
||||
keeps the regular shared Abseil module and its `lts_20250814` namespace.
|
||||
Both can link into one binary without interposing functions built for different
|
||||
C++ runtimes. No V8 dependency needs a hook in shared `rules_cc` libraries.
|
||||
|
||||
### Updating source dependencies
|
||||
|
||||
These are reviewed with each V8 source upgrade. There is no source-pin
|
||||
autoupdater: the prebuilt checksum commands above and their CI check validate
|
||||
published archive/binding pairs, not these source revisions. Bazel verifies
|
||||
the declared download hashes and Git revisions; it does not choose them for us.
|
||||
|
||||
Use the V8 tag in the root `MODULE.bazel` `engine_repository(name = "v8")`
|
||||
(currently `15.2.124.1`) as the input. Read that tag's **unpatched** `DEPS`
|
||||
and `MODULE.bazel`; `@v8` deliberately does not include upstream's MODULE.
|
||||
On an upgrade, also review `v8_defs.patch` against the new `bazel/defs.bzl`
|
||||
and run the V8 source canary. A cleanly applying patch does not by itself
|
||||
verify new upstream defaults or code-generation behavior.
|
||||
|
||||
```bash
|
||||
v8_tag=15.2.124.1 # Replace with the V8 source tag selected for this upgrade.
|
||||
gh api "repos/v8/v8/contents/DEPS?ref=$v8_tag" \
|
||||
-H 'Accept: application/vnd.github.raw+json' |
|
||||
rg -n -A 2 "'third_party/(highway/src|icu|dragonbox/src|fp16/src|fast_float/src|simdutf)'"
|
||||
gh api "repos/v8/v8/contents/MODULE.bazel?ref=$v8_tag" \
|
||||
-H 'Accept: application/vnd.github.raw+json' | rg 'bazel_dep\(name = "abseil-cpp"'
|
||||
```
|
||||
|
||||
- `v8_highway`, `v8_icu`, `v8_dragonbox`, `v8_fp16`: copy the respective
|
||||
DEPS commits. For Highway, use that commit in the archive URL and strip prefix.
|
||||
- `v8_fast_float`: use the DEPS commit. If selecting a release-tag archive,
|
||||
verify the tag resolves to that commit, e.g.
|
||||
`gh api repos/fastfloat/fast_float/git/ref/tags/v8.2.10 --jq '.object'`
|
||||
(dereference annotated tags). Current v8.2.10 equals DEPS commit `34164f5`.
|
||||
- `v8_simdutf`: DEPS points at a Chromium vendoring repo, not the simdutf
|
||||
source repo. Read the metadata at that DEPS commit:
|
||||
|
||||
```bash
|
||||
simdutf_chromium=f7356eed293f8208c40b3c1b344a50bd70971983 # from new DEPS
|
||||
curl -fsSL "https://chromium.googlesource.com/chromium/src/third_party/simdutf/+/$simdutf_chromium/README.chromium?format=TEXT" |
|
||||
base64 -d
|
||||
```
|
||||
|
||||
Match its `Version:` to the upstream release tag and inspect Chromium's
|
||||
local changes before accepting the source form. Chromium vendors amalgamated
|
||||
files; we build upstream `src/simdutf.cpp`. At the current pin it reports
|
||||
7.7.0, but its `Revision: da645ece` predates the v7.7.0 tag. This is a
|
||||
version match, not an assertion that the repositories' commits or bytes match.
|
||||
- `v8_abseil`: follow `abseil-cpp` in V8's unpatched MODULE, not its Chromium
|
||||
DEPS vendor revision. Refresh `abseil_repository.bzl` release archive and
|
||||
its guarded inline namespace together; the V8 namespace must stay private.
|
||||
|
||||
For each `http_archive`/`download_and_extract` source, hash the exact new
|
||||
URL, not a different archive of the same commit:
|
||||
|
||||
```bash
|
||||
source_url='https://github.com/google/highway/archive/2607d3b5b0113992fe84d3848859eae13b3b52c1.tar.gz'
|
||||
curl -fsSL "$source_url" | shasum -a 256
|
||||
# For an integrity= field (Abseil) instead:
|
||||
curl -fsSL "$source_url" | openssl dgst -sha256 -binary | openssl base64 -A
|
||||
```
|
||||
|
||||
Record the hex digest in `sha256`, or prefix the base64 digest with `sha256-`
|
||||
for `integrity`. Review each matching BUILD overlay against its stated source,
|
||||
then build the V8 generator and source/archive targets on supported platforms.
|
||||
The regular V8 canary/release checks validate the resulting engine; they do not
|
||||
prove upstream-version equivalence for a substituted source.
|
||||
294
third_party/v8/abseil.BUILD.bazel
vendored
Normal file
294
third_party/v8/abseil.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,294 @@
|
||||
# Codex-owned build of the eight Abseil entry points V8 15.2.124.1 uses.
|
||||
# Sources are from their transitive closure in Abseil 20250814.1's BUILD files.
|
||||
# Share headers, but compile runtime objects only when a caller needs them.
|
||||
# Keep non-Cord strings below time/synchronization: Cord depends on both.
|
||||
load("@@//third_party/v8:dependency_config.bzl", "RUSTY_V8_DEPENDENCY_COPTS", "RUSTY_V8_DEPENDENCY_DEPS")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"]) # Apache-2.0
|
||||
|
||||
exports_files(["LICENSE"])
|
||||
|
||||
config_setting(
|
||||
name = "windows",
|
||||
constraint_values = ["@platforms//os:windows"],
|
||||
)
|
||||
|
||||
# Include the OS constraint so these settings refine :windows in selects.
|
||||
config_setting(
|
||||
name = "windows_msvc",
|
||||
constraint_values = ["@platforms//os:windows"],
|
||||
flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "windows_clang_cl",
|
||||
constraint_values = ["@platforms//os:windows"],
|
||||
flag_values = {"@bazel_tools//tools/cpp:compiler": "clang-cl"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "windows_lexan",
|
||||
constraint_values = ["@platforms//os:windows"],
|
||||
flag_values = {"@bazel_tools//tools/cpp:compiler": "lexan"},
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "headers",
|
||||
hdrs = glob(
|
||||
["absl/**/*.h"],
|
||||
exclude = [
|
||||
"absl/**/*_test*.h",
|
||||
"absl/**/testdata/**",
|
||||
],
|
||||
),
|
||||
# Abseil offers a supported control for this. GNU Windows needs the same
|
||||
# C++11 TLS path as native Windows; avoid patching thread_identity.h.
|
||||
defines = select({
|
||||
":windows": ["ABSL_FORCE_THREAD_IDENTITY_MODE=ABSL_THREAD_IDENTITY_MODE_USE_CPP11"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
features = ["-module_maps"],
|
||||
includes = [
|
||||
".",
|
||||
"absl/time/internal/cctz/include",
|
||||
],
|
||||
linkopts = select({
|
||||
":windows_msvc": [
|
||||
"advapi32.lib",
|
||||
"dbghelp.lib",
|
||||
],
|
||||
":windows_clang_cl": [
|
||||
"advapi32.lib",
|
||||
"dbghelp.lib",
|
||||
],
|
||||
":windows_lexan": [
|
||||
"advapi32.lib",
|
||||
"dbghelp.lib",
|
||||
],
|
||||
":windows": [
|
||||
"-ladvapi32",
|
||||
"-ldbghelp",
|
||||
],
|
||||
"//conditions:default": ["-pthread"],
|
||||
}),
|
||||
textual_hdrs = glob(["absl/**/*.inc"]),
|
||||
visibility = ["//visibility:private"],
|
||||
deps = RUSTY_V8_DEPENDENCY_DEPS,
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "base",
|
||||
srcs = [
|
||||
"absl/base/internal/cycleclock.cc",
|
||||
"absl/base/internal/low_level_alloc.cc",
|
||||
"absl/base/internal/raw_logging.cc",
|
||||
"absl/base/internal/spinlock.cc",
|
||||
"absl/base/internal/spinlock_wait.cc",
|
||||
"absl/base/internal/sysinfo.cc",
|
||||
"absl/base/internal/thread_identity.cc",
|
||||
"absl/base/internal/throw_delegate.cc",
|
||||
"absl/base/internal/tracing.cc",
|
||||
"absl/base/internal/unscaledcycleclock.cc",
|
||||
"absl/base/log_severity.cc",
|
||||
"absl/numeric/int128.cc",
|
||||
],
|
||||
copts = RUSTY_V8_DEPENDENCY_COPTS,
|
||||
features = ["-module_maps"],
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":headers",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "strings",
|
||||
srcs = [
|
||||
"absl/strings/ascii.cc",
|
||||
"absl/strings/charconv.cc",
|
||||
"absl/strings/escaping.cc",
|
||||
"absl/strings/internal/charconv_bigint.cc",
|
||||
"absl/strings/internal/charconv_parse.cc",
|
||||
"absl/strings/internal/damerau_levenshtein_distance.cc",
|
||||
"absl/strings/internal/escaping.cc",
|
||||
"absl/strings/internal/memutil.cc",
|
||||
"absl/strings/internal/ostringstream.cc",
|
||||
"absl/strings/internal/str_format/arg.cc",
|
||||
"absl/strings/internal/str_format/bind.cc",
|
||||
"absl/strings/internal/str_format/extension.cc",
|
||||
"absl/strings/internal/str_format/float_conversion.cc",
|
||||
"absl/strings/internal/str_format/output.cc",
|
||||
"absl/strings/internal/str_format/parser.cc",
|
||||
"absl/strings/internal/stringify_sink.cc",
|
||||
"absl/strings/internal/utf8.cc",
|
||||
"absl/strings/match.cc",
|
||||
"absl/strings/numbers.cc",
|
||||
"absl/strings/str_cat.cc",
|
||||
"absl/strings/str_replace.cc",
|
||||
"absl/strings/str_split.cc",
|
||||
"absl/strings/string_view.cc",
|
||||
"absl/strings/substitute.cc",
|
||||
],
|
||||
copts = RUSTY_V8_DEPENDENCY_COPTS,
|
||||
features = ["-module_maps"],
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":base",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "time",
|
||||
srcs = [
|
||||
"absl/time/civil_time.cc",
|
||||
"absl/time/clock.cc",
|
||||
"absl/time/duration.cc",
|
||||
"absl/time/format.cc",
|
||||
"absl/time/internal/cctz/src/civil_time_detail.cc",
|
||||
"absl/time/internal/cctz/src/time_zone_fixed.cc",
|
||||
"absl/time/internal/cctz/src/time_zone_format.cc",
|
||||
"absl/time/internal/cctz/src/time_zone_if.cc",
|
||||
"absl/time/internal/cctz/src/time_zone_impl.cc",
|
||||
"absl/time/internal/cctz/src/time_zone_info.cc",
|
||||
"absl/time/internal/cctz/src/time_zone_libc.cc",
|
||||
"absl/time/internal/cctz/src/time_zone_lookup.cc",
|
||||
"absl/time/internal/cctz/src/time_zone_posix.cc",
|
||||
"absl/time/internal/cctz/src/zone_info_source.cc",
|
||||
"absl/time/time.cc",
|
||||
],
|
||||
copts = RUSTY_V8_DEPENDENCY_COPTS,
|
||||
features = ["-module_maps"],
|
||||
deps = [
|
||||
":strings",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "synchronization",
|
||||
srcs = [
|
||||
"absl/debugging/internal/address_is_readable.cc",
|
||||
"absl/debugging/internal/decode_rust_punycode.cc",
|
||||
"absl/debugging/internal/demangle.cc",
|
||||
"absl/debugging/internal/demangle_rust.cc",
|
||||
"absl/debugging/internal/elf_mem_image.cc",
|
||||
"absl/debugging/internal/utf8_for_code_point.cc",
|
||||
"absl/debugging/internal/vdso_support.cc",
|
||||
"absl/debugging/stacktrace.cc",
|
||||
"absl/debugging/symbolize.cc",
|
||||
"absl/synchronization/barrier.cc",
|
||||
"absl/synchronization/blocking_counter.cc",
|
||||
"absl/synchronization/internal/create_thread_identity.cc",
|
||||
"absl/synchronization/internal/futex_waiter.cc",
|
||||
"absl/synchronization/internal/graphcycles.cc",
|
||||
"absl/synchronization/internal/kernel_timeout.cc",
|
||||
"absl/synchronization/internal/per_thread_sem.cc",
|
||||
"absl/synchronization/internal/pthread_waiter.cc",
|
||||
"absl/synchronization/internal/sem_waiter.cc",
|
||||
"absl/synchronization/internal/stdcpp_waiter.cc",
|
||||
"absl/synchronization/internal/waiter_base.cc",
|
||||
"absl/synchronization/internal/win32_waiter.cc",
|
||||
"absl/synchronization/mutex.cc",
|
||||
"absl/synchronization/notification.cc",
|
||||
],
|
||||
copts = RUSTY_V8_DEPENDENCY_COPTS,
|
||||
features = ["-module_maps"],
|
||||
deps = [
|
||||
":time",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cord",
|
||||
srcs = [
|
||||
"absl/crc/crc32c.cc",
|
||||
"absl/crc/internal/cpu_detect.cc",
|
||||
"absl/crc/internal/crc.cc",
|
||||
"absl/crc/internal/crc_cord_state.cc",
|
||||
"absl/crc/internal/crc_memcpy_fallback.cc",
|
||||
"absl/crc/internal/crc_memcpy_x86_arm_combined.cc",
|
||||
"absl/crc/internal/crc_non_temporal_memcpy.cc",
|
||||
"absl/crc/internal/crc_x86_arm_combined.cc",
|
||||
"absl/profiling/internal/exponential_biased.cc",
|
||||
"absl/strings/cord.cc",
|
||||
"absl/strings/cord_analysis.cc",
|
||||
"absl/strings/internal/cord_internal.cc",
|
||||
"absl/strings/internal/cord_rep_btree.cc",
|
||||
"absl/strings/internal/cord_rep_btree_navigator.cc",
|
||||
"absl/strings/internal/cord_rep_btree_reader.cc",
|
||||
"absl/strings/internal/cord_rep_consume.cc",
|
||||
"absl/strings/internal/cord_rep_crc.cc",
|
||||
"absl/strings/internal/cordz_functions.cc",
|
||||
"absl/strings/internal/cordz_handle.cc",
|
||||
"absl/strings/internal/cordz_info.cc",
|
||||
],
|
||||
copts = RUSTY_V8_DEPENDENCY_COPTS,
|
||||
features = ["-module_maps"],
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":strings",
|
||||
":synchronization",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "hash_containers",
|
||||
srcs = [
|
||||
"absl/container/internal/hashtablez_sampler.cc",
|
||||
"absl/container/internal/hashtablez_sampler_force_weak_definition.cc",
|
||||
"absl/container/internal/raw_hash_set.cc",
|
||||
"absl/hash/internal/city.cc",
|
||||
"absl/hash/internal/hash.cc",
|
||||
],
|
||||
copts = RUSTY_V8_DEPENDENCY_COPTS,
|
||||
features = ["-module_maps"],
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":cord",
|
||||
":synchronization",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "btree",
|
||||
deps = [":cord"],
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "overload",
|
||||
actual = ":headers",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "flat_hash_map",
|
||||
actual = ":hash_containers",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "flat_hash_set",
|
||||
actual = ":hash_containers",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "node_hash_map",
|
||||
actual = ":hash_containers",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "node_hash_set",
|
||||
actual = ":hash_containers",
|
||||
)
|
||||
|
||||
# Compatibility for the engine graph further up the V8 build stack. The
|
||||
# individual V8 targets in this layer use the narrower entry points above.
|
||||
cc_library(
|
||||
name = "abseil",
|
||||
deps = [
|
||||
":btree",
|
||||
":flat_hash_map",
|
||||
":overload",
|
||||
":synchronization",
|
||||
":time",
|
||||
],
|
||||
)
|
||||
57
third_party/v8/abseil_repository.bzl
vendored
Normal file
57
third_party/v8/abseil_repository.bzl
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
"""Source-only, private Abseil build for V8.
|
||||
|
||||
Abseil's inline namespace is deliberately set in options.h, not a command line
|
||||
override: upstream's options header defines it unconditionally. That file is
|
||||
Abseil's supported build configuration interface for packagers. Namespace all
|
||||
of the V8 copy (including its public headers) identically so it can coexist in
|
||||
the same binary with the shared Abseil module compiled for protobuf.
|
||||
"""
|
||||
|
||||
def _v8_abseil_repository_impl(repository_ctx):
|
||||
repository_ctx.download_and_extract(
|
||||
url = "https://github.com/abseil/abseil-cpp/releases/download/20250814.1/abseil-cpp-20250814.1.tar.gz",
|
||||
integrity = "sha256-FpL3fRc5us8/lDNxiLeFg88JurfkINLcbFYFpPhnhaE=",
|
||||
stripPrefix = "abseil-cpp-20250814.1",
|
||||
)
|
||||
|
||||
# Our root BUILD must own all sources beneath absl/. Native Starlark
|
||||
# filesystem operations work on Windows as well; no shell or Python.
|
||||
directories = [repository_ctx.path("absl")]
|
||||
for _ in range(32):
|
||||
if not directories:
|
||||
break
|
||||
next_directories = []
|
||||
for directory in directories:
|
||||
for entry in directory.readdir():
|
||||
if entry.basename in ["BUILD", "BUILD.bazel"]:
|
||||
repository_ctx.delete(entry)
|
||||
elif entry.is_dir:
|
||||
next_directories.append(entry)
|
||||
directories = next_directories
|
||||
if directories:
|
||||
fail("V8 Abseil source tree exceeds the supported traversal depth")
|
||||
repository_ctx.delete("BUILD")
|
||||
repository_ctx.delete("BUILD.bazel")
|
||||
repository_ctx.symlink(repository_ctx.attr.build_file, "BUILD.bazel")
|
||||
|
||||
# Do not silently configure a new Abseil version as this version on upgrade.
|
||||
# See absl/base/options.h: ABSL_OPTION_INLINE_NAMESPACE_NAME.
|
||||
options = repository_ctx.read("absl/base/options.h")
|
||||
original = "#define ABSL_OPTION_INLINE_NAMESPACE_NAME lts_20250814"
|
||||
if options.count(original) != 1:
|
||||
fail("Unexpected Abseil inline namespace: recheck the private V8 ABI for this source revision")
|
||||
repository_ctx.file(
|
||||
"absl/base/options.h",
|
||||
options.replace(original, "#define ABSL_OPTION_INLINE_NAMESPACE_NAME codex_v8_lts_20250814"),
|
||||
executable = False,
|
||||
)
|
||||
|
||||
v8_abseil_repository = repository_rule(
|
||||
implementation = _v8_abseil_repository_impl,
|
||||
attrs = {
|
||||
"build_file": attr.label(
|
||||
default = Label("//third_party/v8:abseil.BUILD.bazel"),
|
||||
allow_single_file = True,
|
||||
),
|
||||
},
|
||||
)
|
||||
95
third_party/v8/artifact_profile.bzl
vendored
Normal file
95
third_party/v8/artifact_profile.bzl
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
"""Complete V8 artifact profiles, enforced at the source archive boundary.
|
||||
|
||||
The source profile is for local consumers and uses the workspace C++ runtime.
|
||||
Published profiles embed the pinned Chromium runtime. Generators inherit the
|
||||
V8 target CPU even when their executable is built for the exec platform.
|
||||
"""
|
||||
|
||||
_POINTER_COMPRESSION = "@v8//:v8_enable_pointer_compression"
|
||||
_SANDBOX = "@v8//:v8_enable_sandbox"
|
||||
_LIBCXX = "@v8//:v8_use_rusty_v8_custom_libcxx"
|
||||
_TARGET_CPU = "@v8//bazel/config:v8_target_cpu"
|
||||
_TOOLCHAINS = "//command_line_option:extra_toolchains"
|
||||
_NATIVE_WINDOWS_TOOLCHAINS = [
|
||||
str(Label("@v8_native_windows_cc//:cc-toolchain-x64_windows")),
|
||||
str(Label("@v8_native_windows_cc//:cc-toolchain-arm64_windows")),
|
||||
]
|
||||
_CPU_CONSTRAINTS = {
|
||||
"arm64": Label("@platforms//cpu:aarch64"),
|
||||
"x64": Label("@platforms//cpu:x86_64"),
|
||||
}
|
||||
|
||||
def _artifact_profile_impl(settings, attr):
|
||||
sandbox = attr.profile != "release"
|
||||
return {
|
||||
_POINTER_COMPRESSION: "True" if sandbox else "False",
|
||||
_SANDBOX: sandbox,
|
||||
_LIBCXX: attr.profile != "source",
|
||||
_TARGET_CPU: attr.v8_cpu,
|
||||
# Select clang-cl only below the V8 archive/binding boundary. Keep the
|
||||
# caller's toolchains (including the ordinary MSVC compiler) elsewhere.
|
||||
_TOOLCHAINS: settings[_TOOLCHAINS] + (_NATIVE_WINDOWS_TOOLCHAINS if attr.native_windows else []),
|
||||
}
|
||||
|
||||
_artifact_profile = transition(
|
||||
implementation = _artifact_profile_impl,
|
||||
inputs = [_TOOLCHAINS],
|
||||
outputs = [_POINTER_COMPRESSION, _SANDBOX, _LIBCXX, _TARGET_CPU, _TOOLCHAINS],
|
||||
)
|
||||
|
||||
def _profiled_files_impl(ctx):
|
||||
constraint_target = ctx.attr._arm64 if ctx.attr.v8_cpu == "arm64" else ctx.attr._x64
|
||||
if not ctx.target_platform_has_constraint(constraint_target[platform_common.ConstraintValueInfo]):
|
||||
fail("%s: V8 CPU %s requires %s on the Bazel target platform. Choose a matching artifact target and --platforms." % (
|
||||
ctx.label,
|
||||
ctx.attr.v8_cpu,
|
||||
constraint_target.label,
|
||||
))
|
||||
files = depset(transitive = [target[DefaultInfo].files for target in ctx.attr.srcs])
|
||||
runfiles = ctx.runfiles().merge_all([
|
||||
target[DefaultInfo].default_runfiles
|
||||
for target in ctx.attr.srcs
|
||||
])
|
||||
return [DefaultInfo(files = files, runfiles = runfiles)]
|
||||
|
||||
_v8_artifact_files = rule(
|
||||
implementation = _profiled_files_impl,
|
||||
doc = "Build a source archive or release pair under its named V8 profile.",
|
||||
attrs = {
|
||||
"native_windows": attr.bool(mandatory = True),
|
||||
"profile": attr.string(
|
||||
mandatory = True,
|
||||
values = ["source", "release", "sandbox_release"],
|
||||
),
|
||||
"srcs": attr.label_list(allow_files = True, cfg = _artifact_profile, mandatory = True),
|
||||
"v8_cpu": attr.string(mandatory = True, values = ["arm64", "x64"]),
|
||||
"_allowlist_function_transition": attr.label(
|
||||
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
|
||||
),
|
||||
"_arm64": attr.label(default = _CPU_CONSTRAINTS["arm64"]),
|
||||
"_x64": attr.label(default = _CPU_CONSTRAINTS["x64"]),
|
||||
},
|
||||
)
|
||||
|
||||
def v8_artifact_files(name, v8_cpu, **kwargs):
|
||||
"""Declare an artifact that is only valid for its requested CPU.
|
||||
|
||||
Fixed-CPU targets without explicit platform constraints can be skipped in
|
||||
wildcard builds. Preserve constraints on targets such as native Windows
|
||||
which already specify their CPU and ABI. The rule checks the resolved CPU
|
||||
in both cases, including values chosen by select().
|
||||
The generator exec platform remains independent of this target constraint.
|
||||
"""
|
||||
if type(v8_cpu) == "string":
|
||||
kwargs.setdefault("target_compatible_with", [_CPU_CONSTRAINTS[v8_cpu]])
|
||||
_v8_artifact_files(
|
||||
name = name,
|
||||
# Derived from the target platform; callers cannot set this knob.
|
||||
native_windows = select({
|
||||
"@rules_rs//rs/platforms/config:aarch64-pc-windows-msvc": True,
|
||||
"@rules_rs//rs/platforms/config:x86_64-pc-windows-msvc": True,
|
||||
"//conditions:default": False,
|
||||
}),
|
||||
v8_cpu = v8_cpu,
|
||||
**kwargs
|
||||
)
|
||||
73
third_party/v8/dependencies.bzl
vendored
Normal file
73
third_party/v8/dependencies.bzl
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
"""Pinned source imports for Codex's V8 dependency builds.
|
||||
|
||||
V8 uses these same repositories through the codex_deps module-extension bridge
|
||||
in its MODULE.bazel. The BUILD files, and all dependency compilation policy,
|
||||
live next to this file so updating V8 does not require patching shared rules.
|
||||
|
||||
On V8 upgrades follow README.md#updating-source-dependencies. Highway, ICU,
|
||||
dragonbox, FP16 and fast_float follow the pinned V8 DEPS; simdutf matches the
|
||||
version in Chromium's vendored metadata. Abseil follows V8's unpatched MODULE.
|
||||
Source versions are reviewed manually, not by the prebuilt checksum CI check.
|
||||
"""
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load(":abseil_repository.bzl", "v8_abseil_repository")
|
||||
|
||||
def _dependencies_impl(module_ctx):
|
||||
v8_abseil_repository(name = "v8_abseil")
|
||||
|
||||
http_archive(
|
||||
name = "v8_highway",
|
||||
build_file = Label("//third_party/v8:highway.BUILD.bazel"),
|
||||
sha256 = "741d705781e0b3e406beda8f1f994fbae01321237ce8023a1ad90fbaf7940c25",
|
||||
strip_prefix = "highway-2607d3b5b0113992fe84d3848859eae13b3b52c1",
|
||||
urls = ["https://github.com/google/highway/archive/2607d3b5b0113992fe84d3848859eae13b3b52c1.tar.gz"],
|
||||
)
|
||||
|
||||
git_repository(
|
||||
name = "v8_icu",
|
||||
build_file = Label("//third_party/v8:icu.BUILD.bazel"),
|
||||
commit = "d578f2e8b7bd5938e21cfb6bf15c079e0aa5b738",
|
||||
patch_cmds = ["find source -name BUILD.bazel | xargs rm"],
|
||||
patch_cmds_win = ["Get-ChildItem -Path source -File -Include BUILD.bazel -Recurse | Remove-Item"],
|
||||
remote = "https://chromium.googlesource.com/chromium/deps/icu.git",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "v8_fast_float",
|
||||
build_file = Label("//third_party/v8:fast_float.BUILD.bazel"),
|
||||
sha256 = "76f958dd97b1cf4d8862d1f0986a47d4bdfa8845252bae15ef0f40de3b95961f",
|
||||
strip_prefix = "fast_float-8.2.10",
|
||||
urls = ["https://github.com/fastfloat/fast_float/archive/refs/tags/v8.2.10.tar.gz"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "v8_simdutf",
|
||||
build_file = Label("//third_party/v8:simdutf.BUILD.bazel"),
|
||||
sha256 = "0180de81a1dd48a87b8c0442ffa81734f3db91a7350914107a449935124e3c6f",
|
||||
strip_prefix = "simdutf-7.7.0",
|
||||
urls = ["https://github.com/simdutf/simdutf/archive/refs/tags/v7.7.0.tar.gz"],
|
||||
)
|
||||
|
||||
git_repository(
|
||||
name = "v8_dragonbox",
|
||||
build_file = Label("//third_party/v8:dragonbox.BUILD.bazel"),
|
||||
commit = "beeeef91cf6fef89a4d4ba5e95d47ca64ccb3a44",
|
||||
remote = "https://chromium.googlesource.com/external/github.com/jk-jeon/dragonbox.git",
|
||||
)
|
||||
|
||||
git_repository(
|
||||
name = "v8_fp16",
|
||||
build_file = Label("//third_party/v8:fp16.BUILD.bazel"),
|
||||
commit = "782eea126dc5c755827be751a099eb01826175cf",
|
||||
remote = "https://chromium.googlesource.com/external/github.com/Maratyszcza/FP16.git",
|
||||
)
|
||||
|
||||
return module_ctx.extension_metadata(
|
||||
reproducible = True,
|
||||
root_module_direct_deps = "all",
|
||||
root_module_direct_dev_deps = [],
|
||||
)
|
||||
|
||||
dependencies = module_extension(implementation = _dependencies_impl)
|
||||
28
third_party/v8/dependency_config.bzl
vendored
Normal file
28
third_party/v8/dependency_config.bzl
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Runtime settings for Codex's Highway and simdutf V8 dependencies.
|
||||
|
||||
These targets build with the same Chromium libc++ headers as V8 when that
|
||||
profile is active. Shared libraries such as Abseil remain separate.
|
||||
"""
|
||||
|
||||
RUSTY_V8_DEPENDENCY_COPTS = select({
|
||||
"@@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [
|
||||
"/D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
"/D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
"/D_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
],
|
||||
"@@//third_party/v8:use_rusty_v8_custom_libcxx": [
|
||||
"-nostdinc++",
|
||||
"-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
"-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
"-D_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
"-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
RUSTY_V8_DEPENDENCY_DEPS = select({
|
||||
"@@//third_party/v8:use_rusty_v8_custom_libcxx": [
|
||||
"@@//third_party/v8:rusty_v8_custom_libcxx_headers",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
11
third_party/v8/dragonbox.BUILD.bazel
vendored
Normal file
11
third_party/v8/dragonbox.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Codex overlay for the V8 DEPS revision. Mirrors :lib_dragonbox in V8's
|
||||
# BUILD.bazel, exporting the include path V8 expects from a separate repo.
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "dragonbox",
|
||||
hdrs = ["include/dragonbox/dragonbox.h"],
|
||||
include_prefix = "third_party/dragonbox/src/include",
|
||||
strip_include_prefix = "include",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
981
third_party/v8/engine.BUILD.bazel
vendored
Normal file
981
third_party/v8/engine.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,981 @@
|
||||
# Copyright 2021 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
load("@@//third_party/v8:engine_rules.bzl", "v8_build_config", "v8_fixed_source_features")
|
||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
|
||||
load(
|
||||
"@v8//:bazel/defs.bzl",
|
||||
"v8_binary",
|
||||
"v8_config",
|
||||
"v8_flag",
|
||||
"v8_library",
|
||||
"v8_mksnapshot",
|
||||
"v8_string",
|
||||
"v8_torque_files",
|
||||
)
|
||||
load("@v8//:bazel/v8-non-pointer-compression.bzl", "v8_binary_non_pointer_compression")
|
||||
load("@v8_python_deps//:requirements.bzl", "requirement")
|
||||
|
||||
# Used by the Codex-owned pip hub; pin changes travel with the V8 source.
|
||||
exports_files(["bazel/requirements.txt"])
|
||||
|
||||
# Codex V8 source policy. Only ABI, runtime and target CPU vary, selected by
|
||||
# artifact profiles. CPU selection lives in bazel/config.
|
||||
# Platform feature choices preserve the published Bazel Unix and GN MSVC builds.
|
||||
# ICU and no-ICU remain separate targets for the engine and its generators.
|
||||
v8_flag(name = "v8_enable_sandbox")
|
||||
|
||||
v8_flag(name = "v8_use_rusty_v8_custom_libcxx")
|
||||
|
||||
# Maglev is supported on the two architectures shipped by Codex. Keep the
|
||||
# architecture tests separate from feature policy for host-tool transitions.
|
||||
selects.config_setting_group(
|
||||
name = "enable_maglev",
|
||||
match_any = [
|
||||
"@v8//bazel/config:v8_target_x64",
|
||||
"@v8//bazel/config:v8_target_arm64",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "enable_maglev_x64",
|
||||
match_all = [
|
||||
":enable_maglev",
|
||||
"@v8//bazel/config:v8_target_x64",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "enable_maglev_arm64",
|
||||
match_all = [
|
||||
":enable_maglev",
|
||||
"@v8//bazel/config:v8_target_arm64",
|
||||
],
|
||||
)
|
||||
|
||||
# WebAssembly remains enabled; its source implementation still depends on OS.
|
||||
selects.config_setting_group(
|
||||
name = "webassembly_on_posix",
|
||||
match_any = ["@v8//bazel/config:is_posix"],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "webassembly_on_windows",
|
||||
match_any = ["@v8//bazel/config:is_windows"],
|
||||
)
|
||||
|
||||
# Artifact transitions set True or False, never the upstream "none" auto mode.
|
||||
# The 32-bit Torque helper can also force this off.
|
||||
v8_string(
|
||||
name = "v8_enable_pointer_compression",
|
||||
default = "False",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "is_v8_enable_pointer_compression",
|
||||
flag_values = {":v8_enable_pointer_compression": "True"},
|
||||
)
|
||||
|
||||
# V8's pinned default short-call policy differs on x64 and arm64. In particular
|
||||
# the legacy arm64 non-pointer-compressed profile still uses short calls.
|
||||
selects.config_setting_group(
|
||||
name = "v8_target_x64_default_short_builtin_calls",
|
||||
match_all = [
|
||||
"@v8//bazel/config:v8_target_x64",
|
||||
":is_v8_enable_pointer_compression",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "v8_target_arm64_default_short_builtin_calls",
|
||||
match_all = [
|
||||
"@v8//bazel/config:v8_target_arm64",
|
||||
"@v8//bazel/config:is_not_android",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "is_v8_enable_short_builtin_calls",
|
||||
match_any = [
|
||||
":v8_target_x64_default_short_builtin_calls",
|
||||
":v8_target_arm64_default_short_builtin_calls",
|
||||
],
|
||||
)
|
||||
|
||||
# Fixed V8 15.2 Codex feature contract: TurboFan and WebAssembly enabled;
|
||||
# experiments, VTune and profiling disabled. Do not hard-code ABI-sensitive
|
||||
# values such as sandbox, pointer compression or target CPU into this baseline.
|
||||
v8_config(
|
||||
name = "define_flags",
|
||||
conditional_defines = {"v8_enable_sandbox": "V8_ENABLE_SANDBOX"},
|
||||
defines = [
|
||||
"V8_DEPRECATION_WARNINGS",
|
||||
"V8_ENABLE_LAZY_SOURCE_POSITIONS",
|
||||
"V8_ENABLE_TURBOFAN",
|
||||
"V8_ENABLE_WEBASSEMBLY",
|
||||
"V8_ENABLE_UNDEFINED_DOUBLE",
|
||||
"V8_USE_HOST_CPU_ARM_FEATURES",
|
||||
] + [
|
||||
"GOOGLE3",
|
||||
"V8_ADVANCED_BIGINT_ALGORITHMS",
|
||||
"V8_CONCURRENT_MARKING",
|
||||
"V8_ENABLE_SPARKPLUG",
|
||||
"V8_ENABLE_EXTENSIBLE_RO_SNAPSHOT",
|
||||
"V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA",
|
||||
"V8_TLS_USED_IN_LIBRARY",
|
||||
] + select({
|
||||
# The published MSVC artifacts used GN's CppGC queue and Wasm fuzzers.
|
||||
# Keep these choices in the owned policy, including snapshot generators.
|
||||
"@@//third_party/v8:platform_windows_msvc": [
|
||||
"V8_CPPGC_MICROTASK_QUEUE",
|
||||
"V8_WASM_RANDOM_FUZZERS",
|
||||
"V8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=0",
|
||||
],
|
||||
"//conditions:default": [
|
||||
"V8_IMMINENT_DEPRECATION_WARNINGS",
|
||||
"V8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64",
|
||||
],
|
||||
}) + select({
|
||||
# Rusty V8's v8_enable_v8_checks feature is off in Codex. Keep the
|
||||
# matching C++ flag undefined even in debug: it adds a HandleScope
|
||||
# field that Rust would not allocate. DEBUG itself preserves that ABI.
|
||||
# V8's BUILD.gn also selects logging level 2 for debug verification.
|
||||
# Debug-only FATAL_WITH_LOC sites require that level to use the location.
|
||||
"@v8//bazel/config:is_debug": [
|
||||
"DEBUG",
|
||||
"V8_LOGGING_LEVEL=2",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@v8//bazel/config:asan_enabled": ["V8_USE_ADDRESS_SANITIZER"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@v8//bazel/config:hwasan_enabled": ["V8_USE_HWADDRESS_SANITIZER"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@v8//bazel/config:msan_enabled": ["V8_USE_MEMORY_SANITIZER"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@v8//bazel/config:ubsan_enabled": ["V8_USE_UNDEFINED_BEHAVIOR_SANITIZER"],
|
||||
"//conditions:default": [],
|
||||
}) + select(
|
||||
{
|
||||
"@v8//bazel/config:v8_target_ia32": ["V8_TARGET_ARCH_IA32"],
|
||||
"@v8//bazel/config:v8_target_x64": [
|
||||
"V8_TARGET_ARCH_X64",
|
||||
"V8_ENABLE_SPARKPLUG_PLUS",
|
||||
],
|
||||
"@v8//bazel/config:v8_target_arm": [
|
||||
"V8_TARGET_ARCH_ARM",
|
||||
"CAN_USE_ARMV7_INSTRUCTIONS",
|
||||
"CAN_USE_VFP3_INSTRUCTIONS",
|
||||
],
|
||||
"@v8//bazel/config:v8_target_arm64": [
|
||||
"V8_TARGET_ARCH_ARM64",
|
||||
"V8_ENABLE_SPARKPLUG_PLUS",
|
||||
],
|
||||
"@v8//bazel/config:v8_target_s390x": [
|
||||
"V8_TARGET_ARCH_S390X",
|
||||
],
|
||||
"@v8//bazel/config:v8_target_riscv64": [
|
||||
# NOTE: Bazel rules for riscv64 weren't tested on a real system.
|
||||
"V8_TARGET_ARCH_RISCV64",
|
||||
"CAN_USE_FPU_INSTRUCTIONS",
|
||||
],
|
||||
"@v8//bazel/config:v8_target_ppc64le": [
|
||||
# NOTE: Bazel rules for ppc64le weren't tested on a real system.
|
||||
"V8_TARGET_ARCH_PPC64",
|
||||
],
|
||||
},
|
||||
no_match_error = "Please specify a target cpu supported by v8",
|
||||
) + select({
|
||||
"@v8//bazel/config:is_android": [
|
||||
"V8_HAVE_TARGET_OS",
|
||||
"V8_TARGET_OS_ANDROID",
|
||||
],
|
||||
"@v8//bazel/config:is_linux": [
|
||||
"V8_HAVE_TARGET_OS",
|
||||
"V8_TARGET_OS_LINUX",
|
||||
],
|
||||
"@v8//bazel/config:is_macos": [
|
||||
"V8_HAVE_TARGET_OS",
|
||||
"V8_TARGET_OS_MACOS",
|
||||
],
|
||||
"@v8//bazel/config:is_windows": [
|
||||
"V8_HAVE_TARGET_OS",
|
||||
"V8_TARGET_OS_WIN",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"_CRT_RAND_S",
|
||||
"_WIN32_WINNT=0x0A00",
|
||||
],
|
||||
}) + select({
|
||||
":is_v8_enable_pointer_compression": [
|
||||
"V8_COMPRESS_POINTERS",
|
||||
"V8_31BIT_SMIS_ON_64BIT_ARCH",
|
||||
"V8_CONTIGUOUS_COMPRESSED_RO_SPACE",
|
||||
"V8_CONTIGUOUS_COMPRESSED_RO_SPACE_SIZE_MB=8",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":is_v8_enable_pointer_compression": [
|
||||
"V8_COMPRESS_POINTERS_IN_SHARED_CAGE",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":is_v8_enable_short_builtin_calls": [
|
||||
"V8_SHORT_BUILTIN_CALLS",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":is_v8_enable_pointer_compression": [
|
||||
"V8_EXTERNAL_CODE_SPACE",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":is_v8_enable_pointer_compression": [
|
||||
"V8_STATIC_ROOTS",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":enable_maglev": [
|
||||
"V8_ENABLE_MAGLEV",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + [] + [],
|
||||
deps = [],
|
||||
)
|
||||
|
||||
# Source inventory and dependency aliases.
|
||||
|
||||
# The imported groups retain upstream select names. They express our pinned
|
||||
# feature contract here; only CPU, ABI and the C++ runtime actually vary.
|
||||
v8_fixed_source_features(
|
||||
name = "pinned_source_features",
|
||||
build_setting_default = True,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "is_v8_enable_webassembly",
|
||||
flag_values = {":pinned_source_features": "True"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "disabled_pinned_source_feature",
|
||||
flag_values = {":pinned_source_features": "False"},
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "enable_drumbrake_arm64",
|
||||
actual = ":disabled_pinned_source_feature",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "enable_drumbrake_x64",
|
||||
actual = ":disabled_pinned_source_feature",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "enable_maglev_arm",
|
||||
actual = ":disabled_pinned_source_feature",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "enable_maglev_riscv",
|
||||
actual = ":disabled_pinned_source_feature",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "is_v8_enable_drumbrake",
|
||||
actual = ":disabled_pinned_source_feature",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "is_v8_enable_experimental_tq_to_tsa",
|
||||
actual = ":disabled_pinned_source_feature",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "is_v8_wasm_random_fuzzers",
|
||||
actual = "@@//third_party/v8:platform_windows_msvc",
|
||||
)
|
||||
|
||||
# @CODEX_V8_UPSTREAM_FILEGROUPS@
|
||||
|
||||
filegroup(
|
||||
name = "windows_x64_stack_assembly",
|
||||
# The import preserves upstream MASM; only GNU builds use our GAS source.
|
||||
srcs = select({
|
||||
"@@//third_party/v8:platform_windows_msvc": ["src/heap/base/asm/x64/push_registers_masm.asm"],
|
||||
"//conditions:default": ["@@//third_party/v8:push_registers_gnullvm.S"],
|
||||
}),
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "lib_dragonbox",
|
||||
actual = "@v8_dragonbox//:dragonbox",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "lib_fp16",
|
||||
actual = "@v8_fp16//:fp16",
|
||||
)
|
||||
|
||||
# Generated files
|
||||
|
||||
# Define file groups for torque definitions and initializers. Both are
|
||||
# generated together, but we can use output_group to split them.
|
||||
filegroup(
|
||||
name = "icu/generated_torque_definitions",
|
||||
srcs = [":icu/generated_torque_files"],
|
||||
output_group = "definitions",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "noicu/generated_torque_definitions",
|
||||
srcs = [":noicu/generated_torque_files"],
|
||||
output_group = "definitions",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "icu/generated_torque_initializers",
|
||||
srcs = [":icu/generated_torque_files"],
|
||||
output_group = "initializers",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "noicu/generated_torque_initializers",
|
||||
srcs = [":noicu/generated_torque_files"],
|
||||
output_group = "initializers",
|
||||
)
|
||||
|
||||
# TODO(victorgomes): Add support to tools/debug_helper,
|
||||
# which needs class-debug-readers and debug-macros.
|
||||
v8_torque_files(
|
||||
name = "generated_torque_files",
|
||||
args = [] + select({
|
||||
"@v8//bazel/config:v8_target_is_32_bits": ["-m32"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
definition_extras = [
|
||||
"bit-field-asserts.cc",
|
||||
"builtin-definitions.h",
|
||||
# "class-debug-readers.cc",
|
||||
# "class-debug-readers.h",
|
||||
"class-forward-declarations.h",
|
||||
# "debug-macros.cc",
|
||||
# "debug-macros.h",
|
||||
"instance-types.h",
|
||||
"interface-descriptors.inc",
|
||||
],
|
||||
icu_srcs = [":icu/torque_files"],
|
||||
initializer_extras = [
|
||||
"csa-types.h",
|
||||
"enum-verifiers.cc",
|
||||
"exported-macros-assembler.cc",
|
||||
"exported-macros-assembler.h",
|
||||
],
|
||||
noicu_srcs = [":noicu/torque_files"],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "code_generator",
|
||||
srcs = [
|
||||
"third_party/inspector_protocol/code_generator.py",
|
||||
"third_party/inspector_protocol/pdl.py",
|
||||
],
|
||||
data = [
|
||||
"third_party/inspector_protocol/lib/Forward_h.template",
|
||||
"third_party/inspector_protocol/lib/Object_cpp.template",
|
||||
"third_party/inspector_protocol/lib/Object_h.template",
|
||||
"third_party/inspector_protocol/lib/Protocol_cpp.template",
|
||||
"third_party/inspector_protocol/lib/ValueConversions_cpp.template",
|
||||
"third_party/inspector_protocol/lib/ValueConversions_h.template",
|
||||
"third_party/inspector_protocol/lib/Values_cpp.template",
|
||||
"third_party/inspector_protocol/lib/Values_h.template",
|
||||
"third_party/inspector_protocol/templates/Exported_h.template",
|
||||
"third_party/inspector_protocol/templates/Imported_h.template",
|
||||
"third_party/inspector_protocol/templates/TypeBuilder_cpp.template",
|
||||
"third_party/inspector_protocol/templates/TypeBuilder_h.template",
|
||||
],
|
||||
imports = ["third_party/inspector_protocol/"],
|
||||
deps = [
|
||||
requirement("jinja2"),
|
||||
],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "generated_inspector_files",
|
||||
srcs = [
|
||||
"include/js_protocol.pdl",
|
||||
"src/inspector/inspector_protocol_config.json",
|
||||
"third_party/inspector_protocol/code_generator.py",
|
||||
"third_party/inspector_protocol/pdl.py",
|
||||
"third_party/inspector_protocol/lib/Forward_h.template",
|
||||
"third_party/inspector_protocol/lib/Object_cpp.template",
|
||||
"third_party/inspector_protocol/lib/Object_h.template",
|
||||
"third_party/inspector_protocol/lib/Protocol_cpp.template",
|
||||
"third_party/inspector_protocol/lib/ValueConversions_cpp.template",
|
||||
"third_party/inspector_protocol/lib/ValueConversions_h.template",
|
||||
"third_party/inspector_protocol/lib/Values_cpp.template",
|
||||
"third_party/inspector_protocol/lib/Values_h.template",
|
||||
"third_party/inspector_protocol/templates/Exported_h.template",
|
||||
"third_party/inspector_protocol/templates/Imported_h.template",
|
||||
"third_party/inspector_protocol/templates/TypeBuilder_cpp.template",
|
||||
"third_party/inspector_protocol/templates/TypeBuilder_h.template",
|
||||
],
|
||||
outs = [
|
||||
"include/inspector/Debugger.h",
|
||||
"include/inspector/Runtime.h",
|
||||
"include/inspector/Schema.h",
|
||||
"src/inspector/protocol/Forward.h",
|
||||
"src/inspector/protocol/Protocol.cpp",
|
||||
"src/inspector/protocol/Protocol.h",
|
||||
"src/inspector/protocol/Console.cpp",
|
||||
"src/inspector/protocol/Console.h",
|
||||
"src/inspector/protocol/Debugger.cpp",
|
||||
"src/inspector/protocol/Debugger.h",
|
||||
"src/inspector/protocol/HeapProfiler.cpp",
|
||||
"src/inspector/protocol/HeapProfiler.h",
|
||||
"src/inspector/protocol/Profiler.cpp",
|
||||
"src/inspector/protocol/Profiler.h",
|
||||
"src/inspector/protocol/Runtime.cpp",
|
||||
"src/inspector/protocol/Runtime.h",
|
||||
"src/inspector/protocol/Schema.cpp",
|
||||
"src/inspector/protocol/Schema.h",
|
||||
],
|
||||
cmd = select({
|
||||
"@@//third_party/v8:platform_windows_msvc": "$(execpath :code_generator) --jinja_dir . --inspector_protocol_dir $$(dirname $(execpath third_party/inspector_protocol/code_generator.py)) --config $(location :src/inspector/inspector_protocol_config.json) --config_value protocol.path=$(location :include/js_protocol.pdl) --config_value crdtp.dir=third_party/inspector_protocol/crdtp --output_base $(@D)/src/inspector",
|
||||
"//conditions:default": "INSPECTOR_PROTOCOL_DIR=$$(dirname $(execpath third_party/inspector_protocol/code_generator.py)); \
|
||||
PYTHONPATH=$$INSPECTOR_PROTOCOL_DIR:external/rules_python++pip+v8_python_deps_311_jinja2/site-packages:external/rules_python++pip+v8_python_deps_311_markupsafe/site-packages:$${PYTHONPATH-} \
|
||||
$(execpath @rules_python//python/bin:python) $(execpath third_party/inspector_protocol/code_generator.py) --jinja_dir . \
|
||||
--inspector_protocol_dir $$INSPECTOR_PROTOCOL_DIR \
|
||||
--config $(location :src/inspector/inspector_protocol_config.json) \
|
||||
--config_value protocol.path=$(location :include/js_protocol.pdl) \
|
||||
--config_value crdtp.dir=third_party/inspector_protocol/crdtp \
|
||||
--output_base $(@D)/src/inspector",
|
||||
}),
|
||||
message = "Generating inspector files",
|
||||
tools = select({
|
||||
"@@//third_party/v8:platform_windows_msvc": [":code_generator"],
|
||||
"//conditions:default": [
|
||||
"@rules_python//python/bin:python",
|
||||
requirement("jinja2"),
|
||||
requirement("markupsafe"),
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "v8_common_libshared_files",
|
||||
srcs = [
|
||||
":torque_runtime_support_files",
|
||||
":v8_libplatform_files",
|
||||
":v8_libsampler_files",
|
||||
":v8_shared_internal_headers",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rusty_v8_internal_headers",
|
||||
hdrs = [
|
||||
"src/libplatform/default-platform.h",
|
||||
],
|
||||
strip_include_prefix = "",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rusty_v8_crdtp_headers",
|
||||
hdrs = [
|
||||
"third_party/inspector_protocol/crdtp/cbor.h",
|
||||
"third_party/inspector_protocol/crdtp/dispatch.h",
|
||||
"third_party/inspector_protocol/crdtp/error_support.h",
|
||||
"third_party/inspector_protocol/crdtp/export.h",
|
||||
"third_party/inspector_protocol/crdtp/find_by_first.h",
|
||||
"third_party/inspector_protocol/crdtp/frontend_channel.h",
|
||||
"third_party/inspector_protocol/crdtp/json.h",
|
||||
"third_party/inspector_protocol/crdtp/parser_handler.h",
|
||||
"third_party/inspector_protocol/crdtp/protocol_core.h",
|
||||
"third_party/inspector_protocol/crdtp/serializable.h",
|
||||
"third_party/inspector_protocol/crdtp/span.h",
|
||||
"third_party/inspector_protocol/crdtp/status.h",
|
||||
],
|
||||
strip_include_prefix = "",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "d8_files",
|
||||
srcs = [
|
||||
"src/d8/async-hooks-wrapper.cc",
|
||||
"src/d8/async-hooks-wrapper.h",
|
||||
"src/d8/d8.cc",
|
||||
"src/d8/d8.h",
|
||||
"src/d8/d8-console.cc",
|
||||
"src/d8/d8-console.h",
|
||||
"src/d8/d8-js.cc",
|
||||
"src/d8/d8-platforms.cc",
|
||||
"src/d8/d8-platforms.h",
|
||||
"src/d8/d8-posix.cc",
|
||||
"src/d8/d8-test.cc",
|
||||
"src/d8/hardware-watchpoints.cc",
|
||||
"src/d8/hardware-watchpoints.h",
|
||||
"src/d8/memory-access-information.cc",
|
||||
"src/d8/memory-access-information.h",
|
||||
],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "generated_bytecode_builtins_list",
|
||||
srcs = [],
|
||||
outs = ["builtins-generated/bytecodes-builtins-list.h"],
|
||||
cmd = "$(location :bytecode_builtins_list_generator) $@",
|
||||
cmd_bat = "$(location :bytecode_builtins_list_generator) $@",
|
||||
tools = [":bytecode_builtins_list_generator"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "generated_regexp_special_case",
|
||||
srcs = [],
|
||||
outs = ["src/regexp/special-case.cc"],
|
||||
cmd = "$(location :regexp_special_case_generator) $@",
|
||||
cmd_bat = "$(location :regexp_special_case_generator) $@",
|
||||
tools = [":regexp_special_case_generator"],
|
||||
)
|
||||
|
||||
v8_mksnapshot(
|
||||
name = "generated_snapshot_files",
|
||||
args = [] + [] + [] + ["--no-native-code-counters"],
|
||||
)
|
||||
|
||||
# =================================================
|
||||
# Libraries rules
|
||||
# =================================================
|
||||
|
||||
# NOTE: This allow headers to be accessed without the icu/noicu prefixes.
|
||||
cc_library(
|
||||
name = "icu/generated_torque_definitions_headers",
|
||||
hdrs = [":icu/generated_torque_definitions"],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
strip_include_prefix = "icu",
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "noicu/generated_torque_definitions_headers",
|
||||
hdrs = [":noicu/generated_torque_definitions"],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
strip_include_prefix = "noicu",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "llvm_libc_headers",
|
||||
actual = "@@//third_party/v8:rusty_v8_llvm_libc_headers",
|
||||
)
|
||||
|
||||
v8_library(
|
||||
name = "v8_libbase",
|
||||
srcs = [
|
||||
":v8_libbase_files",
|
||||
":v8_shared_internal_headers",
|
||||
],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
deps = [
|
||||
":llvm_libc_headers",
|
||||
"@v8_abseil//:overload",
|
||||
"@v8_abseil//:synchronization",
|
||||
"@v8_abseil//:time",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "torque_base_headers",
|
||||
hdrs = [
|
||||
"src/torque/kythe-data.h",
|
||||
"src/torque/torque-compiler.h",
|
||||
],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
include_prefix = "third_party/v8",
|
||||
includes = ["."],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "kythe_torque_base",
|
||||
srcs = [
|
||||
":torque_base_files",
|
||||
],
|
||||
copts = ["-Wno-implicit-fallthrough"] + select({
|
||||
"@v8//bazel/config:is_posix": ["-fexceptions"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
features = ["-use_header_modules"],
|
||||
deps = [
|
||||
":torque_base_headers",
|
||||
":v8_libbase",
|
||||
"@v8_abseil//:node_hash_map",
|
||||
"@v8_abseil//:node_hash_set",
|
||||
],
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "simdutf",
|
||||
actual = "@v8_simdutf//:simdutf",
|
||||
)
|
||||
|
||||
v8_library(
|
||||
name = "v8_libshared",
|
||||
srcs = [
|
||||
":v8_base_without_compiler_files",
|
||||
":v8_common_libshared_files",
|
||||
] + [
|
||||
":v8_compiler_files",
|
||||
],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
icu_deps = [
|
||||
":icu/generated_torque_definitions_headers",
|
||||
"@v8_icu//:icu",
|
||||
],
|
||||
icu_srcs = [
|
||||
":generated_regexp_special_case",
|
||||
":icu/generated_torque_definitions",
|
||||
":icu/v8_base_without_compiler_files",
|
||||
],
|
||||
noicu_deps = [
|
||||
":noicu/generated_torque_definitions_headers",
|
||||
],
|
||||
noicu_srcs = [
|
||||
":noicu/generated_torque_definitions",
|
||||
],
|
||||
deps = [
|
||||
# keep
|
||||
":lib_dragonbox",
|
||||
"@v8_fast_float//:fast_float",
|
||||
":lib_fp16",
|
||||
":simdutf",
|
||||
":v8_libbase",
|
||||
"@v8_abseil//:btree",
|
||||
"@v8_abseil//:flat_hash_map",
|
||||
"@v8_abseil//:flat_hash_set",
|
||||
"@v8_abseil//:overload",
|
||||
"@v8_highway//:hwy",
|
||||
],
|
||||
)
|
||||
|
||||
v8_library(
|
||||
name = "v8",
|
||||
srcs = [
|
||||
":v8_inspector_files",
|
||||
] + [],
|
||||
hdrs = [":public_header_files"],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
icu_deps = [":icu/v8_libshared"],
|
||||
icu_srcs = [":icu/snapshot_files"],
|
||||
noicu_deps = [":noicu/v8_libshared"],
|
||||
noicu_srcs = [":noicu/snapshot_files"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
v8_library(
|
||||
name = "wee8",
|
||||
srcs = [":wee8_files"],
|
||||
hdrs = [":public_wasm_c_api_header_files"],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
strip_include_prefix = "third_party",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":noicu/v8"] + [],
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "core_lib_noicu",
|
||||
actual = "noicu/v8",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "core_lib_icu",
|
||||
actual = "icu/v8",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
v8_library(
|
||||
name = "v8_vtune",
|
||||
srcs = [
|
||||
"third_party/vtune/v8-vtune.h",
|
||||
"third_party/vtune/vtune-jit.cc",
|
||||
"third_party/vtune/vtune-jit.h",
|
||||
],
|
||||
copts = ["-I"],
|
||||
deps = [
|
||||
":core_lib_noicu",
|
||||
"@intel_ittapi//:lib_ittapi",
|
||||
],
|
||||
)
|
||||
|
||||
# =================================================
|
||||
# Binary rules
|
||||
# =================================================
|
||||
|
||||
v8_binary(
|
||||
name = "bytecode_builtins_list_generator",
|
||||
srcs = [
|
||||
"src/builtins/generate-bytecodes-builtins-list.cc",
|
||||
"src/interpreter/bytecode-operands.cc",
|
||||
"src/interpreter/bytecode-operands.h",
|
||||
"src/interpreter/bytecode-traits.h",
|
||||
"src/interpreter/bytecodes.cc",
|
||||
"src/interpreter/bytecodes.h",
|
||||
],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
deps = ["v8_libbase"],
|
||||
)
|
||||
|
||||
v8_binary(
|
||||
name = "regexp_special_case_generator",
|
||||
srcs = [
|
||||
"src/regexp/gen-regexp-special-case.cc",
|
||||
"src/regexp/special-case.h",
|
||||
":v8_shared_internal_headers",
|
||||
],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
defines = [
|
||||
"V8_INTL_SUPPORT",
|
||||
"ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC",
|
||||
# src/regexp/regexp-compiler-tonode.cc uses an unsafe ICU method and
|
||||
# access a character implicitly.
|
||||
"UNISTR_FROM_CHAR_EXPLICIT=",
|
||||
],
|
||||
deps = [
|
||||
":v8_libbase",
|
||||
"@v8_icu//:icu",
|
||||
],
|
||||
)
|
||||
|
||||
v8_binary(
|
||||
name = "torque",
|
||||
srcs = [
|
||||
"src/torque/torque.cc",
|
||||
":torque_base_files",
|
||||
],
|
||||
copts = ["-Wno-implicit-fallthrough"] + select({
|
||||
"@v8//bazel/config:is_posix": ["-fexceptions"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
features = ["-use_header_modules"],
|
||||
icu_defines = ["V8_INTL_SUPPORT"],
|
||||
linkopts = select({
|
||||
"@v8//bazel/config:is_android": ["-llog"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = [
|
||||
"v8_libbase",
|
||||
"@v8_abseil//:node_hash_map",
|
||||
"@v8_abseil//:node_hash_set",
|
||||
],
|
||||
)
|
||||
|
||||
v8_binary(
|
||||
name = "mksnapshot",
|
||||
srcs = [
|
||||
":mksnapshot_files",
|
||||
] + [],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
# Match GN's mksnapshot `disable_icf` config. If the linker folds distinct
|
||||
# external-reference helpers together while producing the snapshot, the
|
||||
# final embedder binary may not fold the same pair and startup
|
||||
# deserialization will reject the snapshot.
|
||||
# GN also increases the x64 Windows stack reserve because constructing the
|
||||
# snapshot overflows the linker's 1 MiB default.
|
||||
# The MSVC toolchain adds /OPT:ICF after user linkopts in opt mode.
|
||||
# Disable that feature so the snapshot remains usable in debug embedders.
|
||||
features = select({
|
||||
"@@//third_party/v8:platform_windows_msvc": ["-smaller_binary"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
icu_deps = [":icu/v8_libshared"],
|
||||
icu_srcs = [
|
||||
":icu/generated_torque_initializers",
|
||||
":icu/v8_initializers_files",
|
||||
],
|
||||
linkopts = select({
|
||||
"@v8//bazel/config:is_android": ["-llog"],
|
||||
"@v8//bazel/config:is_macos": ["-Wl,-no_deduplicate"],
|
||||
"@@//third_party/v8:platform_windows_msvc": [
|
||||
"/OPT:NOICF",
|
||||
"/OPT:REF",
|
||||
"/STACK:2097152",
|
||||
],
|
||||
"@v8//bazel/config:is_windows": [
|
||||
"-Wl,/OPT:NOICF",
|
||||
"-Wl,/STACK:2097152",
|
||||
],
|
||||
"//conditions:default": ["-Wl,--icf=none"],
|
||||
}),
|
||||
noicu_deps = [":v8_libshared_noicu"],
|
||||
noicu_srcs = [
|
||||
":noicu/generated_torque_initializers",
|
||||
":noicu/v8_initializers_files",
|
||||
],
|
||||
)
|
||||
|
||||
v8_binary(
|
||||
name = "d8",
|
||||
srcs = [":d8_files"],
|
||||
copts = ["-Wno-implicit-fallthrough"],
|
||||
icu_deps = [":icu/v8"],
|
||||
noicu_deps = [":noicu/v8"],
|
||||
)
|
||||
|
||||
# This target forces torque to be compiled without pointer compression.
|
||||
v8_binary_non_pointer_compression(
|
||||
name = "noicu/torque_non_pointer_compression",
|
||||
binary = "noicu/torque",
|
||||
)
|
||||
|
||||
v8_binary_non_pointer_compression(
|
||||
name = "icu/torque_non_pointer_compression",
|
||||
binary = "icu/torque",
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "v8ci",
|
||||
actual = "noicu/v8",
|
||||
)
|
||||
|
||||
# =================================================
|
||||
# Tests
|
||||
# =================================================
|
||||
|
||||
v8_build_config(
|
||||
name = "v8_build_config",
|
||||
arch = select({
|
||||
"@v8//bazel/config:v8_target_arm64": "arm64",
|
||||
"@v8//bazel/config:v8_target_x64": "x64",
|
||||
"//conditions:default": "x64",
|
||||
}),
|
||||
)
|
||||
|
||||
# Runs mjsunit with d8.
|
||||
py_test(
|
||||
name = "noicu/mjsunit",
|
||||
size = "medium",
|
||||
srcs = [
|
||||
"test/mjsunit/testcfg.py",
|
||||
"tools/predictable_wrapper.py",
|
||||
"tools/run-tests.py",
|
||||
] + glob(["tools/testrunner/**/*.py"]),
|
||||
args = [
|
||||
"--no-sorting",
|
||||
"--nopresubmit",
|
||||
"--variant=google3",
|
||||
"--outdir noicu",
|
||||
"--verbose",
|
||||
] + select({
|
||||
"@v8//bazel/config:v8_target_arm64": [
|
||||
"--arch=arm64",
|
||||
],
|
||||
"@v8//bazel/config:v8_target_x64": [
|
||||
"--arch=x64",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + [
|
||||
"mjsunit",
|
||||
],
|
||||
data = [
|
||||
"test",
|
||||
":noicu/d8",
|
||||
":noicu/v8_build_config",
|
||||
"//testing/pybase",
|
||||
] + glob(["test/**"]) + glob(["tools/**/*.js"]) + glob(["tools/**/*.mjs"]),
|
||||
main = "tools/run-tests.py",
|
||||
tags = [
|
||||
# Disable sanitizers, as they don't work in general in V8.
|
||||
"nosan",
|
||||
],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "icu/mjsunit",
|
||||
size = "medium",
|
||||
srcs = [
|
||||
"test/mjsunit/testcfg.py",
|
||||
"tools/predictable_wrapper.py",
|
||||
"tools/run-tests.py",
|
||||
] + glob(["tools/testrunner/**/*.py"]),
|
||||
args = [
|
||||
"--no-sorting",
|
||||
"--nopresubmit",
|
||||
"--variant=google3",
|
||||
"--outdir icu",
|
||||
"--verbose",
|
||||
] + select({
|
||||
"@v8//bazel/config:v8_target_arm64": [
|
||||
"--arch=arm64",
|
||||
],
|
||||
"@v8//bazel/config:v8_target_x64": [
|
||||
"--arch=x64",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + [
|
||||
"mjsunit",
|
||||
],
|
||||
data = [
|
||||
"test",
|
||||
":icu/d8",
|
||||
":icu/v8_build_config",
|
||||
"//testing/pybase",
|
||||
] + glob(["test/**"]) + glob(["tools/**/*.js"]) + glob(["tools/**/*.mjs"]),
|
||||
main = "tools/run-tests.py",
|
||||
tags = [
|
||||
# Disable sanitizers, as they don't work in general in V8.
|
||||
"nosan",
|
||||
],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "icu/intl",
|
||||
size = "medium",
|
||||
srcs = [
|
||||
"test/intl/testcfg.py",
|
||||
"tools/predictable_wrapper.py",
|
||||
"tools/run-tests.py",
|
||||
] + glob(["tools/testrunner/**/*.py"]),
|
||||
args = [
|
||||
"--no-sorting",
|
||||
"--nopresubmit",
|
||||
"--variant=google3",
|
||||
"--outdir icu",
|
||||
"--verbose",
|
||||
] + select({
|
||||
"@v8//bazel/config:v8_target_arm64": [
|
||||
"--arch=arm64",
|
||||
],
|
||||
"@v8//bazel/config:v8_target_x64": [
|
||||
"--arch=x64",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + [
|
||||
"intl",
|
||||
],
|
||||
data = [
|
||||
"test",
|
||||
":icu/d8",
|
||||
":icu/v8_build_config",
|
||||
"//testing/pybase",
|
||||
] + glob(["test/**"]) + glob(["tools/**/*.js"]) + glob(["tools/**/*.mjs"]),
|
||||
main = "tools/run-tests.py",
|
||||
tags = [
|
||||
# Disable sanitizers, as they don't work in general in V8.
|
||||
"nosan",
|
||||
],
|
||||
)
|
||||
|
||||
# V8's existing converter builds snapshot assembly as C++ for clang-cl.
|
||||
py_binary(
|
||||
name = "native_windows_inline_asm",
|
||||
srcs = ["tools/snapshot/asm_to_inline_asm.py"],
|
||||
main = "tools/snapshot/asm_to_inline_asm.py",
|
||||
tags = ["manual"],
|
||||
)
|
||||
101
third_party/v8/engine_repository.bzl
vendored
Normal file
101
third_party/v8/engine_repository.bzl
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
"""V8 source import with Codex-owned Bazel entry points.
|
||||
|
||||
The root package is placed inside the fetched source tree so relative source
|
||||
labels and globs have their normal Bazel semantics. Reuse upstream's platform
|
||||
and CPU configuration in place, with Codex's narrow patch to bazel/defs.bzl
|
||||
and the target CPU setting.
|
||||
V8's MODULE and toolchain BUILD files are never part of Codex's dependency or
|
||||
toolchain graph.
|
||||
"""
|
||||
|
||||
# Upstream keeps its source groups in BUILD.bazel, which cannot be loaded as
|
||||
# a Starlark library. Reuse filegroups, so labels/globs retain their semantics
|
||||
# inside @v8. Compiled targets (including valid V8 v8_library/v8_binary calls)
|
||||
# belong in engine.BUILD.bazel, where we wire Codex's dependencies and runtime.
|
||||
_INVENTORY_SLOT = "# @CODEX_V8_UPSTREAM_FILEGROUPS@"
|
||||
_FILE_GROUPS = "# File group rules"
|
||||
_GENERATED_FILES = "# Generated files"
|
||||
|
||||
def _upstream_filegroups(upstream):
|
||||
before_and_groups = upstream.split(_FILE_GROUPS)
|
||||
if len(before_and_groups) != 2:
|
||||
fail("V8 source import: expected one File group rules section; review the new pin's BUILD.bazel")
|
||||
groups_and_after = before_and_groups[1].split(_GENERATED_FILES)
|
||||
if len(groups_and_after) != 2:
|
||||
fail("V8 source import: expected one Generated files boundary; review the new pin's BUILD.bazel")
|
||||
|
||||
groups = []
|
||||
statement = []
|
||||
for line in groups_and_after[0].split("\n"):
|
||||
if statement:
|
||||
statement.append(line)
|
||||
if line == ")":
|
||||
source = "\n".join(statement)
|
||||
if statement[0] == "filegroup(":
|
||||
groups.append(source)
|
||||
elif 'name = "lib_dragonbox",' not in source and 'name = "lib_fp16",' not in source:
|
||||
fail("V8 filegroup import: unexpected library; review and wire it in third_party/v8/engine.BUILD.bazel: " + source)
|
||||
statement = []
|
||||
elif line in ["filegroup(", "v8_library("]:
|
||||
# The pinned section happens to contain two libraries. Both are
|
||||
# already provided by our dependency overlays; skip only those names.
|
||||
statement = [line]
|
||||
elif line.strip() and not line.startswith("#"):
|
||||
fail("V8 filegroup import: only filegroups can be reused here; review compiled targets (including v8_binary) in third_party/v8/engine.BUILD.bazel. Unexpected statement: " + line)
|
||||
|
||||
# Group count and library order can change without changing the owned graph.
|
||||
# Fail only when the source section is empty, malformed, or unsafe to reuse.
|
||||
if statement:
|
||||
fail("V8 filegroup import: unterminated statement; review the pinned BUILD.bazel: " + "\n".join(statement))
|
||||
if not groups:
|
||||
fail("V8 filegroup import: no filegroups found; review the pinned BUILD.bazel")
|
||||
return "\n\n".join(groups)
|
||||
|
||||
def _engine_repository_impl(ctx):
|
||||
ctx.download_and_extract(
|
||||
url = ctx.attr.urls,
|
||||
integrity = ctx.attr.integrity,
|
||||
stripPrefix = ctx.attr.strip_prefix,
|
||||
)
|
||||
inventory = _upstream_filegroups(ctx.read("BUILD.bazel"))
|
||||
|
||||
# MSVC and GNU Windows require different x64 stack scanners. Keep that one
|
||||
# choice in our graph while taking all other membership from the V8 pin.
|
||||
msvc_scanner = '"src/heap/base/asm/x64/push_registers_masm.asm"'
|
||||
if inventory.count(msvc_scanner) != 1:
|
||||
fail("V8 source import: expected one x64 MSVC scanner input; review the Windows stack selector")
|
||||
inventory = inventory.replace(msvc_scanner, '":windows_x64_stack_assembly"')
|
||||
template = ctx.read(ctx.attr._engine_build)
|
||||
if template.count(_INVENTORY_SLOT) != 1:
|
||||
fail("Codex V8 BUILD template must contain exactly one upstream filegroup slot")
|
||||
|
||||
for patch in ctx.attr.patches:
|
||||
ctx.patch(patch, strip = ctx.attr.patch_strip)
|
||||
|
||||
# Preserve V8's source layout and the two third-party package boundaries
|
||||
# (disarm and fadec); neither is in the Codex V8 closure. Keep upstream's
|
||||
# platform/CPU package and prevent upstream toolchain discovery.
|
||||
for path in [
|
||||
"MODULE.bazel",
|
||||
"BUILD.bazel",
|
||||
"bazel/toolchain/BUILD.bazel",
|
||||
"bazel/patches/BUILD.bazel",
|
||||
]:
|
||||
ctx.delete(path)
|
||||
ctx.file("BUILD.bazel", template.replace(_INVENTORY_SLOT, inventory))
|
||||
|
||||
engine_repository = repository_rule(
|
||||
implementation = _engine_repository_impl,
|
||||
attrs = {
|
||||
"urls": attr.string_list(mandatory = True),
|
||||
"integrity": attr.string(mandatory = True),
|
||||
"strip_prefix": attr.string(mandatory = True),
|
||||
"patches": attr.label_list(allow_files = True),
|
||||
"patch_strip": attr.int(default = 3),
|
||||
"_engine_build": attr.label(
|
||||
default = Label("//third_party/v8:engine.BUILD.bazel"),
|
||||
allow_single_file = True,
|
||||
),
|
||||
},
|
||||
doc = "Fetch the pinned V8 source tree and install Codex's engine graph.",
|
||||
)
|
||||
45
third_party/v8/engine_rules.bzl
vendored
Normal file
45
third_party/v8/engine_rules.bzl
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"""Owned V8 source selection and test metadata derived from the engine policy."""
|
||||
|
||||
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
|
||||
load("@v8//:bazel/defs.bzl", "FlagInfo", "build_config_content")
|
||||
|
||||
def _options_impl(ctx):
|
||||
return FlagInfo(value = ctx.build_setting_value)
|
||||
|
||||
# Source-only features keep upstream select names without adding CLI options.
|
||||
# ABI/runtime selections are internal settings controlled by artifact profiles.
|
||||
v8_fixed_source_features = rule(
|
||||
implementation = _options_impl,
|
||||
build_setting = config.bool(flag = False),
|
||||
)
|
||||
|
||||
def _v8_build_config_impl(ctx):
|
||||
config = json.decode(build_config_content(json.encode(ctx.attr.arch), "true" if ctx.attr.icu else "false"))
|
||||
defines = ctx.attr.config[CcInfo].compilation_context.defines.to_list()
|
||||
config.update({
|
||||
"cppgc_microtask_queue": "V8_CPPGC_MICROTASK_QUEUE" in defines,
|
||||
"wasm_random_fuzzers": "V8_WASM_RANDOM_FUZZERS" in defines,
|
||||
})
|
||||
ctx.actions.write(ctx.outputs.out, json.encode(config) + "\n")
|
||||
return [DefaultInfo(files = depset([ctx.outputs.out]))]
|
||||
|
||||
_v8_build_config = rule(
|
||||
implementation = _v8_build_config_impl,
|
||||
attrs = {
|
||||
"arch": attr.string(mandatory = True),
|
||||
"config": attr.label(mandatory = True, providers = [CcInfo]),
|
||||
"icu": attr.bool(mandatory = True),
|
||||
"out": attr.output(mandatory = True),
|
||||
},
|
||||
)
|
||||
|
||||
def v8_build_config(name, arch):
|
||||
"""Keep upstream test metadata aligned with the owned platform features."""
|
||||
for mode in ["icu", "noicu"]:
|
||||
_v8_build_config(
|
||||
name = mode + "/" + name,
|
||||
arch = arch,
|
||||
config = ":define_flags",
|
||||
icu = mode == "icu",
|
||||
out = mode + "/" + name + ".json",
|
||||
)
|
||||
11
third_party/v8/fast_float.BUILD.bazel
vendored
Normal file
11
third_party/v8/fast_float.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Codex header-only overlay for the V8 DEPS revision; the include prefix
|
||||
# preserves V8's third_party checkout layout across the repository boundary.
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "fast_float",
|
||||
hdrs = glob(["include/fast_float/*.h"]),
|
||||
include_prefix = "third_party/fast_float/src/include",
|
||||
strip_include_prefix = "include",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
12
third_party/v8/fp16.BUILD.bazel
vendored
Normal file
12
third_party/v8/fp16.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# Codex overlay for the V8 DEPS revision. Mirrors :lib_fp16 in V8's
|
||||
# BUILD.bazel, exporting its headers at V8's expected include path.
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "fp16",
|
||||
hdrs = glob(["include/**/*.h"]),
|
||||
include_prefix = "third_party/fp16/src/include",
|
||||
includes = ["include"],
|
||||
strip_include_prefix = "include",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
13
third_party/v8/gnu_libcxx_shared_exception_symbols.txt
vendored
Normal file
13
third_party/v8/gnu_libcxx_shared_exception_symbols.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# libc++ intentionally leaves these exception functions in std:: across ABI
|
||||
# namespaces. Prefer the Bazel toolchain definitions if both runtimes link.
|
||||
# Keep constructors taking std::__Cr::string strong in the V8 archive.
|
||||
_ZNSt11logic_errorC1EPKc
|
||||
_ZNSt11logic_errorC1ERKS_
|
||||
_ZNSt11logic_errorC2EPKc
|
||||
_ZNSt11logic_errorC2ERKS_
|
||||
_ZNSt11logic_erroraSERKS_
|
||||
_ZNSt13runtime_errorC1EPKc
|
||||
_ZNSt13runtime_errorC1ERKS_
|
||||
_ZNSt13runtime_errorC2EPKc
|
||||
_ZNSt13runtime_errorC2ERKS_
|
||||
_ZNSt13runtime_erroraSERKS_
|
||||
197
third_party/v8/highway.BUILD.bazel
vendored
Normal file
197
third_party/v8/highway.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
# Adapted from google/highway's BUILD at the V8 DEPS revision 2607d3b5:
|
||||
# https://github.com/google/highway/blob/2607d3b5b0113992fe84d3848859eae13b3b52c1/BUILD
|
||||
# Keep :hwy and its compiler configuration; omit upstream tests/other libraries.
|
||||
# Codex adds private V8 runtime settings, disables module maps and builds
|
||||
# statically (no upstream HWY_SHARED_DEFINE). See README.md for update checks.
|
||||
load("@@//third_party/v8:dependency_config.bzl", "RUSTY_V8_DEPENDENCY_COPTS", "RUSTY_V8_DEPENDENCY_DEPS")
|
||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("@rules_license//rules:license.bzl", "license")
|
||||
|
||||
package(
|
||||
default_applicable_licenses = [":license"],
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
license(
|
||||
name = "license",
|
||||
package_name = "highway",
|
||||
license_kinds = ["@rules_license//licenses/generic:notice"],
|
||||
)
|
||||
|
||||
# Dual-licensed Apache 2 and 3-clause BSD.
|
||||
licenses(["notice"])
|
||||
|
||||
exports_files(["LICENSE"])
|
||||
|
||||
# Detect compiler:
|
||||
config_setting(
|
||||
name = "compiler_clang",
|
||||
flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "compiler_lexan",
|
||||
flag_values = {"@bazel_tools//tools/cpp:compiler": "lexan"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "compiler_clang_cl",
|
||||
flag_values = {"@bazel_tools//tools/cpp:compiler": "clang-cl"},
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "compiler_clangcl",
|
||||
match_any = [
|
||||
":compiler_clang_cl",
|
||||
":compiler_lexan",
|
||||
],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "compiler_msvc",
|
||||
flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "compiler_emscripten",
|
||||
constraint_values = [
|
||||
"@platforms//cpu:wasm32",
|
||||
],
|
||||
)
|
||||
|
||||
# See https://github.com/bazelbuild/bazel/issues/12707
|
||||
config_setting(
|
||||
name = "compiler_gcc_bug",
|
||||
flag_values = {
|
||||
"@bazel_tools//tools/cpp:compiler": "compiler",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "compiler_gcc_actual",
|
||||
flag_values = {
|
||||
"@bazel_tools//tools/cpp:compiler": "gcc",
|
||||
},
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "compiler_gcc",
|
||||
match_any = [
|
||||
":compiler_gcc_bug",
|
||||
":compiler_gcc_actual",
|
||||
],
|
||||
)
|
||||
|
||||
# Additional warnings for Clang OR GCC (skip for MSVC)
|
||||
CLANG_GCC_COPTS = [
|
||||
"-Wunused",
|
||||
"-Wextra-semi",
|
||||
"-Wunreachable-code",
|
||||
"-Wshadow",
|
||||
"-Wmissing-declarations",
|
||||
]
|
||||
|
||||
# Warnings supported by Clang and Clang-cl
|
||||
CLANG_OR_CLANGCL_OPTS = CLANG_GCC_COPTS + [
|
||||
"-Wfloat-overflow-conversion",
|
||||
"-Wfloat-zero-conversion",
|
||||
"-Wfor-loop-analysis",
|
||||
"-Wgnu-redeclared-enum",
|
||||
"-Winfinite-recursion",
|
||||
"-Wliteral-conversion",
|
||||
"-Wno-c++98-compat",
|
||||
"-Wno-unused-command-line-argument",
|
||||
"-Wprivate-header",
|
||||
"-Wself-assign",
|
||||
"-Wstring-conversion",
|
||||
"-Wtautological-overlap-compare",
|
||||
"-Wthread-safety-analysis",
|
||||
"-Wundefined-func-template",
|
||||
"-Wunreachable-code-aggressive",
|
||||
"-Wunused-comparison",
|
||||
]
|
||||
|
||||
# Warnings only supported by Clang, but not Clang-cl
|
||||
CLANG_ONLY_COPTS = CLANG_OR_CLANGCL_OPTS + [
|
||||
# Do not treat the third_party headers as system headers when building
|
||||
# highway - the errors are pertinent.
|
||||
"--no-system-header-prefix=third_party/highway",
|
||||
]
|
||||
|
||||
COPTS = select({
|
||||
":compiler_msvc": [],
|
||||
":compiler_gcc": CLANG_GCC_COPTS,
|
||||
":compiler_clangcl": CLANG_OR_CLANGCL_OPTS,
|
||||
# Default to clang because compiler detection only works in Bazel
|
||||
"//conditions:default": CLANG_ONLY_COPTS,
|
||||
}) + select({
|
||||
"@platforms//cpu:riscv64": [
|
||||
"-march=rv64gcv1p0",
|
||||
"-menable-experimental-extensions",
|
||||
],
|
||||
"//conditions:default": [
|
||||
],
|
||||
})
|
||||
|
||||
# V8 embeds Highway in a static archive, including on Windows: do not set
|
||||
# HWY_SHARED_DEFINE, which marks its consumers as importing from a DLL.
|
||||
cc_library(
|
||||
name = "hwy",
|
||||
srcs = [
|
||||
"hwy/abort.cc",
|
||||
"hwy/aligned_allocator.cc",
|
||||
"hwy/per_target.cc",
|
||||
"hwy/print.cc",
|
||||
"hwy/targets.cc",
|
||||
],
|
||||
# Normal headers with include guards
|
||||
hdrs = [
|
||||
"hwy/abort.h",
|
||||
"hwy/aligned_allocator.h",
|
||||
"hwy/base.h",
|
||||
"hwy/cache_control.h",
|
||||
"hwy/detect_compiler_arch.h", # private
|
||||
"hwy/print.h",
|
||||
"hwy/x86_cpuid.h",
|
||||
],
|
||||
copts = COPTS + RUSTY_V8_DEPENDENCY_COPTS,
|
||||
features = ["-module_maps"],
|
||||
local_defines = ["hwy_EXPORTS"],
|
||||
textual_hdrs = [
|
||||
# These are textual because config macros influence them:
|
||||
"hwy/detect_targets.h", # private
|
||||
"hwy/targets.h",
|
||||
# This .cc file #includes itself through foreach_target.h
|
||||
"hwy/per_target.cc",
|
||||
# End of list
|
||||
"hwy/highway.h", # public
|
||||
"hwy/foreach_target.h", # public
|
||||
"hwy/per_target.h", # public
|
||||
"hwy/print-inl.h", # public
|
||||
"hwy/highway_export.h", # public
|
||||
"hwy/ops/arm_neon-inl.h",
|
||||
"hwy/ops/arm_sve-inl.h",
|
||||
"hwy/ops/emu128-inl.h",
|
||||
"hwy/ops/generic_ops-inl.h",
|
||||
"hwy/ops/inside-inl.h",
|
||||
"hwy/ops/scalar-inl.h",
|
||||
"hwy/ops/set_macros-inl.h",
|
||||
"hwy/ops/shared-inl.h",
|
||||
"hwy/ops/x86_128-inl.h",
|
||||
"hwy/ops/x86_256-inl.h",
|
||||
"hwy/ops/x86_512-inl.h",
|
||||
"hwy/ops/x86_avx3-inl.h",
|
||||
# Select avoids recompiling native arch if only non-native changed
|
||||
] + select({
|
||||
":compiler_emscripten": [
|
||||
"hwy/ops/wasm_128-inl.h",
|
||||
"hwy/ops/wasm_256-inl.h",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@platforms//cpu:riscv64": ["hwy/ops/rvv-inl.h"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = RUSTY_V8_DEPENDENCY_DEPS,
|
||||
)
|
||||
131
third_party/v8/icu.BUILD.bazel
vendored
Normal file
131
third_party/v8/icu.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
# Copyright 2021 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
# ICU must use the same C++ runtime as the V8 artifact and its host generators.
|
||||
_ICU_V8_COPTS = select({
|
||||
"@@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [
|
||||
"/D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
"/D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
"/D_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
],
|
||||
"@@//third_party/v8:use_rusty_v8_custom_libcxx": [
|
||||
"-nostdinc++",
|
||||
"-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
"-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
"-D_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
"-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
_ICU_MSVC_COPTS = [
|
||||
"/wd4005",
|
||||
"/wd4068",
|
||||
"/wd4267",
|
||||
"/utf-8",
|
||||
]
|
||||
|
||||
_ICU_LIBRARY_COPTS = select({
|
||||
"@@//third_party/v8:platform_windows_msvc": _ICU_MSVC_COPTS,
|
||||
"//conditions:default": ["-Wno-deprecated-declarations"],
|
||||
}) + _ICU_V8_COPTS
|
||||
|
||||
_ICU_V8_RUNTIME_DEPS = select({
|
||||
"@@//third_party/v8:use_rusty_v8_custom_libcxx": [
|
||||
"@@//third_party/v8:rusty_v8_custom_libcxx_headers",
|
||||
"@@//third_party/v8:rusty_v8_custom_libcxx_runtime",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
filegroup(
|
||||
name = "icudata",
|
||||
srcs = ["common/icudtl.dat"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "icuuc",
|
||||
srcs = glob([
|
||||
"source/common/**/*.h",
|
||||
"source/common/**/*.cpp",
|
||||
]),
|
||||
copts = _ICU_LIBRARY_COPTS,
|
||||
data = [":icudata"],
|
||||
defines = [
|
||||
"HAVE_DLOPEN=0",
|
||||
"UCONFIG_ONLY_HTML_CONVERSION=1",
|
||||
"U_CHARSET_IS_UTF8=1",
|
||||
"U_USING_ICU_NAMESPACE=0",
|
||||
"U_ENABLE_DYLOAD=0",
|
||||
"USE_CHROMIUM_ICU=1",
|
||||
"U_ENABLE_TRACING=1",
|
||||
"U_ENABLE_RESOURCE_TRACING=0",
|
||||
"UNISTR_FROM_STRING_EXPLICIT=",
|
||||
"UNISTR_FROM_CHAR_EXPLICIT=",
|
||||
] + select({
|
||||
"@platforms//os:windows": [
|
||||
"U_STATIC_IMPLEMENTATION",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = [
|
||||
"source/common",
|
||||
"source/i18n",
|
||||
],
|
||||
local_defines = [
|
||||
"U_COMMON_IMPLEMENTATION",
|
||||
"U_ICUDATAENTRY_IN_COMMON",
|
||||
],
|
||||
tags = ["requires-rtti"],
|
||||
deps = _ICU_V8_RUNTIME_DEPS,
|
||||
alwayslink = 1,
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "icui18n",
|
||||
srcs = glob([
|
||||
"source/i18n/**/*.h",
|
||||
"source/i18n/**/*.cpp",
|
||||
]),
|
||||
copts = _ICU_LIBRARY_COPTS,
|
||||
local_defines = [
|
||||
"U_I18N_IMPLEMENTATION",
|
||||
],
|
||||
deps = [":icuuc"] + _ICU_V8_RUNTIME_DEPS,
|
||||
alwayslink = 1,
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "icu",
|
||||
srcs = [
|
||||
"source/stubdata/stubdata.cpp",
|
||||
"source/stubdata/stubdata.h",
|
||||
],
|
||||
hdrs = glob([
|
||||
"source/common/unicode/*.h",
|
||||
"source/i18n/unicode/*.h",
|
||||
]),
|
||||
copts = select({
|
||||
"@@//third_party/v8:platform_windows_msvc": _ICU_MSVC_COPTS,
|
||||
"@platforms//os:windows": [
|
||||
"-Wno-deprecated-declarations",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + _ICU_V8_COPTS,
|
||||
include_prefix = "third_party/icu",
|
||||
local_defines = [
|
||||
"U_COMMON_IMPLEMENTATION",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":icui18n",
|
||||
":icuuc",
|
||||
] + _ICU_V8_RUNTIME_DEPS,
|
||||
alwayslink = 1,
|
||||
)
|
||||
205
third_party/v8/libcxx.BUILD.bazel
vendored
Normal file
205
third_party/v8/libcxx.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
load("@//third_party/v8:libcxx_rules.bzl", "libcxx_library")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
config_setting(
|
||||
name = "is_linux",
|
||||
constraint_values = ["@platforms//os:linux"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "is_macos",
|
||||
constraint_values = ["@platforms//os:macos"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "is_windows",
|
||||
constraint_values = ["@platforms//os:windows"],
|
||||
)
|
||||
|
||||
LIBCXX_SRCS = [
|
||||
"src/algorithm.cpp",
|
||||
"src/any.cpp",
|
||||
"src/atomic.cpp",
|
||||
"src/barrier.cpp",
|
||||
"src/bind.cpp",
|
||||
"src/call_once.cpp",
|
||||
"src/charconv.cpp",
|
||||
"src/chrono.cpp",
|
||||
"src/condition_variable.cpp",
|
||||
"src/condition_variable_destructor.cpp",
|
||||
"src/error_category.cpp",
|
||||
"src/exception.cpp",
|
||||
"src/filesystem/directory_iterator.cpp",
|
||||
"src/filesystem/filesystem_error.cpp",
|
||||
"src/filesystem/operations.cpp",
|
||||
"src/filesystem/path.cpp",
|
||||
"src/functional.cpp",
|
||||
"src/future.cpp",
|
||||
"src/hash.cpp",
|
||||
"src/ios.cpp",
|
||||
"src/ios.instantiations.cpp",
|
||||
"src/iostream.cpp",
|
||||
"src/locale.cpp",
|
||||
"src/memory.cpp",
|
||||
"src/mutex.cpp",
|
||||
"src/mutex_destructor.cpp",
|
||||
"src/new.cpp",
|
||||
"src/new_handler.cpp",
|
||||
"src/new_helpers.cpp",
|
||||
"src/optional.cpp",
|
||||
"src/random.cpp",
|
||||
"src/random_shuffle.cpp",
|
||||
"src/regex.cpp",
|
||||
"src/ryu/d2fixed.cpp",
|
||||
"src/ryu/d2s.cpp",
|
||||
"src/ryu/f2s.cpp",
|
||||
"src/shared_mutex.cpp",
|
||||
"src/stdexcept.cpp",
|
||||
"src/string.cpp",
|
||||
"src/strstream.cpp",
|
||||
"src/system_error.cpp",
|
||||
"src/thread.cpp",
|
||||
"src/typeinfo.cpp",
|
||||
"src/valarray.cpp",
|
||||
"src/variant.cpp",
|
||||
"src/vector.cpp",
|
||||
"src/verbose_abort.cpp",
|
||||
]
|
||||
|
||||
cc_library(
|
||||
name = "headers",
|
||||
hdrs = glob(["include/**"]),
|
||||
strip_include_prefix = "include",
|
||||
deps = ["@//third_party/v8/libcxx_config:headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "internal_headers",
|
||||
hdrs = glob([
|
||||
"src/**/*.h",
|
||||
"src/**/*.ipp",
|
||||
]),
|
||||
includes = ["src"],
|
||||
)
|
||||
|
||||
libcxx_library(
|
||||
name = "libcxx",
|
||||
srcs = LIBCXX_SRCS + select({
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [
|
||||
"src/filesystem/filesystem_clock.cpp",
|
||||
],
|
||||
":is_linux": [
|
||||
"src/filesystem/directory_entry.cpp",
|
||||
"src/filesystem/filesystem_clock.cpp",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":is_windows": [
|
||||
"src/support/win32/locale_win32.cpp",
|
||||
"src/support/win32/support.cpp",
|
||||
"src/support/win32/thread_win32.cpp",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
copts = select({
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [
|
||||
"/EHsc",
|
||||
"/GR",
|
||||
"/std:c++latest",
|
||||
"/Zc:__cplusplus",
|
||||
"/clang:-fstrict-aliasing",
|
||||
"/clang:-Wno-nullability-completeness",
|
||||
"/clang:-Wno-unused-parameter",
|
||||
"/clang:-Wundef",
|
||||
# libc++ uses the Microsoft exception implementation with /MT.
|
||||
"/clang:-Xclang",
|
||||
"/clang:--dependent-lib=libcpmt",
|
||||
"/wd4005",
|
||||
],
|
||||
"//conditions:default": [
|
||||
"-fexceptions",
|
||||
"-frtti",
|
||||
"-fstrict-aliasing",
|
||||
"-fvisibility=hidden",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-nostdinc++",
|
||||
"-std=c++23",
|
||||
"-Wno-nullability-completeness",
|
||||
"-Wno-unused-parameter",
|
||||
"-Wundef",
|
||||
],
|
||||
}) + select({
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [],
|
||||
":is_windows": ["-Wno-macro-redefined"],
|
||||
"//conditions:default": ["-fPIC"],
|
||||
}) + select({
|
||||
":is_macos": [
|
||||
"-Wno-pragma-clang-attribute",
|
||||
"-Wno-thread-safety-analysis",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
defines = [
|
||||
"CR_LIBCXX_REVISION=b16984ce99c702355a5b2b4c52574e82cec41fb9",
|
||||
"LIBC_NAMESPACE=__llvm_libc_cr",
|
||||
"_LIBCPP_BUILDING_LIBRARY",
|
||||
"_LIBCPP_CONSTINIT=constinit",
|
||||
"_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
"_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
"_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
] + select({
|
||||
# The Windows build uses the Microsoft ABI, never Itanium libc++abi.
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [],
|
||||
"//conditions:default": [
|
||||
"LIBCXX_BUILDING_LIBCXXABI",
|
||||
"_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
],
|
||||
}) + select({
|
||||
"@llvm//platforms/config:musl": [
|
||||
# Chromium's checked-in __config_site uses this switch to enable
|
||||
# libc++'s musl-specific configuration.
|
||||
"ANDROID_HOST_MUSL",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [],
|
||||
":is_windows": [
|
||||
"NTDDI_VERSION=NTDDI_WIN7",
|
||||
"WINVER=_WIN32_WINNT_WIN7",
|
||||
"_WIN32_WINNT=_WIN32_WINNT_WIN7",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
implementation_deps = [
|
||||
":headers",
|
||||
":internal_headers",
|
||||
"@rusty_v8_llvm_libc//:headers",
|
||||
] + select({
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [],
|
||||
"//conditions:default": ["@rusty_v8_libcxxabi//:headers"],
|
||||
}) + select({
|
||||
":is_linux": [
|
||||
"@@llvm++kernel_headers+kernel_headers//:kernel_headers",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@llvm//platforms/config:gnu": [
|
||||
"@@llvm++glibc+glibc//:gnu_libc_headers",
|
||||
],
|
||||
"@llvm//platforms/config:musl": [
|
||||
"@@llvm++musl+musl_libc//:musl_libc_headers",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = ["src"],
|
||||
local_defines = select({
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [
|
||||
"NTDDI_VERSION=NTDDI_WIN7",
|
||||
"WINVER=_WIN32_WINNT_WIN7",
|
||||
"_WIN32_WINNT=_WIN32_WINNT_WIN7",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
12
third_party/v8/libcxx_config/BUILD.bazel
vendored
Normal file
12
third_party/v8/libcxx_config/BUILD.bazel
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
cc_library(
|
||||
name = "headers",
|
||||
hdrs = [
|
||||
"__assertion_handler",
|
||||
"__config_site",
|
||||
],
|
||||
includes = ["."],
|
||||
)
|
||||
27
third_party/v8/libcxx_config/__assertion_handler
vendored
Normal file
27
third_party/v8/libcxx_config/__assertion_handler
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// -*- C++ -*-
|
||||
|
||||
#ifndef _LIBCPP___ASSERTION_HANDLER
|
||||
#define _LIBCPP___ASSERTION_HANDLER
|
||||
|
||||
#include <__config>
|
||||
#include <__verbose_abort>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if defined(OFFICIAL_BUILD) && !defined(DCHECK_ALWAYS_ON)
|
||||
|
||||
[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI void __libcpp_hardening_failure() {
|
||||
__builtin_trap();
|
||||
}
|
||||
|
||||
#define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __libcpp_hardening_failure())
|
||||
|
||||
#else
|
||||
|
||||
#define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_ABORT("%s", message)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _LIBCPP___ASSERTION_HANDLER
|
||||
55
third_party/v8/libcxx_config/__config_site
vendored
Normal file
55
third_party/v8/libcxx_config/__config_site
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef _LIBCPP_CONFIG_SITE
|
||||
#define _LIBCPP_CONFIG_SITE
|
||||
|
||||
#define _LIBCPP_ABI_NAMESPACE __Cr
|
||||
#define _LIBCPP_ABI_VERSION 2
|
||||
|
||||
#define _LIBCPP_ABI_FORCE_ITANIUM 0
|
||||
#define _LIBCPP_ABI_FORCE_MICROSOFT 0
|
||||
#define _LIBCPP_HAS_THREADS 1
|
||||
#define _LIBCPP_HAS_MONOTONIC_CLOCK 1
|
||||
#define _LIBCPP_HAS_TERMINAL 1
|
||||
|
||||
#ifdef ANDROID_HOST_MUSL
|
||||
#define _LIBCPP_HAS_MUSL_LIBC 1
|
||||
#else
|
||||
#define _LIBCPP_HAS_MUSL_LIBC 0
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _LIBCPP_HAS_THREAD_API_PTHREAD 0
|
||||
#define _LIBCPP_HAS_THREAD_API_EXTERNAL 0
|
||||
#define _LIBCPP_HAS_THREAD_API_WIN32 1
|
||||
#else
|
||||
#define _LIBCPP_HAS_THREAD_API_PTHREAD 1
|
||||
#define _LIBCPP_HAS_THREAD_API_EXTERNAL 0
|
||||
#define _LIBCPP_HAS_THREAD_API_WIN32 0
|
||||
#endif
|
||||
|
||||
#define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0
|
||||
#define _LIBCPP_HAS_FILESYSTEM 1
|
||||
#define _LIBCPP_HAS_RANDOM_DEVICE 1
|
||||
#define _LIBCPP_HAS_LOCALIZATION 1
|
||||
#define _LIBCPP_HAS_UNICODE 1
|
||||
#define _LIBCPP_HAS_WIDE_CHARACTERS 1
|
||||
#define _LIBCPP_HAS_TIME_ZONE_DATABASE 1
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define _LIBCPP_PSTL_BACKEND_LIBDISPATCH
|
||||
#else
|
||||
#define _LIBCPP_PSTL_BACKEND_STD_THREAD
|
||||
#endif
|
||||
|
||||
#define _LIBCPP_ASSERTION_SEMANTIC_DEFAULT \
|
||||
_LIBCPP_ASSERTION_SEMANTIC_HARDENING_DEPENDENT
|
||||
|
||||
#define _LIBCPP_LIBC_PICOLIBC 0
|
||||
#define _LIBCPP_LIBC_NEWLIB 0
|
||||
|
||||
#define _LIBCPP_NO_AUTO_LINK
|
||||
#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
|
||||
#define _LIBCPP_NO_ABI_TAG
|
||||
#define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__)
|
||||
#define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
|
||||
|
||||
#endif // _LIBCPP_CONFIG_SITE
|
||||
26
third_party/v8/libcxx_rules.bzl
vendored
Normal file
26
third_party/v8/libcxx_rules.bzl
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Select the installed SDK-capable toolchain for native Windows libc++."""
|
||||
|
||||
load("@llvm//toolchain/runtimes:cc_runtime_library.bzl", "cc_runtime_stage0_library")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
def libcxx_library(name, **kwargs):
|
||||
cc_runtime_stage0_library(
|
||||
name = name + "_stage0",
|
||||
**kwargs
|
||||
)
|
||||
cc_library(
|
||||
name = name + "_native_windows",
|
||||
linkstatic = True,
|
||||
target_compatible_with = select({
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
**kwargs
|
||||
)
|
||||
native.alias(
|
||||
name = name,
|
||||
actual = select({
|
||||
"@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": ":" + name + "_native_windows",
|
||||
"//conditions:default": ":" + name + "_stage0",
|
||||
}),
|
||||
)
|
||||
99
third_party/v8/libcxxabi.BUILD.bazel
vendored
Normal file
99
third_party/v8/libcxxabi.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
load("@llvm//toolchain/runtimes:cc_runtime_library.bzl", "cc_runtime_stage0_library")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
config_setting(
|
||||
name = "is_linux",
|
||||
constraint_values = ["@platforms//os:linux"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "is_windows",
|
||||
constraint_values = ["@platforms//os:windows"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "headers",
|
||||
hdrs = glob(["include/**"]),
|
||||
strip_include_prefix = "include",
|
||||
)
|
||||
|
||||
cc_runtime_stage0_library(
|
||||
name = "libcxxabi",
|
||||
srcs = [
|
||||
"src/abort_message.cpp",
|
||||
"src/cxa_aux_runtime.cpp",
|
||||
"src/cxa_default_handlers.cpp",
|
||||
"src/cxa_demangle.cpp",
|
||||
"src/cxa_exception.cpp",
|
||||
"src/cxa_exception_storage.cpp",
|
||||
"src/cxa_guard.cpp",
|
||||
"src/cxa_handlers.cpp",
|
||||
"src/cxa_personality.cpp",
|
||||
"src/cxa_vector.cpp",
|
||||
"src/cxa_virtual.cpp",
|
||||
"src/fallback_malloc.cpp",
|
||||
"src/private_typeinfo.cpp",
|
||||
"src/stdlib_exception.cpp",
|
||||
"src/stdlib_stdexcept.cpp",
|
||||
"src/stdlib_typeinfo.cpp",
|
||||
] + select({
|
||||
":is_linux": ["src/cxa_thread_atexit.cpp"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
copts = [
|
||||
"-fexceptions",
|
||||
"-frtti",
|
||||
"-fstrict-aliasing",
|
||||
"-fvisibility=hidden",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-nostdinc++",
|
||||
"-std=c++23",
|
||||
"-Wno-nullability-completeness",
|
||||
"-Wno-unused-parameter",
|
||||
"-Wundef",
|
||||
] + select({
|
||||
":is_windows": ["-Wno-macro-redefined"],
|
||||
"//conditions:default": ["-fPIC"],
|
||||
}),
|
||||
defines = [
|
||||
"LIBCXXABI_SILENT_TERMINATE",
|
||||
"_LIBCPP_BUILDING_LIBRARY",
|
||||
"_LIBCPP_CONSTINIT=constinit",
|
||||
"_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
"_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
"_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
"_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
] + select({
|
||||
"@llvm//platforms/config:musl": [
|
||||
"ANDROID_HOST_MUSL",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
implementation_deps = [
|
||||
":headers",
|
||||
"@//third_party/v8/libcxx_config:headers",
|
||||
"@rusty_v8_libcxx//:headers",
|
||||
"@rusty_v8_libcxx//:internal_headers",
|
||||
] + select({
|
||||
":is_linux": [
|
||||
"@@llvm++kernel_headers+kernel_headers//:kernel_headers",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"@llvm//platforms/config:gnu": [
|
||||
"@@llvm++glibc+glibc//:gnu_libc_headers",
|
||||
],
|
||||
"@llvm//platforms/config:musl": [
|
||||
"@@llvm++musl+musl_libc//:musl_libc_headers",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = ["src"],
|
||||
textual_hdrs = glob([
|
||||
"src/**/*.def",
|
||||
"src/**/*.h",
|
||||
"src/**/*.inc",
|
||||
]),
|
||||
)
|
||||
17
third_party/v8/llvm_libc.BUILD.bazel
vendored
Normal file
17
third_party/v8/llvm_libc.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
cc_library(
|
||||
name = "headers",
|
||||
hdrs = glob(["**/*.h"]),
|
||||
defines = ["LIBC_NAMESPACE=__llvm_libc_cr"],
|
||||
includes = ["."],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "v8_headers",
|
||||
hdrs = glob(["shared/**/*.h"]),
|
||||
include_prefix = "third_party/llvm-libc/src",
|
||||
deps = [":headers"],
|
||||
)
|
||||
102
third_party/v8/native_windows.bzl
vendored
Normal file
102
third_party/v8/native_windows.bzl
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
"""Inputs for the native Windows V8 build, using rules_cc's installed SDK."""
|
||||
|
||||
load("@llvm//toolchain:selects.bzl", "LLVM_VERSION")
|
||||
load("@rules_cc//cc/private/toolchain:cc_configure.bzl", "MSVC_ENVVARS")
|
||||
load("@rules_cc//cc/private/toolchain:windows_cc_configure.bzl", "configure_windows_toolchain")
|
||||
|
||||
# Match @llvm 0.8.11's bindgen compiler. Unlike its minimal bootstrap seed,
|
||||
# these official distributions also contain the MSVC compiler-rt builtins.
|
||||
_LLVM_WINDOWS = {
|
||||
"x86_64": "d96c2cc1736f4eb7fa43cb9bbdf56d93551a9ae0a9aadb9c99c3c3b2b712a234",
|
||||
"aarch64": "de718c58ebbc5f61d58c17b90457fcf42983bc2c4a4aba3e010d108713bfd7f1",
|
||||
}
|
||||
|
||||
def _native_windows_llvm_impl(repository_ctx):
|
||||
if repository_ctx.os.name.lower().find("windows") != -1:
|
||||
arch = repository_ctx.os.arch.lower()
|
||||
arch = {"amd64": "x86_64", "arm64": "aarch64"}.get(arch, arch)
|
||||
if arch not in _LLVM_WINDOWS:
|
||||
fail("V8's native Windows build supports x64 and arm64, got " + arch)
|
||||
filename = "clang+llvm-%s-%s-pc-windows-msvc" % (LLVM_VERSION, arch)
|
||||
repository_ctx.download_and_extract(
|
||||
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-%s/%s.tar.xz" % (LLVM_VERSION, filename.replace("+", "%2B")),
|
||||
sha256 = _LLVM_WINDOWS[arch],
|
||||
stripPrefix = filename,
|
||||
)
|
||||
|
||||
# Native-only inputs are empty on other hosts, without fetching Windows
|
||||
# archives on Linux/macOS during //... queries or public lockfile checks.
|
||||
repository_ctx.file("BUILD.bazel", """
|
||||
load("@rules_cc//cc:defs.bzl", "cc_import")
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
exports_files(["BUILD.bazel"])
|
||||
filegroup(name = "llvm-readobj", srcs = glob(["bin/llvm-readobj.exe"], allow_empty = True))
|
||||
filegroup(name = "llvm-lib", srcs = glob(["bin/llvm-lib.exe"], allow_empty = True))
|
||||
# Tool paths alone do not invalidate cached C++ actions when the pin changes.
|
||||
# Keep compiler resources and bundled runtime DLLs in the toolchain inputs.
|
||||
filegroup(
|
||||
name = "compiler_files",
|
||||
srcs = glob(["bin/clang-cl.exe", "bin/*.dll", "lib/clang/*/include/**"], allow_empty = True),
|
||||
)
|
||||
filegroup(
|
||||
name = "linker_files",
|
||||
srcs = glob(["bin/lld-link.exe", "bin/*.dll"], allow_empty = True),
|
||||
)
|
||||
filegroup(
|
||||
name = "archiver_files",
|
||||
srcs = glob(["bin/llvm-lib.exe", "bin/*.dll"], allow_empty = True),
|
||||
)
|
||||
filegroup(
|
||||
name = "all_files",
|
||||
srcs = [":compiler_files", ":linker_files", ":archiver_files"],
|
||||
)
|
||||
[
|
||||
filegroup(
|
||||
name = "builtins_" + arch,
|
||||
srcs = glob(["lib/clang/*/lib/windows/clang_rt.builtins-%s.lib" % arch], allow_empty = True),
|
||||
)
|
||||
for arch in ["x86_64", "aarch64"]
|
||||
]
|
||||
filegroup(
|
||||
name = "builtins_archive",
|
||||
srcs = select({
|
||||
"@platforms//cpu:x86_64": [":builtins_x86_64"],
|
||||
"@platforms//cpu:aarch64": [":builtins_aarch64"],
|
||||
}),
|
||||
)
|
||||
cc_import(
|
||||
name = "builtins",
|
||||
static_library = ":builtins_archive",
|
||||
)
|
||||
""")
|
||||
|
||||
native_windows_llvm = repository_rule(
|
||||
implementation = _native_windows_llvm_impl,
|
||||
)
|
||||
|
||||
def _native_windows_cc_impl(repository_ctx):
|
||||
if repository_ctx.os.name.lower().find("windows") != -1:
|
||||
configure_windows_toolchain(repository_ctx)
|
||||
else:
|
||||
repository_ctx.file("BUILD.bazel", "# Native Windows toolchains are only available on Windows.\n")
|
||||
|
||||
native_windows_cc = repository_rule(
|
||||
implementation = _native_windows_cc_impl,
|
||||
attrs = {
|
||||
# A Bazel repo label rather than a user's ambient installation path.
|
||||
# The rules_cc pin patch reads this only for this opt-in repository.
|
||||
"native_llvm": attr.label(allow_single_file = True, mandatory = True),
|
||||
},
|
||||
environ = MSVC_ENVVARS + [
|
||||
"BAZEL_CONLYOPTS",
|
||||
"BAZEL_COPTS",
|
||||
"BAZEL_CXXOPTS",
|
||||
"BAZEL_LINKOPTS",
|
||||
"BAZEL_SH",
|
||||
"BAZEL_WIN32_WINNT",
|
||||
"SYSTEMROOT",
|
||||
"PROGRAMFILES",
|
||||
],
|
||||
configure = True,
|
||||
local = True,
|
||||
)
|
||||
7
third_party/v8/native_windows_link_probe.c
vendored
Normal file
7
third_party/v8/native_windows_link_probe.c
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// __powidf2 is in compiler-rt's generic builtins on both x64 and arm64.
|
||||
// MSVC must resolve it from the staged V8 archive without any LLVM search path.
|
||||
extern double __powidf2(double, int);
|
||||
|
||||
int main(void) {
|
||||
return __powidf2(3.0, 4) == 81.0 ? 0 : 1;
|
||||
}
|
||||
47
third_party/v8/push_registers_gnullvm.S
vendored
Normal file
47
third_party/v8/push_registers_gnullvm.S
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
.text
|
||||
.globl PushAllRegistersAndIterateStack
|
||||
.seh_proc PushAllRegistersAndIterateStack
|
||||
PushAllRegistersAndIterateStack:
|
||||
push %rbp
|
||||
.seh_pushreg %rbp
|
||||
mov %rsp, %rbp
|
||||
.seh_setframe %rbp, 0
|
||||
push $0xCDCDCD
|
||||
.seh_stackalloc 8
|
||||
push %rsi
|
||||
.seh_pushreg %rsi
|
||||
push %rdi
|
||||
.seh_pushreg %rdi
|
||||
push %rbx
|
||||
.seh_pushreg %rbx
|
||||
push %r12
|
||||
.seh_pushreg %r12
|
||||
push %r13
|
||||
.seh_pushreg %r13
|
||||
push %r14
|
||||
.seh_pushreg %r14
|
||||
push %r15
|
||||
.seh_pushreg %r15
|
||||
sub $160, %rsp
|
||||
.seh_stackalloc 160
|
||||
# Preserve Windows unwind metadata even though this is now GNU syntax.
|
||||
# Without the .seh_* directives, SEH and stack walking can mis-handle
|
||||
# unwinding across this callback frame.
|
||||
.seh_endprologue
|
||||
movdqa %xmm6, 144(%rsp)
|
||||
movdqa %xmm7, 128(%rsp)
|
||||
movdqa %xmm8, 112(%rsp)
|
||||
movdqa %xmm9, 96(%rsp)
|
||||
movdqa %xmm10, 80(%rsp)
|
||||
movdqa %xmm11, 64(%rsp)
|
||||
movdqa %xmm12, 48(%rsp)
|
||||
movdqa %xmm13, 32(%rsp)
|
||||
movdqa %xmm14, 16(%rsp)
|
||||
movdqa %xmm15, 0(%rsp)
|
||||
mov %r8, %r9
|
||||
mov %rsp, %r8
|
||||
call *%r9
|
||||
add $224, %rsp
|
||||
pop %rbp
|
||||
ret
|
||||
.seh_endproc
|
||||
16
third_party/v8/rusty_v8_152_2_0.sha256
vendored
Normal file
16
third_party/v8/rusty_v8_152_2_0.sha256
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
feab9ae0384bebaa99c1d000654462c9d42123d587185c7876aaeef7d76ff749 librusty_v8_ptrcomp_sandbox_release_aarch64-apple-darwin.a.gz
|
||||
b9d5652ebca515eb2bf4c2ee4a6551b2567117b5aa720f430d2032616dd7e3b5 src_binding_ptrcomp_sandbox_release_aarch64-apple-darwin.rs
|
||||
daf327876f7753a94b3b05d6d64776258def3ae67503ac75db9c35c6deaa28a5 rusty_v8_ptrcomp_sandbox_release_aarch64-pc-windows-msvc.lib.gz
|
||||
572ed16ff09bb7944f4b35c659ff62dcd3faf43a0351e3f94f011e01b2f92a62 src_binding_ptrcomp_sandbox_release_aarch64-pc-windows-msvc.rs
|
||||
1054464a623006cdf5e25ae20877002bf3edb9a2c2f3e64f44a8714742b15e87 librusty_v8_ptrcomp_sandbox_release_aarch64-unknown-linux-gnu.a.gz
|
||||
3e4d5fecdbe0f98a6017e69d7ca82519a77fb032c5eb5e4cdbecdd3e2ec519d5 src_binding_ptrcomp_sandbox_release_aarch64-unknown-linux-gnu.rs
|
||||
1a60f36a3dd8778802e6980668c4d65a3c7305d85a5d2debf466d9aa0daadd75 librusty_v8_ptrcomp_sandbox_release_aarch64-unknown-linux-musl.a.gz
|
||||
3e4d5fecdbe0f98a6017e69d7ca82519a77fb032c5eb5e4cdbecdd3e2ec519d5 src_binding_ptrcomp_sandbox_release_aarch64-unknown-linux-musl.rs
|
||||
bfe19d9b633b61d99780ece89690427fef4b985c6b4196536eaf94571166fc24 librusty_v8_ptrcomp_sandbox_release_x86_64-apple-darwin.a.gz
|
||||
b9d5652ebca515eb2bf4c2ee4a6551b2567117b5aa720f430d2032616dd7e3b5 src_binding_ptrcomp_sandbox_release_x86_64-apple-darwin.rs
|
||||
cd829415695b30ad61b306b23a381e11276f14bb0b46815ac5ed8b96711d002d rusty_v8_ptrcomp_sandbox_release_x86_64-pc-windows-msvc.lib.gz
|
||||
572ed16ff09bb7944f4b35c659ff62dcd3faf43a0351e3f94f011e01b2f92a62 src_binding_ptrcomp_sandbox_release_x86_64-pc-windows-msvc.rs
|
||||
b3b490f2aa809eda7f6ac727f851fb00ce8355be72827577cfaac28c7137dbcd librusty_v8_ptrcomp_sandbox_release_x86_64-unknown-linux-gnu.a.gz
|
||||
3e4d5fecdbe0f98a6017e69d7ca82519a77fb032c5eb5e4cdbecdd3e2ec519d5 src_binding_ptrcomp_sandbox_release_x86_64-unknown-linux-gnu.rs
|
||||
2f2679773a12576dc6b89b0f7d70e8190e5aea8a57f8f6364efaffdd1497d0e7 librusty_v8_ptrcomp_sandbox_release_x86_64-unknown-linux-musl.a.gz
|
||||
3e4d5fecdbe0f98a6017e69d7ca82519a77fb032c5eb5e4cdbecdd3e2ec519d5 src_binding_ptrcomp_sandbox_release_x86_64-unknown-linux-musl.rs
|
||||
8
third_party/v8/rusty_v8_152_2_0_release_manifests.sha256
vendored
Normal file
8
third_party/v8/rusty_v8_152_2_0_release_manifests.sha256
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
5cebc5830127b460ae8af23004430fd70b535bb22d599d68d024b60df08400d8 rusty_v8_ptrcomp_sandbox_release_aarch64-apple-darwin.sha256
|
||||
a4c895148240270c8b685bf0b86ca6257533c3ecad8833560e462b0854cb3bfc rusty_v8_ptrcomp_sandbox_release_aarch64-pc-windows-msvc.sha256
|
||||
94195fe3a70a6043474afabd145c0bbe322f409e95a52c745d64c9f929f80a22 rusty_v8_ptrcomp_sandbox_release_aarch64-unknown-linux-gnu.sha256
|
||||
c35b823c23c32d349029467e8fa75cc492146a658dc5bd37597d93b125cc64e8 rusty_v8_ptrcomp_sandbox_release_aarch64-unknown-linux-musl.sha256
|
||||
f9259abda68c50bfd71d856ece97d272832ac9c18e91fdc892fa9625a003b7bc rusty_v8_ptrcomp_sandbox_release_x86_64-apple-darwin.sha256
|
||||
e16bf2d7bc4b64a96a89e87048d61b9c466040e4c82ae64cfe9f7f2052ef3179 rusty_v8_ptrcomp_sandbox_release_x86_64-pc-windows-msvc.sha256
|
||||
1ec730635970ab1c0e8f4764ea113ad29d69d7f8d4c2ae69f3d766434a759350 rusty_v8_ptrcomp_sandbox_release_x86_64-unknown-linux-gnu.sha256
|
||||
12acf8747729db642a9d49d3448174471fb07cf47e01a6238222e2d9299de72f rusty_v8_ptrcomp_sandbox_release_x86_64-unknown-linux-musl.sha256
|
||||
35
third_party/v8/simdutf.BUILD.bazel
vendored
Normal file
35
third_party/v8/simdutf.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Codex overlay for upstream simdutf source, not copied from V8's BUILD.
|
||||
# V8 builds Chromium's single-header vendored form; match its Version field
|
||||
# and review vendor changes on each upgrade (README.md#updating-source-dependencies).
|
||||
load("@@//third_party/v8:dependency_config.bzl", "RUSTY_V8_DEPENDENCY_COPTS", "RUSTY_V8_DEPENDENCY_DEPS")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "simdutf",
|
||||
srcs = ["src/simdutf.cpp"],
|
||||
hdrs = glob(["include/**/*.h"]),
|
||||
# Match V8's C++20 feature macros, including atomic_ref for the base64 API.
|
||||
copts = select({
|
||||
"@@//third_party/v8:platform_windows_msvc": [
|
||||
"/std:c++20",
|
||||
"/Zc:__cplusplus",
|
||||
],
|
||||
"//conditions:default": ["-std=c++20"],
|
||||
}) + RUSTY_V8_DEPENDENCY_COPTS,
|
||||
features = ["-module_maps"],
|
||||
include_prefix = "third_party/simdutf",
|
||||
includes = [
|
||||
"include",
|
||||
"src",
|
||||
],
|
||||
strip_include_prefix = "include",
|
||||
textual_hdrs = glob(
|
||||
[
|
||||
"src/**/*.h",
|
||||
"src/**/*.cpp",
|
||||
],
|
||||
exclude = ["src/simdutf.cpp"],
|
||||
),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = RUSTY_V8_DEPENDENCY_DEPS,
|
||||
)
|
||||
21
third_party/v8/v8_crate.BUILD.bazel
vendored
Normal file
21
third_party/v8/v8_crate.BUILD.bazel
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
filegroup(
|
||||
name = "binding_cc",
|
||||
srcs = ["src/binding.cc"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "binding_hpp",
|
||||
srcs = ["src/binding.hpp"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "crdtp_binding_cc",
|
||||
srcs = ["src/crdtp_binding.cc"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "support_h",
|
||||
srcs = ["src/support.h"],
|
||||
)
|
||||
254
third_party/v8/v8_defs.patch
vendored
Normal file
254
third_party/v8/v8_defs.patch
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
# What: adapt the pinned V8 rule helpers to Codex's engine configuration.
|
||||
# Scope: bazel/defs.bzl and bazel/config/v8-target-cpu.bzl; the engine graph
|
||||
# and dependency choices live in third_party/v8/engine.BUILD.bazel. ABI,
|
||||
# runtime and CPU settings are internal outputs of artifact_profile.bzl.
|
||||
# Preserve Chromium libc++ headers/runtime, Clang Windows driver flags, and
|
||||
# the Windows target-ABI snapshot tool. The optional
|
||||
# Linux backtrace link flag is omitted because that feature is fixed off.
|
||||
# On a V8 pin change, review these hunks and build the native canary matrix.
|
||||
|
||||
diff --git a/orig/v8-15.2.124.1/bazel/defs.bzl b/mod/v8-15.2.124.1/bazel/defs.bzl
|
||||
--- a/orig/v8-15.2.124.1/bazel/defs.bzl
|
||||
+++ b/mod/v8-15.2.124.1/bazel/defs.bzl
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
_create_option_flag = rule(
|
||||
implementation = _options_impl,
|
||||
- build_setting = config.bool(flag = True),
|
||||
+ build_setting = config.bool(flag = False),
|
||||
attrs = {
|
||||
"scope": attr.string(),
|
||||
},
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
_create_option_string = rule(
|
||||
implementation = _options_impl,
|
||||
- build_setting = config.string(flag = True),
|
||||
+ build_setting = config.string(flag = False),
|
||||
attrs = {
|
||||
"scope": attr.string(),
|
||||
},
|
||||
@@ -42,12 +42,30 @@
|
||||
)
|
||||
|
||||
def v8_flag(name, default = False):
|
||||
- _create_option_flag(name = name, build_setting_default = default, scope = "universal")
|
||||
- native.config_setting(name = "is_" + name, flag_values = {name: "True"})
|
||||
- native.config_setting(name = "is_not_" + name, flag_values = {name: "False"})
|
||||
-
|
||||
-def v8_string(name, default = ""):
|
||||
- _create_option_string(name = name, build_setting_default = default, scope = "universal")
|
||||
+ _create_option_flag(
|
||||
+ name = name,
|
||||
+ build_setting_default = default,
|
||||
+ scope = "universal",
|
||||
+ visibility = ["//visibility:public"],
|
||||
+ )
|
||||
+ native.config_setting(
|
||||
+ name = "is_" + name,
|
||||
+ flag_values = {name: "True"},
|
||||
+ visibility = ["//visibility:public"],
|
||||
+ )
|
||||
+ native.config_setting(
|
||||
+ name = "is_not_" + name,
|
||||
+ flag_values = {name: "False"},
|
||||
+ visibility = ["//visibility:public"],
|
||||
+ )
|
||||
+
|
||||
+def v8_string(name, default = "", visibility = None):
|
||||
+ _create_option_string(
|
||||
+ name = name,
|
||||
+ build_setting_default = default,
|
||||
+ scope = "universal",
|
||||
+ visibility = visibility,
|
||||
+ )
|
||||
|
||||
def v8_int(name, default = 0):
|
||||
_create_option_int(name = name, build_setting_default = default, scope = "universal")
|
||||
@@ -106,7 +124,18 @@
|
||||
|
||||
def _default_args():
|
||||
return struct(
|
||||
- deps = [":define_flags", "@libcxx//:libc++"],
|
||||
+ deps = [":define_flags"] + select({
|
||||
+ "@v8//:is_v8_use_rusty_v8_custom_libcxx": [
|
||||
+ "@@//third_party/v8:rusty_v8_custom_libcxx_headers",
|
||||
+ "@@//third_party/v8:rusty_v8_custom_libcxx_runtime",
|
||||
+ ],
|
||||
+ "//conditions:default": [],
|
||||
+ }) + select({
|
||||
+ "@@//third_party/v8:platform_windows_msvc": [
|
||||
+ "@@//third_party/v8:native_windows_compiler_builtins",
|
||||
+ ],
|
||||
+ "//conditions:default": [],
|
||||
+ }),
|
||||
defines = select({
|
||||
"@v8//bazel/config:is_windows": [
|
||||
"UNICODE",
|
||||
@@ -136,11 +165,27 @@
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
- "@v8//bazel/config:is_clang": [
|
||||
- "-Wno-invalid-offsetof",
|
||||
- "-Wno-deprecated-this-capture",
|
||||
- "-Wno-deprecated-declarations",
|
||||
- "-std=c++20",
|
||||
+ "@@//third_party/v8:use_rusty_v8_custom_libcxx_native_windows": [
|
||||
+ "/D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
+ "/D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
+ "/D_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
+ ],
|
||||
+ "@v8//:is_v8_use_rusty_v8_custom_libcxx": [
|
||||
+ "-nostdinc++",
|
||||
+ "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
+ "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE",
|
||||
+ "-D_LIBCPP_INSTRUMENTED_WITH_ASAN=0",
|
||||
+ "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
|
||||
+ ],
|
||||
+ "//conditions:default": [],
|
||||
+ }) + select({
|
||||
+ "@@//third_party/v8:platform_windows_msvc": [
|
||||
+ "/std:c++20",
|
||||
+ "/Zc:__cplusplus",
|
||||
+ "/clang:-fconstexpr-steps=2000000",
|
||||
+ "/clang:-Wno-deprecated-declarations",
|
||||
+ "/clang:-Wno-deprecated-this-capture",
|
||||
+ "/clang:-Wno-invalid-offsetof",
|
||||
],
|
||||
"@v8//bazel/config:is_gcc": [
|
||||
"-Wno-extra",
|
||||
@@ -161,9 +206,17 @@
|
||||
"-std=gnu++2a",
|
||||
],
|
||||
"@v8//bazel/config:is_windows": [
|
||||
- "/std:c++20",
|
||||
- ],
|
||||
- "//conditions:default": [],
|
||||
+ "-Wno-invalid-offsetof",
|
||||
+ "-Wno-deprecated-this-capture",
|
||||
+ "-Wno-deprecated-declarations",
|
||||
+ "-std=c++20",
|
||||
+ ],
|
||||
+ "//conditions:default": [
|
||||
+ "-Wno-invalid-offsetof",
|
||||
+ "-Wno-deprecated-this-capture",
|
||||
+ "-Wno-deprecated-declarations",
|
||||
+ "-std=c++20",
|
||||
+ ],
|
||||
}) + select({
|
||||
"@v8//bazel/config:is_gcc_fastbuild": [
|
||||
# Non-debug builds without optimizations fail because
|
||||
@@ -186,16 +239,18 @@
|
||||
}),
|
||||
includes = ["include"],
|
||||
linkopts = select({
|
||||
- "@v8//bazel/config:is_windows": [
|
||||
+ "@@//third_party/v8:platform_windows_msvc": [
|
||||
"Winmm.lib",
|
||||
"DbgHelp.lib",
|
||||
"Advapi32.lib",
|
||||
],
|
||||
+ "@v8//bazel/config:is_windows": [
|
||||
+ "-lwinmm",
|
||||
+ "-ldbghelp",
|
||||
+ "-ladvapi32",
|
||||
+ ],
|
||||
"@v8//bazel/config:is_macos": ["-pthread"],
|
||||
- "//conditions:default": ["-Wl,--no-as-needed -ldl -latomic -pthread"],
|
||||
- }) + select({
|
||||
- ":should_add_rdynamic": ["-rdynamic"],
|
||||
- "//conditions:default": [],
|
||||
+ "//conditions:default": ["-Wl,--no-as-needed -ldl -pthread"],
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -466,6 +521,12 @@
|
||||
def _mksnapshot(ctx):
|
||||
prefix = ctx.attr.prefix
|
||||
suffix = ctx.attr.suffix
|
||||
+
|
||||
+ # Windows cross-builds use Linux for the exec configuration, but the
|
||||
+ # snapshot generator must match the target ABI and run on the Windows
|
||||
+ # runner. Action strategies only choose where an action runs; they cannot
|
||||
+ # change this executable from the exec to the target configuration.
|
||||
+ tool = ctx.executable.target_tool if ctx.attr.target_os == "win" else ctx.executable.tool
|
||||
outs = [
|
||||
ctx.actions.declare_file(prefix + "/snapshot" + suffix + ".cc"),
|
||||
ctx.actions.declare_file(prefix + "/embedded" + suffix + ".S"),
|
||||
@@ -483,9 +544,22 @@
|
||||
"--embedded_src",
|
||||
outs[1].path,
|
||||
] + ctx.attr.args,
|
||||
- executable = ctx.executable.tool,
|
||||
+ executable = tool,
|
||||
progress_message = "Running mksnapshot",
|
||||
)
|
||||
+ if ctx.attr.inline_asm_converter:
|
||||
+ # The installed Windows toolchain sends .S files to MASM. V8 provides
|
||||
+ # this conversion for clang-cl so its generated assembly is compiled
|
||||
+ # as C++, using the same target flags as the rest of the engine.
|
||||
+ embedded_cc = ctx.actions.declare_file(prefix + "/embedded" + suffix + ".cc")
|
||||
+ ctx.actions.run(
|
||||
+ executable = ctx.attr.inline_asm_converter[DefaultInfo].files_to_run,
|
||||
+ inputs = [outs[1]],
|
||||
+ outputs = [embedded_cc],
|
||||
+ arguments = [outs[1].path, embedded_cc.path],
|
||||
+ mnemonic = "V8NativeWindowsInlineAssembly",
|
||||
+ )
|
||||
+ outs = [outs[0], embedded_cc]
|
||||
return [DefaultInfo(files = depset(outs))]
|
||||
|
||||
_v8_mksnapshot = rule(
|
||||
@@ -498,6 +572,13 @@
|
||||
executable = True,
|
||||
cfg = "exec",
|
||||
),
|
||||
+ "target_tool": attr.label(
|
||||
+ mandatory = True,
|
||||
+ allow_files = True,
|
||||
+ executable = True,
|
||||
+ cfg = "target",
|
||||
+ ),
|
||||
+ "inline_asm_converter": attr.label(executable = True, cfg = "exec"),
|
||||
"target_os": attr.string(mandatory = True),
|
||||
"prefix": attr.string(mandatory = True),
|
||||
"suffix": attr.string(mandatory = True),
|
||||
@@ -511,6 +592,11 @@
|
||||
args = args,
|
||||
prefix = "noicu",
|
||||
tool = ":noicu/mksnapshot" + suffix,
|
||||
+ target_tool = ":noicu/mksnapshot" + suffix,
|
||||
+ inline_asm_converter = select({
|
||||
+ "@@//third_party/v8:platform_windows_msvc": ":native_windows_inline_asm",
|
||||
+ "//conditions:default": None,
|
||||
+ }),
|
||||
suffix = suffix,
|
||||
target_os = select({
|
||||
"@v8//bazel/config:is_macos": "mac",
|
||||
@@ -523,6 +609,11 @@
|
||||
args = args,
|
||||
prefix = "icu",
|
||||
tool = ":icu/mksnapshot" + suffix,
|
||||
+ target_tool = ":icu/mksnapshot" + suffix,
|
||||
+ inline_asm_converter = select({
|
||||
+ "@@//third_party/v8:platform_windows_msvc": ":native_windows_inline_asm",
|
||||
+ "//conditions:default": None,
|
||||
+ }),
|
||||
suffix = suffix,
|
||||
target_os = select({
|
||||
"@v8//bazel/config:is_macos": "mac",
|
||||
diff --git a/orig/v8-15.2.124.1/bazel/config/v8-target-cpu.bzl b/mod/v8-15.2.124.1/bazel/config/v8-target-cpu.bzl
|
||||
--- a/orig/v8-15.2.124.1/bazel/config/v8-target-cpu.bzl
|
||||
+++ b/mod/v8-15.2.124.1/bazel/config/v8-target-cpu.bzl
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
v8_target_cpu = rule(
|
||||
implementation = _host_target_cpu_impl,
|
||||
- build_setting = config.string(flag = True),
|
||||
- doc = "CPU that V8 will generate code for.",
|
||||
+ build_setting = config.string(flag = False),
|
||||
+ doc = "Internal CPU that V8 generates code for; set by the artifact transition.",
|
||||
attrs = {
|
||||
"scope": attr.string(),
|
||||
},
|
||||
431
third_party/voice/BUILD.bazel
vendored
Normal file
431
third_party/voice/BUILD.bazel
vendored
Normal file
@@ -0,0 +1,431 @@
|
||||
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
|
||||
load("@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl", "native_tool_toolchain")
|
||||
load(":native.bzl", "native_prefix")
|
||||
load(":native_link.bzl", "native_link")
|
||||
load(":pkg_config.bzl", "pkg_config")
|
||||
load(":runtime.bzl", "native_runtime")
|
||||
load(":windows_native.bzl", "windows_build_tools", "windows_native_prefix")
|
||||
|
||||
# All native build consumers must receive the same pinned source manifest.
|
||||
exports_files(["opus-toolchain.cmake"])
|
||||
|
||||
filegroup(
|
||||
name = "source_inputs",
|
||||
srcs = [
|
||||
"prepare_sources.py",
|
||||
"sources.json",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Fetch and unpack only when this source target is requested by a build.
|
||||
filegroup(
|
||||
name = "sources",
|
||||
srcs = [
|
||||
"@voice_glib//:sources",
|
||||
"@voice_gst_plugins_base//:sources",
|
||||
"@voice_gst_plugins_good//:sources",
|
||||
"@voice_gstreamer//:sources",
|
||||
"@voice_libffi//:sources",
|
||||
"@voice_meson//:sources",
|
||||
"@voice_ninja//:sources",
|
||||
"@voice_opus//:sources",
|
||||
"@voice_pcre2//:sources",
|
||||
"@voice_proxy_libintl//:sources",
|
||||
"@voice_zlib//:sources",
|
||||
],
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "build_inputs",
|
||||
srcs = [
|
||||
"assemble_package.py",
|
||||
"build_native.py",
|
||||
"linux_runtime.py",
|
||||
"macos_runtime.py",
|
||||
"package_runtime.py",
|
||||
"runtime.py",
|
||||
"sdk.py",
|
||||
"windows_build_inputs.py",
|
||||
"windows_runtime.py",
|
||||
":source_inputs",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "native_recipe",
|
||||
srcs = [
|
||||
"build_native.py",
|
||||
"windows_build_inputs.py",
|
||||
":source_inputs",
|
||||
],
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "pkg_config_linker",
|
||||
actual = select({
|
||||
"@platforms//os:macos": "@llvm//tools:ld64.lld",
|
||||
"//conditions:default": "@llvm//tools:ld.lld",
|
||||
}),
|
||||
)
|
||||
|
||||
# Keep the pinned pkg-config sources, but explicitly use LLVM archive tools.
|
||||
# The upstream bootstrap otherwise selects host ar/ranlib on macOS.
|
||||
pkg_config(
|
||||
name = "pkg_config_unix",
|
||||
build_data = [
|
||||
":pkg_config_linker",
|
||||
"@llvm//tools:llvm-ar",
|
||||
"@llvm//tools:llvm-ranlib",
|
||||
],
|
||||
# foreign_cc normalizes copied source timestamps, preserving the release
|
||||
# configure files when remote execution materializes inputs in a new order.
|
||||
configure_in_place = True,
|
||||
configure_options = [
|
||||
"--with-internal-glib",
|
||||
"--disable-shared",
|
||||
"--enable-define-prefix",
|
||||
],
|
||||
copts = ["-Wno-int-conversion"],
|
||||
env = {
|
||||
"AR": "$(execpath @llvm//tools:llvm-ar)",
|
||||
"LD": "$(execpath :pkg_config_linker)",
|
||||
"PKG_CONFIG": "/bin/false",
|
||||
"RANLIB": "$(execpath @llvm//tools:llvm-ranlib)",
|
||||
},
|
||||
lib_source = "@pkgconfig_src//:all_srcs",
|
||||
# foreign_cc rewrites *-config files as text. Keep the executable out of
|
||||
# that transformation, which otherwise corrupts its native code signature.
|
||||
out_binaries = ["pkg-config-tool"],
|
||||
out_include_dir = "",
|
||||
out_static_libs = [],
|
||||
postfix_script = 'mv "$$INSTALLDIR/bin/pkg-config" "$$INSTALLDIR/bin/pkg-config-tool"',
|
||||
tags = ["manual"],
|
||||
target_compatible_with = select({
|
||||
"@platforms//os:windows": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
# Internal GLib needs no pkg-config. Avoid bootstrapping another copy first;
|
||||
# the explicit failing command above forbids falling back to a host copy.
|
||||
toolchain = "@rules_foreign_cc//toolchains:preinstalled_pkgconfig_toolchain",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
native_tool_toolchain(
|
||||
name = "pkg_config_tool",
|
||||
path = "$(execpath :pkg_config_unix)",
|
||||
tags = ["manual"],
|
||||
target = ":pkg_config_unix",
|
||||
)
|
||||
|
||||
# Build-script tools select their execution platform, independently of target ABI.
|
||||
alias(
|
||||
name = "pkg_config",
|
||||
actual = select({
|
||||
":windows_x86_64": ":windows_tools_x86_64",
|
||||
":windows_aarch64": ":windows_tools_aarch64",
|
||||
"//conditions:default": ":pkg_config_unix",
|
||||
}),
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Explicitly select the installed pkgconf and pinned CMake in Windows voice CI.
|
||||
native_tool_toolchain(
|
||||
name = "windows_pkg_config_tool",
|
||||
env = {"PKG_CONFIG": "$(execpath :pkg_config)"},
|
||||
path = "$(execpath :pkg_config)",
|
||||
target = ":pkg_config",
|
||||
)
|
||||
|
||||
toolchain(
|
||||
name = "windows_pkg_config_toolchain",
|
||||
exec_compatible_with = ["@platforms//os:windows"],
|
||||
toolchain = ":windows_pkg_config_tool",
|
||||
toolchain_type = "@rules_foreign_cc//toolchains:pkgconfig_toolchain",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
toolchain(
|
||||
name = "windows_cmake_toolchain",
|
||||
exec_compatible_with = ["@platforms//os:windows"],
|
||||
toolchain = "@cmake-3.31.8-windows-x86_64//:cmake_tool",
|
||||
toolchain_type = "@rules_foreign_cc//toolchains:cmake_toolchain",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "archives",
|
||||
srcs = [
|
||||
"@voice_archive_glib//file",
|
||||
"@voice_archive_gst_plugins_base//file",
|
||||
"@voice_archive_gst_plugins_good//file",
|
||||
"@voice_archive_gstreamer//file",
|
||||
"@voice_archive_libffi//file",
|
||||
"@voice_archive_meson//file",
|
||||
"@voice_archive_ninja//file",
|
||||
"@voice_archive_opus//file",
|
||||
"@voice_archive_pcre2//file",
|
||||
"@voice_archive_proxy_libintl//file",
|
||||
"@voice_archive_zlib//file",
|
||||
],
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "optimized",
|
||||
values = {"compilation_mode": "opt"},
|
||||
)
|
||||
|
||||
# Configure probes execute target binaries: constrain each action's host too.
|
||||
_NATIVE_PLATFORMS = [
|
||||
("macos", "aarch64", "apple-darwin"),
|
||||
("macos", "x86_64", "apple-darwin"),
|
||||
("linux", "aarch64", "unknown-linux-gnu"),
|
||||
("linux", "x86_64", "unknown-linux-gnu"),
|
||||
]
|
||||
|
||||
[
|
||||
config_setting(
|
||||
name = os + "_" + cpu,
|
||||
constraint_values = [
|
||||
"@platforms//os:" + os,
|
||||
"@platforms//cpu:" + cpu,
|
||||
] + (["@llvm//constraints/libc:gnu.2.28"] if os == "linux" else []),
|
||||
)
|
||||
for os, cpu, _ in _NATIVE_PLATFORMS
|
||||
]
|
||||
|
||||
[
|
||||
native_prefix(
|
||||
name = "native_prefix_" + os + "_" + cpu,
|
||||
archives = [":archives"],
|
||||
# Preserve the native recipe's Meson/CMake release optimization after
|
||||
# toolchain flags, without optimizing unrelated native targets or tools.
|
||||
copts = select({
|
||||
":optimized": ["-O3"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
exec_compatible_with = [
|
||||
"@platforms//os:" + os,
|
||||
"@platforms//cpu:" + cpu,
|
||||
],
|
||||
tags = ["manual"],
|
||||
target = cpu + "-" + suffix,
|
||||
target_compatible_with = select({
|
||||
":" + os + "_" + cpu: [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
)
|
||||
for os, cpu, suffix in _NATIVE_PLATFORMS
|
||||
]
|
||||
|
||||
alias(
|
||||
name = "native_prefix",
|
||||
actual = select({
|
||||
":" + os + "_" + cpu: ":native_prefix_" + os + "_" + cpu
|
||||
for os, cpu, _ in _NATIVE_PLATFORMS
|
||||
} | {
|
||||
":windows_" + cpu + "_msvc": ":native_prefix_windows_" + cpu
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
}),
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
[
|
||||
native_runtime(
|
||||
name = "native_runtime_" + os + "_" + cpu,
|
||||
exec_compatible_with = [
|
||||
"@platforms//os:" + os,
|
||||
"@platforms//cpu:" + cpu,
|
||||
],
|
||||
prefix = ":native_prefix_" + os + "_" + cpu,
|
||||
tags = ["manual"],
|
||||
target = cpu + "-" + suffix,
|
||||
target_compatible_with = select({
|
||||
":" + os + "_" + cpu: [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
)
|
||||
for os, cpu, suffix in _NATIVE_PLATFORMS
|
||||
]
|
||||
|
||||
alias(
|
||||
name = "native_runtime",
|
||||
actual = select({
|
||||
":" + os + "_" + cpu: ":native_runtime_" + os + "_" + cpu
|
||||
for os, cpu, _ in _NATIVE_PLATFORMS
|
||||
} | {
|
||||
":windows_" + cpu + "_msvc": ":native_runtime_windows_" + cpu
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
}),
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "native_sdk",
|
||||
srcs = [":native_runtime"],
|
||||
output_group = "sdk",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
[
|
||||
native_link(
|
||||
name = "native_link_" + os + "_" + cpu,
|
||||
runtime = ":native_runtime_" + os + "_" + cpu,
|
||||
tags = ["manual"],
|
||||
target = cpu + "-" + suffix,
|
||||
target_compatible_with = select({
|
||||
":" + os + "_" + cpu: [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
)
|
||||
for os, cpu, suffix in _NATIVE_PLATFORMS
|
||||
]
|
||||
|
||||
alias(
|
||||
name = "native_link",
|
||||
actual = select({
|
||||
":" + os + "_" + cpu: ":native_link_" + os + "_" + cpu
|
||||
for os, cpu, _ in _NATIVE_PLATFORMS
|
||||
} | {
|
||||
":windows_" + cpu + "_msvc": ":native_link_windows_" + cpu
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
}),
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Explicit opt-in inputs: no private downloader is loaded by the public module.
|
||||
# CMake and Cygwin use x64 emulation on native ARM64; Python/MSVC/pkgconf do not.
|
||||
filegroup(
|
||||
name = "windows_tools_unavailable",
|
||||
srcs = [],
|
||||
)
|
||||
|
||||
label_flag(
|
||||
name = "windows_installed_tools",
|
||||
build_setting_default = ":windows_tools_unavailable",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
[
|
||||
config_setting(
|
||||
name = "windows_" + cpu,
|
||||
constraint_values = [
|
||||
"@platforms//os:windows",
|
||||
"@platforms//cpu:" + cpu,
|
||||
],
|
||||
)
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
]
|
||||
|
||||
[
|
||||
config_setting(
|
||||
name = "windows_" + cpu + "_msvc",
|
||||
constraint_values = [
|
||||
"@platforms//os:windows",
|
||||
"@platforms//cpu:" + cpu,
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
)
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
]
|
||||
|
||||
[
|
||||
windows_build_tools(
|
||||
name = "windows_tools_" + cpu,
|
||||
includes = ["@msvc_runtime//:msvc_include"] + ["@windows_sdk//:winsdk_" + part + "_include" for part in ("ucrt", "shared", "um", "winrt")],
|
||||
installed_tools = ":windows_installed_tools",
|
||||
libraries = ["@msvc_runtime//:msvc_lib_" + arch] + ["@windows_sdk//:winsdk_" + part + "_lib_" + arch for part in ("ucrt", "um")],
|
||||
msvc = "@msvc_runtime//:msvc_tools_" + arch,
|
||||
sdk = "@windows_sdk//:winsdk_tools_" + arch,
|
||||
tags = ["manual"],
|
||||
target = cpu + "-pc-windows-msvc",
|
||||
target_compatible_with = [
|
||||
"@platforms//os:windows",
|
||||
"@platforms//cpu:" + cpu,
|
||||
],
|
||||
)
|
||||
for cpu, arch in (
|
||||
("x86_64", "x64"),
|
||||
("aarch64", "arm64"),
|
||||
)
|
||||
]
|
||||
|
||||
[
|
||||
windows_native_prefix(
|
||||
name = "native_prefix_windows_" + cpu,
|
||||
archives = [":archives"],
|
||||
build_tools = ":windows_tools_" + cpu,
|
||||
exec_compatible_with = [
|
||||
"@platforms//os:windows",
|
||||
"@platforms//cpu:" + cpu,
|
||||
],
|
||||
tags = ["manual"],
|
||||
target_compatible_with = select({
|
||||
":windows_" + cpu + "_msvc": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
]
|
||||
|
||||
[
|
||||
native_runtime(
|
||||
name = "native_runtime_windows_" + cpu,
|
||||
exec_compatible_with = [
|
||||
"@platforms//os:windows",
|
||||
"@platforms//cpu:" + cpu,
|
||||
],
|
||||
prefix = ":native_prefix_windows_" + cpu,
|
||||
tags = ["manual"],
|
||||
target = cpu + "-pc-windows-msvc",
|
||||
target_compatible_with = select({
|
||||
":windows_" + cpu + "_msvc": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
windows_tools = ":windows_tools_" + cpu,
|
||||
)
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
]
|
||||
|
||||
[
|
||||
native_link(
|
||||
name = "native_link_windows_" + cpu,
|
||||
runtime = ":native_runtime_windows_" + cpu,
|
||||
tags = ["manual"],
|
||||
target = cpu + "-pc-windows-msvc",
|
||||
target_compatible_with = select({
|
||||
":windows_" + cpu + "_msvc": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
]
|
||||
|
||||
# Link a concrete symbol so CI checks the Windows CcInfo import-library path,
|
||||
# not only the native runtime and SDK artifact actions.
|
||||
[
|
||||
cc_binary(
|
||||
name = "windows_link_smoke_" + cpu,
|
||||
srcs = ["windows_link_smoke.cc"],
|
||||
tags = ["manual"],
|
||||
target_compatible_with = [
|
||||
"@platforms//os:windows",
|
||||
"@platforms//cpu:" + cpu,
|
||||
"@llvm//constraints/windows/abi:msvc",
|
||||
],
|
||||
deps = [":native_link_windows_" + cpu],
|
||||
)
|
||||
for cpu in ("x86_64", "aarch64")
|
||||
]
|
||||
36
third_party/voice/NOTICE.md
vendored
Normal file
36
third_party/voice/NOTICE.md
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# Native voice libraries in Codex releases
|
||||
|
||||
Codex release packages with voice include dynamically linked GStreamer and GLib
|
||||
libraries and selected plugins, plus their native library dependencies. These
|
||||
components have their own copyrights and licenses. Their notices accompany
|
||||
this file in `licenses/`: `LGPL-2.1.txt` for GStreamer and GLib,
|
||||
`proxy-libintl.txt` for libintl, `libffi.txt`, `PCRE2.md` and `sljit.txt`
|
||||
for PCRE2, `Opus.txt`, and `zlib.txt`. GVDB is included with GLib under LGPL.
|
||||
|
||||
The exact upstream versions, source archive URLs and SHA-256 digests are in
|
||||
`sources.json` alongside this notice. The corresponding build, runtime
|
||||
projection and package scripts are in the public Codex source tree under
|
||||
`third_party/voice/`. The source commit for this package is recorded in
|
||||
`manifest.json`. The native libraries remain separate dynamic libraries in
|
||||
platform-specific runtime directories. Replacements must be compatible with
|
||||
the package and, on macOS, have valid code signatures. Build tools listed in
|
||||
`sources.json` are build inputs, not bundled runtime libraries.
|
||||
|
||||
## Microsoft Visual C++ runtime (Windows)
|
||||
|
||||
Windows packages also contain the unmodified Microsoft Visual C++ runtime DLL
|
||||
`bin/vcruntime140.dll`, relative to this notice in release packages,
|
||||
copyright Microsoft Corporation, under Microsoft's applicable software license
|
||||
terms, separately from the open-source audio libraries. `windows-crt.json`
|
||||
records its version, official download, hashes, and redistribution references.
|
||||
The Apache and LGPL licenses for other components do not license this DLL.
|
||||
Microsoft's runtime terms and separate developer redistribution terms apply
|
||||
to the Microsoft component; the runtime terms alone do not grant redistribution.
|
||||
Only retail redistributable files are included; Microsoft signatures are retained.
|
||||
App-local runtime security updates must be delivered with Codex updates.
|
||||
|
||||
Microsoft provides the following license terms and redistribution information:
|
||||
|
||||
- [Visual C++ v14 Redistributable and Runtime license terms](https://visualstudio.microsoft.com/license-terms/vs2026-ga-visualcpp-v14-redist-runtime/)
|
||||
- [Visual C++ Redistributable downloads and support information](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170)
|
||||
- [Visual Studio 2026 redistribution information](https://learn.microsoft.com/en-us/visualstudio/releases/2026/redistribution)
|
||||
306
third_party/voice/README.md
vendored
Normal file
306
third_party/voice/README.md
vendored
Normal file
@@ -0,0 +1,306 @@
|
||||
# Native voice source inputs
|
||||
|
||||
This stage pins and prepares sources for a privately bundled, GStreamer-based
|
||||
audio runtime, including its native dependencies and build tools. It does not
|
||||
compile native libraries, link them into Codex or enable voice.
|
||||
|
||||
`sources.json` records the versions, URLs and SHA-256 digests of 11 archives:
|
||||
|
||||
| Purpose | Sources |
|
||||
| --- | --- |
|
||||
| GStreamer framework and plugin sources | `gstreamer`, `gst-plugins-base`, `gst-plugins-good` |
|
||||
| Supporting native libraries | `glib`, `libffi`, `pcre2`, `zlib`, `proxy-libintl` |
|
||||
| Audio codec | `opus` |
|
||||
| Build tools, not runtime libraries | `meson`, `ninja` |
|
||||
|
||||
GLib also includes `gvdb` in its archive; it is recorded without a separate fetch.
|
||||
These inputs do not include the complete platform toolchain for native builds.
|
||||
|
||||
Bazel uses standard `http_archive` rules to fetch, verify, unpack and cache the
|
||||
archives from that manifest. Run from the repository root:
|
||||
|
||||
```sh
|
||||
bazel build //third_party/voice:sources
|
||||
```
|
||||
|
||||
For offline preparation without Bazel, use Python 3.12 or newer and an existing
|
||||
archive directory whose filenames match the manifest:
|
||||
|
||||
```sh
|
||||
python3 third_party/voice/prepare_sources.py --archives /path/to/archives --output /path/to/new-sources
|
||||
python3 -m unittest discover -s third_party/voice -p 'test_*.py'
|
||||
```
|
||||
|
||||
The adapter verifies archive digests and bounds, then extracts with Python's
|
||||
`tarfile` data filter. It preserves links where supported and copies their archive
|
||||
targets when link creation is unavailable, including on Windows. It refuses an
|
||||
existing output directory and cleans up incomplete output. `prepared.json` records
|
||||
successful preparation, not the integrity of later edits to the extracted tree.
|
||||
|
||||
Ordinary CLI builds do not run either path. The Bazel `:sources` target is
|
||||
`manual`, so wildcard builds do not fetch these archives. `:source_inputs`
|
||||
exports the manifest and adapter for standalone consumers; `:sources` exposes
|
||||
extracted archives with Bazel build metadata. Neither target compiles libraries.
|
||||
|
||||
Checksums establish input identity, not security or license approval. Native
|
||||
compilation, final Cargo/Bazel linking, installed packages, minimum OS support
|
||||
and duplex audio validation remain separate stages. These inputs do not establish
|
||||
a shared Opus build with Rust consumers or a reduced dependency count.
|
||||
|
||||
Rust `opus` 0.4.0 is available through Socket. Adding Rust transport dependencies
|
||||
and establishing a shared Opus build remain separate integration work.
|
||||
|
||||
## Native development inputs
|
||||
|
||||
The private native CI job also emits `sdk.tar.gz` from the same inspected prefix.
|
||||
It contains headers (including the target's GLib configuration), development
|
||||
library names, import/static libraries and pkg-config metadata. `sdk.json`
|
||||
records the target, source commit, pinned manifest and every exported file hash.
|
||||
Shared-library bytes must match the native inspection receipt; other development
|
||||
files are hashed during export. This is provenance, not an authenticity check.
|
||||
|
||||
Meson generates relocatable pkg-config metadata using its standard option.
|
||||
Consumers must restrict `PKG_CONFIG_LIBDIR` to the SDK, clear `PKG_CONFIG_PATH`,
|
||||
and use `pkg-config --define-prefix` for libffi/PCRE2/zlib metadata too. Only the
|
||||
required native metadata is exported; capture Opus uses `opusic-sys`. Native
|
||||
library loader paths are not changed by SDK export. These build inputs do not replace the
|
||||
separate runtime projection and are never copied into users' Codex packages.
|
||||
Final helper linkage and moved-package execution remain separate integration
|
||||
work; exporting an SDK does not enable voice.
|
||||
|
||||
The Rust GStreamer bindings also link GLib's GIO library. Its pkg-config metadata
|
||||
is included in the SDK, and runtime preparation treats its loader identity as an
|
||||
explicit dependency root alongside the seven plugins. GIO comes from the same
|
||||
pinned GLib build; it is not another source package or a GStreamer plugin. Its
|
||||
transitive imports must satisfy the same private-library and system-import checks.
|
||||
|
||||
## Native build recipe
|
||||
|
||||
`bazel build //third_party/voice:native_prefix` runs this same recipe with
|
||||
Bazel-declared source archives, C/C++ compiler and SDK flags, LLVM ranlib,
|
||||
CMake, Make, pkg-config and Python. It supports matching native macOS and Linux
|
||||
GNU 2.28 toolchain targets on x64/ARM64; Windows continues to use the standalone
|
||||
recipe below. The macOS minimum comes from the selected CcToolchain. This manual
|
||||
target is not part of ordinary wildcard CLI builds.
|
||||
Mac libffi partial links require Apple's `/usr/bin/ld` from Command Line Tools;
|
||||
the LLVM compiler and normal final-link flags remain in use.
|
||||
|
||||
The root registers the existing pinned built-Make toolchain for all foreign_cc
|
||||
Make consumers, including pkg-config's bootstrap, instead of selecting host Make.
|
||||
The recipe still needs the host's standard Unix utilities and `/bin/bash`;
|
||||
it is not a fully hermetic build.
|
||||
|
||||
The target exports raw `prefix.tar` and a `built.json` receipt (the `receipt`
|
||||
output group). These are build inputs, not a relocatable SDK or runtime package.
|
||||
No Rust GStreamer build-script annotations or helper loader-path changes are
|
||||
provided by this target. Upstream build failure logs appear in the action output.
|
||||
|
||||
`build_native.py` runs the unmodified upstream build systems in a new output
|
||||
directory, using the same archives. Unix builds accept repeated `--c-flag=...`,
|
||||
`--cxx-flag=...`, `--link-flag=...` and optional `--ar`/`--ranlib` inputs.
|
||||
These overrides are rejected on Windows; ambient flags remain ignored.
|
||||
Libffi uses compiler response files to preserve literal definitions through
|
||||
configure, recursive Make and libtool. Response-file paths must not require shell
|
||||
quoting. Its
|
||||
Autoconf recipe cannot preserve flags containing whitespace; those are rejected.
|
||||
Declared archiver and ranlib paths must not require shell quoting for libffi.
|
||||
Specify the target and existing compiler,
|
||||
CMake, make, pkg-config and shell paths explicitly. It requires a matching
|
||||
native host: GNU Linux, macOS, or Windows MSVC, on x64 or ARM64.
|
||||
|
||||
On macOS, specify the existing release deployment target with
|
||||
`--deployment-target`; the host OS version is not an acceptable default.
|
||||
Windows requires the normal Visual Studio SDK environment, Cygwin GNU make,
|
||||
bash/cygpath and Automake 1.18's standard `ar-lib` for upstream libffi,
|
||||
native Windows pkgconf, and `--bootstrap-make` pointing to NMake.
|
||||
The recipe does not install these build prerequisites or patch upstream sources.
|
||||
The optional `--windows-build-inputs <json>` argument records an explicit selection
|
||||
of these tools, the target-specific MSVC assembler, linker, library manager,
|
||||
inspector, Windows SDK resource/manifest tools, Python, and include/library roots.
|
||||
The existing private CI driver supplies this input from its provisioned VS/Cygwin
|
||||
setup. In this mode the recipe checks that named tools resolve to the selected
|
||||
files, puts MSVC ahead of Cygwin's different `link.exe`, and excludes unrelated
|
||||
inherited PATH and SDK entries. The exact selection is retained in build receipts.
|
||||
The JSON uses `schemaVersion: 1`, `target`, `tools` (role to absolute file path),
|
||||
`systemRoot`, and `INCLUDE`/`LIB` arrays of absolute directories. The CLI tool
|
||||
arguments must agree with the recorded selection. Without this argument, the
|
||||
standalone recipe keeps using the normal Visual Studio environment.
|
||||
|
||||
This selects already installed inputs; it does not hash their support files,
|
||||
sandbox the build, supply a Bazel Windows provider, or publish build tools.
|
||||
Those still require a complete declared compiler/bootstrap closure and approved
|
||||
public-readable inputs. Existing private Cygwin release assets do not satisfy
|
||||
public self-build access. No Windows support is disabled to hide that gap.
|
||||
The private CI bootstrap verifies the official Cygwin installer and native pkgconf
|
||||
MSI hashes before use. It also verifies a retained Cygwin package snapshot against
|
||||
pinned archive and member hashes before installing it offline using signed
|
||||
metadata. The installed package/version set must exactly match the snapshot
|
||||
manifest.
|
||||
The MSI is administratively extracted into job storage without a system install.
|
||||
Cygwin runs under x64 emulation on ARM64; the compiler probes and emitted DLLs
|
||||
must still match the real native target. Native pkgconf relocates libffi's POSIX
|
||||
prefix metadata; CI rejects residual Cygwin paths. These are build prerequisites,
|
||||
not shipped runtime components or evidence of working voice.
|
||||
|
||||
CMake libraries use relative install runpaths (`$ORIGIN` on Linux and
|
||||
`@loader_path` on Mac), with `@rpath` install names on Mac. Linux Meson links
|
||||
use `$ORIGIN:$ORIGIN/..`, matching libraries in `lib/` and plugins in
|
||||
`lib/gstreamer-1.0/`. Mac Meson and libffi still need packaging-time fixups;
|
||||
these options do not make every Mac library relocatable at installation.
|
||||
|
||||
Outputs are under `prefix/`, build tools under `tools/`, and logs beside them.
|
||||
`build-state.json` records completed commands and failures; `built.json` exists
|
||||
only when every build/install command succeeds. Failed builds retain their logs
|
||||
and must use a new output directory on retry. CMake compiler-identification logs
|
||||
and the recorded tool/configuration inputs remain part of the build provenance.
|
||||
|
||||
The recipe disables optional plugins and Meson fallback dependency resolution,
|
||||
with pkg-config restricted to this prefix. Only system ABI libraries/frameworks
|
||||
may remain external; runtime closure inspection must verify that independently.
|
||||
`//third_party/voice:build_inputs` exposes the recipe and source inputs to Bazel.
|
||||
Neither this filegroup nor a successful prefix build proves final Cargo/Bazel
|
||||
linkage, safe private runtime loading, or an installed voice-capable Codex package.
|
||||
|
||||
## Private macOS runtime projection
|
||||
|
||||
`macos_runtime.py --prefix <extracted-prefix> --receipts <native-ci-receipts>
|
||||
--target <macOS-triple> --output <fresh-directory>` verifies the native receipt,
|
||||
source manifest, per-file digests and Mach-O architecture before projecting the
|
||||
seven explicit plugins and their declared library dependencies. It removes SDK
|
||||
aliases and build-machine runpaths, rewrites private imports relative to each
|
||||
loader, and regenerates only development ad-hoc signatures. Inputs are untouched.
|
||||
The output must be new and outside the input directories; failures remove only
|
||||
that new output. `runtime.json` records source and transformed file identities.
|
||||
Xcode's `xcrun llvm-objdump` inspects Mach-O headers and load commands; the
|
||||
preparer reads its output and enforces the package dependency policy rather than
|
||||
decoding binary structures itself. `install_name_tool` still rewrites paths.
|
||||
`runtime.py` owns shared receipt checks, dependency selection, verified copying,
|
||||
and cleanup; each platform owns its binary format and loader changes. Output
|
||||
containment uses filesystem identity, and copied bytes are checked again before
|
||||
transformation so input changes cannot silently invalidate the source receipt.
|
||||
|
||||
This is a development-only payload, not a signed distribution package or proof of
|
||||
audio behavior. Dynamic-only dependencies, native helper linkage, LGPL notices,
|
||||
production signing/notarization, Windows/Linux loading and security approval remain
|
||||
separate requirements. No microphone, device, plugin scanner or backend is started
|
||||
by projection. Run its native relocation tests on macOS with Python 3.12 or newer.
|
||||
|
||||
## Private GNU Linux runtime preparation
|
||||
|
||||
`linux_runtime.py` takes the same prefix, receipts, target and output arguments.
|
||||
It reads bounded ELF64 headers, segments and dynamic tables directly and accepts
|
||||
x64/ARM64 GNU Linux libraries. The shared Python coordinator selects the seven
|
||||
plugins and their declared dependencies without changing their bytes. The native
|
||||
build must have emitted package-relative runpaths; older absolute paths are
|
||||
rejected with a rebuild instruction. Output preserves `lib/gstreamer-1.0/` so
|
||||
those relative paths remain valid. Loader audit/filter dependencies and
|
||||
path-bearing imports are rejected. Native tests require Python 3.12, a C compiler
|
||||
and `patchelf`; the latter constructs malformed inputs and is not needed during
|
||||
preparation or shipped in the runtime. The output is development-only, uses the
|
||||
host glibc, and does not establish musl or minimum-glibc support, dynamic-only
|
||||
dependency closure, helper loading policy or working voice.
|
||||
|
||||
## Prepare Bazel's native build output
|
||||
|
||||
`bazel build //third_party/voice:native_runtime` prepares the selected Mac or GNU
|
||||
Linux prefix archive using the existing platform inspection and preparation code.
|
||||
It checks the completed build receipt, records the current workspace build commit,
|
||||
inspects physical libraries, and prepares verified copies. These receipts describe
|
||||
build inputs and inspection; they are not signatures or release approval.
|
||||
|
||||
This manual target requires the same host inspection/signing tools as the standalone
|
||||
platform preparer. It does not link Rust, change Windows builds, assemble a CLI
|
||||
package, or enable voice. The prepared runtime is the input to those later steps.
|
||||
|
||||
The `native_sdk` output exports the existing development SDK from that same
|
||||
inspected build. Unix Bazel Rust bindings keep their upstream pkg-config version
|
||||
checks, restricted to this SDK and the declared pkg-config executable. The
|
||||
supported `system-deps` search-path override directs linking to `native_link`'s
|
||||
prepared libraries; its GStreamer linker-flag override removes the SDK's absolute
|
||||
rpath. Standard CcInfo supplies relative Bazel runpaths and explicit runfiles.
|
||||
Canonical ABI names and development aliases stay together, including transitive
|
||||
native dependencies. No host library fallback or version-probe bypass is used.
|
||||
Plugins and their manifest are exported beside those same canonical libraries;
|
||||
bindings and plugin imports must resolve to one physical copy of each library.
|
||||
Cargo still consumes an explicitly supplied SDK; Windows MSVC and final installed
|
||||
helper loader paths remain separate packaging steps. This does not enable voice.
|
||||
|
||||
## Private Windows runtime preparation
|
||||
|
||||
`windows_runtime.py` takes the same arguments for x64/ARM64 MSVC build prefixes.
|
||||
MSVC's existing `dumpbin` reads PE headers, dependencies and exports; the Python
|
||||
adapter applies package policy without walking binary structures.
|
||||
It checks bounded PE32+ import tables, uses case-insensitive DLL identities, and
|
||||
copies the seven plugins and their declared dependencies into one private `bin/`
|
||||
directory without changing DLL bytes. Delayed imports, managed DLLs and forwarded
|
||||
exports are unsupported and rejected. Native tests require MSVC and Python 3.12;
|
||||
they load the moved DLLs using only the DLL directory and System32 search flags.
|
||||
This development payload expects the Windows Universal CRT and the matching
|
||||
Microsoft Visual C++ runtime (`VCRUNTIME140.dll`) already installed. The latter
|
||||
is not a guaranteed OS component. Release redistribution/licensing, Authenticode
|
||||
policy and actual helper loading remain separate requirements; this script does
|
||||
not install or redistribute Microsoft runtime files or enable voice.
|
||||
# Windows Bazel inputs and actions
|
||||
|
||||
The named `native_prefix_windows_{x86_64,aarch64}`,
|
||||
`native_runtime_windows_{x86_64,aarch64}` and
|
||||
`native_link_windows_{x86_64,aarch64}` targets use the existing native recipe,
|
||||
runtime inspection and SDK export. These targets are MSVC-only. They require
|
||||
native Windows execution of the matching architecture; they are not cross builds.
|
||||
The generic Rust-consumer aliases are connected separately, after these inputs.
|
||||
|
||||
Provide the complete installed Cygwin/pkgconf repository explicitly. For a public
|
||||
Windows build, `.github/scripts/setup-voice-windows.ps1 -Target
|
||||
x86_64-pc-windows-msvc -SnapshotArchive <path>` (under `public/` in
|
||||
codex-internal) verifies the pinned archive and every input size and SHA-512
|
||||
digest, then runs the offline installer against its signed metadata. ARM64 uses
|
||||
`aarch64-pc-windows-msvc` and the same Cygwin x64 tools under emulation. The
|
||||
installed tool tree stays in the CI temporary directory and is never added to
|
||||
a Codex package. The upstream mirror's signed metadata changes over time, so
|
||||
the archived snapshot must be supplied separately. Private CI validates this
|
||||
public bootstrap against its existing pinned archive. Public release CI obtains
|
||||
the same hash-pinned build inputs from the public `openai/codex` release named
|
||||
by `voice-cygwin-snapshot.json`. That release also makes the corresponding
|
||||
upstream source archives available under `cygwin-build-sources.tar`, with its
|
||||
own size and SHA-256 pin. These Cygwin tools run only on the build runner;
|
||||
neither archive is included in the user's Codex package.
|
||||
|
||||
The default
|
||||
`windows_installed_tools` label setting is empty and fails if a Windows action
|
||||
needs it. This keeps ordinary public dependency queries independent of private
|
||||
provisioning; it does not silently omit tools from a requested Windows build.
|
||||
The module does not download that installed tree or accept compiler licenses.
|
||||
|
||||
After provisioning, a native PowerShell invocation is:
|
||||
|
||||
```powershell
|
||||
$hostArch = $env:PROCESSOR_ARCHITEW6432
|
||||
if (-not $hostArch) { $hostArch = $env:PROCESSOR_ARCHITECTURE }
|
||||
bazel build //third_party/voice:native_link_windows_x86_64 `
|
||||
--platforms=//:local_windows_msvc `
|
||||
--inject_repository="voice_windows_tools=$env:VOICE_WINDOWS_BAZEL_REPOSITORY" `
|
||||
--//third_party/voice:windows_installed_tools=@voice_windows_tools//:tools `
|
||||
--action_env="SystemRoot=$env:SystemRoot" --host_action_env="SystemRoot=$env:SystemRoot" `
|
||||
--action_env="PROCESSOR_ARCHITECTURE=$hostArch" --host_action_env="PROCESSOR_ARCHITECTURE=$hostArch"
|
||||
```
|
||||
|
||||
Use `native_link_windows_aarch64` on native ARM64 Windows. Existing MSVC license
|
||||
acceptance requirements still apply. `SystemRoot` must be a fixed action value,
|
||||
not the inherited form `--action_env=SystemRoot`; Bazel analysis cannot inspect
|
||||
that inherited value. The action validates the Windows command directory and
|
||||
constructs its tool search path from declared inputs, not developer PATH entries.
|
||||
|
||||
Compiler, SDK, Python and CMake inputs use the existing pinned repositories.
|
||||
CMake and Cygwin execute as x64 under emulation on ARM64; compiler, SDK tools,
|
||||
Python and pkgconf match the native architecture. Complete support, include and
|
||||
library files are declared, and installed entrypoints must match the supplied
|
||||
target/architecture manifest and belong to that declared tree. This does not
|
||||
turn caller-provided files into authenticated inputs: provisioning retains that
|
||||
responsibility. These build tools must never enter shipped Codex packages.
|
||||
|
||||
Windows link inputs pair SDK import libraries with the corresponding prepared
|
||||
DLLs. DLLs, plugins and the receipt remain under the normal native-link runfiles
|
||||
layout; Windows receives no ELF or Mach-O runtime-search flags. This capability
|
||||
still needs real native x64/ARM64 Bazel execution and consumer validation before
|
||||
it establishes complete Windows voice support. The existing direct native recipe
|
||||
passing on Windows does not prove this new Bazel input and execution path.
|
||||
178
third_party/voice/assemble_package.py
vendored
Normal file
178
third_party/voice/assemble_package.py
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
"""Add a helper and its prepared runtime to a fresh private Codex package."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
# Import only this script's siblings, including under PYTHONSAFEPATH.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from package_runtime import runtime_files
|
||||
from runtime import digest
|
||||
|
||||
|
||||
def assemble(
|
||||
package: Path,
|
||||
helper: Path,
|
||||
voice_target: str,
|
||||
commit: str,
|
||||
output: Path,
|
||||
*,
|
||||
runtime: Path,
|
||||
release_version: str | None = None,
|
||||
):
|
||||
package, helper = package.resolve(strict=True), helper.resolve(strict=True)
|
||||
output = output.absolute()
|
||||
if (
|
||||
output.exists()
|
||||
or output.is_symlink()
|
||||
or output.resolve().is_relative_to(package)
|
||||
):
|
||||
raise ValueError("output must be fresh and outside the input package")
|
||||
if not re.fullmatch(r"[0-9a-f]{40}", commit):
|
||||
raise ValueError(
|
||||
"a full build commit is required; dev builds are not distributable"
|
||||
)
|
||||
metadata = json.loads((package / "codex-package.json").read_text())
|
||||
app_target = metadata["target"]
|
||||
targets = {
|
||||
f"{arch}-{suffix}": f"{arch}-{suffix.replace('musl', 'gnu')}"
|
||||
for arch in ("aarch64", "x86_64")
|
||||
for suffix in (
|
||||
"apple-darwin",
|
||||
"unknown-linux-gnu",
|
||||
"unknown-linux-musl",
|
||||
"pc-windows-msvc",
|
||||
)
|
||||
}
|
||||
if targets.get(app_target) != voice_target:
|
||||
raise ValueError("incompatible app and helper targets")
|
||||
suffix = ".exe" if app_target.endswith("windows-msvc") else ""
|
||||
entrypoint = f"bin/codex{suffix}"
|
||||
expected = {
|
||||
"layoutVersion": 1,
|
||||
"variant": "codex",
|
||||
"entrypoint": entrypoint,
|
||||
"resourcesDir": "codex-resources",
|
||||
"pathDir": "codex-path",
|
||||
}
|
||||
if any(metadata.get(key) != value for key, value in expected.items()):
|
||||
raise ValueError("input is not a canonical Codex package")
|
||||
if release_version is None:
|
||||
if not metadata["version"].endswith(f"+{commit}"):
|
||||
raise ValueError("package version does not match the declared build")
|
||||
elif (
|
||||
not re.fullmatch(
|
||||
r"[0-9]+\.[0-9]+\.[0-9]+(?:-alpha(?:\.[0-9]+){0,2}|-beta(?:\.[0-9]+)?)?",
|
||||
release_version,
|
||||
)
|
||||
or metadata["version"] != release_version
|
||||
):
|
||||
raise ValueError("package version does not match the release")
|
||||
if (package / "codex-resources/voice").exists():
|
||||
raise ValueError("input already contains voice resources")
|
||||
for path in package.rglob("*"):
|
||||
if path.is_symlink() or not (path.is_file() or path.is_dir()):
|
||||
raise ValueError("package inputs must be regular files or directories")
|
||||
if not helper.is_file() or not (package / entrypoint).is_file():
|
||||
raise ValueError("helper and app entrypoint must be regular files")
|
||||
if not suffix and not helper.stat().st_mode & 0o111:
|
||||
raise ValueError("helper is not executable")
|
||||
runtime = runtime.resolve(strict=True)
|
||||
if any(parent.samefile(package) for parent in (runtime, *runtime.parents)):
|
||||
raise ValueError("runtime must be outside the input package")
|
||||
if any(
|
||||
parent.exists() and parent.samefile(runtime)
|
||||
for parent in output.resolve().parents
|
||||
):
|
||||
raise ValueError("output must be outside the runtime input")
|
||||
inputs = runtime_files(
|
||||
runtime, voice_target, public_release=release_version is not None
|
||||
)
|
||||
if release_version is not None:
|
||||
receipt = json.loads((runtime / "runtime.json").read_text(encoding="utf-8"))
|
||||
if receipt["sourceCommit"] != commit:
|
||||
raise ValueError("release runtime source does not match the app build")
|
||||
output.mkdir() # Exclusive creation: never clean or overwrite a pre-existing output.
|
||||
try:
|
||||
shutil.copytree(package, output, dirs_exist_ok=True)
|
||||
relative_helper = f"codex-resources/voice/bin/codex-voice-host{suffix}"
|
||||
destination = output / relative_helper
|
||||
destination.parent.mkdir(parents=True)
|
||||
shutil.copy2(helper, destination)
|
||||
for relative, expected_digest in inputs.items():
|
||||
copied = output / "codex-resources/voice" / relative
|
||||
copied.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(runtime / relative, copied)
|
||||
if digest(copied) != expected_digest:
|
||||
raise ValueError("runtime file changed during copying")
|
||||
if release_version is not None:
|
||||
source_dir = Path(__file__).resolve().parent
|
||||
for relative in (
|
||||
"NOTICE.md",
|
||||
"sources.json",
|
||||
*(("windows-crt.json",) if suffix else ()),
|
||||
"licenses/LGPL-2.1.txt",
|
||||
"licenses/Opus.txt",
|
||||
"licenses/PCRE2.md",
|
||||
"licenses/libffi.txt",
|
||||
"licenses/proxy-libintl.txt",
|
||||
"licenses/sljit.txt",
|
||||
"licenses/zlib.txt",
|
||||
):
|
||||
destination_file = destination.parent.parent / relative
|
||||
destination_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(source_dir / relative, destination_file)
|
||||
inputs[relative] = digest(destination_file)
|
||||
digests = {}
|
||||
for relative in (entrypoint, relative_helper):
|
||||
with (output / relative).open("rb") as source:
|
||||
digests[relative] = hashlib.file_digest(source, "sha256").hexdigest()
|
||||
digests.update(
|
||||
{f"codex-resources/voice/{name}": value for name, value in inputs.items()}
|
||||
)
|
||||
manifest = {
|
||||
"schemaVersion": 1,
|
||||
"buildCommit": commit,
|
||||
"appTarget": app_target,
|
||||
"voiceTarget": voice_target,
|
||||
"appVersion": metadata["version"],
|
||||
"sha256": digests,
|
||||
}
|
||||
(destination.parent.parent / "manifest.json").write_text(
|
||||
json.dumps(manifest, indent=2) + "\n", encoding="utf-8"
|
||||
)
|
||||
except BaseException:
|
||||
shutil.rmtree(output)
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--package", type=Path, required=True)
|
||||
parser.add_argument("--helper", type=Path, required=True)
|
||||
parser.add_argument("--voice-target", required=True)
|
||||
parser.add_argument("--build-commit", required=True)
|
||||
parser.add_argument(
|
||||
"--release-version", help="exact version of a public release package"
|
||||
)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
parser.add_argument(
|
||||
"--runtime",
|
||||
type=Path,
|
||||
required=True,
|
||||
help="prepared runtime required by the helper",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
assemble(
|
||||
args.package,
|
||||
args.helper,
|
||||
args.voice_target,
|
||||
args.build_commit,
|
||||
args.output,
|
||||
runtime=args.runtime,
|
||||
release_version=args.release_version,
|
||||
)
|
||||
19
third_party/voice/bazel_copy.py
vendored
Normal file
19
third_party/voice/bazel_copy.py
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"""Copy declared library payloads while keeping a real native-search directory."""
|
||||
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
|
||||
def copy_payloads(locator, pairs):
|
||||
if len(pairs) % 2:
|
||||
raise ValueError("library copies require source/destination pairs")
|
||||
Path(locator).mkdir(parents=True, exist_ok=True)
|
||||
for source, destination in zip(pairs[::2], pairs[1::2], strict=True):
|
||||
output = Path(destination)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(source, output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
copy_payloads(sys.argv[1], sys.argv[2:])
|
||||
68
third_party/voice/bazel_native.py
vendored
Normal file
68
third_party/voice/bazel_native.py
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run the existing native recipe with Bazel-declared inputs; export a raw prefix."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
from types import SimpleNamespace
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from build_native import NativeBuild
|
||||
|
||||
|
||||
def main():
|
||||
config = json.loads(Path(sys.argv[1]).read_text())
|
||||
root = str(Path.cwd())
|
||||
# Toolchain flags may name execroot-relative SDK files even though upstream
|
||||
# build systems change directory. Substitute a literal marker, never a shell.
|
||||
config = json.loads(json.dumps(config).replace("@VOICE_EXECROOT@", root))
|
||||
with tempfile.TemporaryDirectory(prefix="voice-native-") as temporary:
|
||||
temporary = Path(temporary)
|
||||
archives = temporary / "archives"
|
||||
archives.mkdir()
|
||||
for archive in config.pop("archives"):
|
||||
source = Path(archive)
|
||||
shutil.copyfile(source, archives / source.name)
|
||||
prefix = Path(config.pop("prefix")).absolute()
|
||||
receipt = Path(config.pop("receipt")).absolute()
|
||||
ld = Path(config.pop("ld")).absolute()
|
||||
for name in (
|
||||
"cc",
|
||||
"cxx",
|
||||
"ar",
|
||||
"ranlib",
|
||||
"cmake",
|
||||
"make",
|
||||
"pkg_config",
|
||||
"shell",
|
||||
):
|
||||
config[name] = Path(config[name]).absolute()
|
||||
args = SimpleNamespace(
|
||||
**config,
|
||||
archives=archives,
|
||||
output=temporary / "build",
|
||||
bootstrap_make=None,
|
||||
)
|
||||
builder = NativeBuild(args, os.environ)
|
||||
# Libtool probes the raw linker separately from compiler link flags.
|
||||
builder.environment["LD"] = str(ld)
|
||||
try:
|
||||
builder.build()
|
||||
except Exception:
|
||||
# Preserve the failing upstream diagnostic in the Bazel action log.
|
||||
if builder.record["steps"]:
|
||||
log = builder.output / (builder.record["steps"][-1]["name"] + ".log")
|
||||
if log.is_file():
|
||||
print(log.read_text(errors="replace"), file=sys.stderr)
|
||||
raise
|
||||
with tarfile.open(prefix, "w") as archive:
|
||||
archive.add(builder.prefix, arcname=".")
|
||||
shutil.copyfile(builder.output / "built.json", receipt)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
175
third_party/voice/bazel_windows.py
vendored
Normal file
175
third_party/voice/bazel_windows.py
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
"""Adapt declared Windows tool paths to the existing native build/runtime recipes."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from build_native import NativeBuild
|
||||
from windows_build_inputs import build_environment
|
||||
|
||||
|
||||
def selected_inputs(config, root):
|
||||
inputs = dict(config["inputs"])
|
||||
tools = {name: (root / path).absolute() for name, path in inputs["tools"].items()}
|
||||
manifest = (root / config["manifest"]).absolute()
|
||||
declared = {(root / path).absolute() for path in config["installed_files"]}
|
||||
if manifest.stat().st_size > 65536:
|
||||
raise ValueError("installed Windows tool metadata exceeds limits")
|
||||
installed = json.loads(manifest.read_text(encoding="utf-8"))
|
||||
expected = {"shell", "make", "cygpath", "automake", "pkg_config"}
|
||||
if (
|
||||
installed.get("schemaVersion") != 1
|
||||
or installed.get("target") != inputs["target"]
|
||||
or installed.get("cygwinArchitecture") != "x86_64"
|
||||
or set(installed.get("tools", {})) != expected
|
||||
):
|
||||
raise ValueError("installed Windows tools do not match the selected target")
|
||||
for name in expected:
|
||||
relative = Path(installed["tools"][name])
|
||||
source = (manifest.parent / relative).absolute()
|
||||
if (
|
||||
relative.is_absolute()
|
||||
or ".." in relative.parts
|
||||
or source not in declared
|
||||
or (name == "pkg_config" and tools.get(name) != source)
|
||||
or not source.resolve(strict=True).is_relative_to(
|
||||
manifest.parent.resolve(strict=True)
|
||||
)
|
||||
):
|
||||
raise ValueError(f"installed Windows tool selection differs: {name}")
|
||||
tools[name] = source
|
||||
inputs["tools"] = {name: str(path) for name, path in tools.items()}
|
||||
for name in ("INCLUDE", "LIB"):
|
||||
inputs[name] = [str((root / path).absolute()) for path in inputs[name]]
|
||||
return inputs
|
||||
|
||||
|
||||
def main():
|
||||
operation, config_path = sys.argv[1:]
|
||||
config = json.loads(Path(config_path).read_text(encoding="utf-8"))
|
||||
root = Path.cwd()
|
||||
with tempfile.TemporaryDirectory(prefix="voice-windows-") as temporary:
|
||||
temporary = Path(temporary)
|
||||
document = temporary / "windows-inputs.json"
|
||||
inputs = selected_inputs(config, root)
|
||||
document.write_text(json.dumps(inputs), encoding="utf-8")
|
||||
environment, _ = build_environment(
|
||||
document, inputs["target"], {"python": Path(sys.executable)}
|
||||
)
|
||||
# Keep host identity and scratch directories, never developer tool search paths.
|
||||
environment.update(
|
||||
{
|
||||
name: os.environ[name]
|
||||
for name in ("TMP", "TEMP", "PROCESSOR_ARCHITECTURE")
|
||||
if name in os.environ
|
||||
}
|
||||
)
|
||||
home = temporary / "home"
|
||||
home.mkdir()
|
||||
environment.update({"HOME": str(home), "USERPROFILE": str(home)})
|
||||
os.environ.clear()
|
||||
os.environ.update(environment)
|
||||
if operation == "prepare":
|
||||
from prepare_built_runtime import prepare_archive
|
||||
|
||||
output = root / config["output"]
|
||||
sdk = root / config["sdk"]
|
||||
for path in (output, sdk):
|
||||
if path.exists():
|
||||
path.rmdir()
|
||||
try:
|
||||
prepare_archive(
|
||||
root / config["prefix"],
|
||||
root / config["receipt"],
|
||||
root / config["status"],
|
||||
inputs["target"],
|
||||
output,
|
||||
sdk_output=sdk,
|
||||
)
|
||||
except ValueError as exc:
|
||||
if str(exc) != "native build receipt is incomplete or mismatched":
|
||||
raise
|
||||
receipt = json.loads((root / config["receipt"]).read_text())
|
||||
commits = [
|
||||
line
|
||||
for line in (root / config["status"]).read_text().splitlines()
|
||||
if line.startswith("STABLE_GIT_COMMIT ")
|
||||
]
|
||||
steps = receipt.get("steps", [])
|
||||
checks = {
|
||||
"commit_count": len(commits) == 1,
|
||||
"commit_format": len(commits) == 1
|
||||
and bool(
|
||||
re.fullmatch(r"STABLE_GIT_COMMIT [0-9a-f]{40}", commits[0])
|
||||
),
|
||||
"target": receipt.get("target") == inputs["target"],
|
||||
"manifest": receipt.get("manifest_sha256")
|
||||
== hashlib.sha256(
|
||||
Path(__file__).with_name("sources.json").read_bytes()
|
||||
).hexdigest(),
|
||||
"step_count": 1 <= len(steps) <= 128,
|
||||
"step_exit": all(step.get("exit_code") == 0 for step in steps),
|
||||
"last_step": bool(steps)
|
||||
and steps[-1].get("name") == "gst-plugins-good-install",
|
||||
}
|
||||
print(
|
||||
"Receipt checks failed: "
|
||||
+ ", ".join(name for name, valid in checks.items() if not valid),
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise
|
||||
return
|
||||
if operation != "build":
|
||||
raise ValueError("unknown Windows native action")
|
||||
archives = temporary / "archives"
|
||||
archives.mkdir()
|
||||
for path in config["archives"]:
|
||||
source = root / path
|
||||
shutil.copyfile(source, archives / source.name)
|
||||
tools = inputs["tools"]
|
||||
builder = NativeBuild(
|
||||
SimpleNamespace(
|
||||
target=inputs["target"],
|
||||
deployment_target=None,
|
||||
jobs=8,
|
||||
output=temporary / "build",
|
||||
archives=archives,
|
||||
windows_build_inputs=document,
|
||||
**{
|
||||
name: Path(tools[name])
|
||||
for name in (
|
||||
"cc",
|
||||
"cxx",
|
||||
"cmake",
|
||||
"make",
|
||||
"pkg_config",
|
||||
"shell",
|
||||
"bootstrap_make",
|
||||
)
|
||||
},
|
||||
),
|
||||
environment,
|
||||
)
|
||||
try:
|
||||
builder.build()
|
||||
except Exception:
|
||||
if builder.record["steps"]:
|
||||
log = builder.output / (builder.record["steps"][-1]["name"] + ".log")
|
||||
if log.is_file():
|
||||
print(log.read_text(errors="replace"), file=sys.stderr)
|
||||
raise
|
||||
with tarfile.open(root / config["prefix"], "w") as archive:
|
||||
archive.add(builder.prefix, arcname=".")
|
||||
shutil.copyfile(builder.output / "built.json", root / config["receipt"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
573
third_party/voice/build_native.py
vendored
Normal file
573
third_party/voice/build_native.py
vendored
Normal file
@@ -0,0 +1,573 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build the candidate native voice prefix with upstream build systems."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Match the package builder: import this script's sibling under PYTHONSAFEPATH,
|
||||
# without adding the caller's working directory to the module search path.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from prepare_sources import MANIFEST, load_sources, prepare_sources
|
||||
from windows_build_inputs import build_environment
|
||||
|
||||
TARGET_SYSTEMS = {
|
||||
"apple-darwin": "Darwin",
|
||||
"unknown-linux-gnu": "Linux",
|
||||
"pc-windows-msvc": "Windows",
|
||||
}
|
||||
|
||||
|
||||
def validate_target(target, system, machine, libc, deployment_target):
|
||||
architecture, separator, suffix = target.partition("-")
|
||||
host_architecture = {"arm64": "aarch64", "amd64": "x86_64"}.get(
|
||||
machine.lower(), machine.lower()
|
||||
)
|
||||
if (
|
||||
not separator
|
||||
or architecture not in ("aarch64", "x86_64")
|
||||
or suffix not in TARGET_SYSTEMS
|
||||
):
|
||||
raise ValueError(f"Unsupported native voice target: {target}")
|
||||
if TARGET_SYSTEMS[suffix] != system or architecture != host_architecture:
|
||||
raise ValueError("Use a native build host matching the requested target")
|
||||
if system == "Linux" and libc != "glibc":
|
||||
raise ValueError("Native Linux voice builds require glibc")
|
||||
if system == "Darwin" and not re.fullmatch(
|
||||
r"[0-9]+\.[0-9]+(?:\.[0-9]+)?", deployment_target or ""
|
||||
):
|
||||
raise ValueError(
|
||||
"Declare the macOS deployment target; do not inherit the host default"
|
||||
)
|
||||
|
||||
|
||||
class NativeBuild:
|
||||
def __init__(self, args, inherited_environment):
|
||||
validate_target(
|
||||
args.target,
|
||||
platform.system(),
|
||||
platform.machine(),
|
||||
platform.libc_ver()[0],
|
||||
args.deployment_target,
|
||||
)
|
||||
self.args = args
|
||||
self.output = args.output.absolute()
|
||||
self.prefix = self.output / "prefix"
|
||||
self.tools = self.output / "tools"
|
||||
self.windows = args.target.endswith("windows-msvc")
|
||||
# Compiler drivers such as clang++ select link behavior from argv[0].
|
||||
self.toolchain = {
|
||||
name: getattr(args, name).absolute()
|
||||
for name in ("cc", "cxx", "cmake", "make", "pkg_config", "shell")
|
||||
}
|
||||
self.toolchain.update(
|
||||
(name, path.absolute())
|
||||
for name in ("ar", "ranlib")
|
||||
if (path := getattr(args, name, None)) is not None
|
||||
)
|
||||
self.quote = subprocess.list2cmdline if self.windows else shlex.join
|
||||
self.flags = {
|
||||
variable: list(getattr(args, argument, []))
|
||||
for variable, argument in (
|
||||
("CFLAGS", "c_flag"),
|
||||
("CXXFLAGS", "cxx_flag"),
|
||||
("LDFLAGS", "link_flag"),
|
||||
)
|
||||
}
|
||||
if self.windows and (
|
||||
any(self.flags.values())
|
||||
or any(name in self.toolchain for name in ("ar", "ranlib"))
|
||||
):
|
||||
raise ValueError("Explicit toolchain overrides require a Unix build host")
|
||||
self.bootstrap_make = (args.bootstrap_make or args.make).absolute()
|
||||
for tool in (*self.toolchain.values(), self.bootstrap_make):
|
||||
if not tool.is_file():
|
||||
raise ValueError(f"Missing build tool: {tool}")
|
||||
windows_inputs = getattr(args, "windows_build_inputs", None)
|
||||
input_record = None
|
||||
if windows_inputs is not None:
|
||||
if not self.windows:
|
||||
raise ValueError("Windows build inputs require a Windows MSVC target")
|
||||
explicit, input_record = build_environment(
|
||||
windows_inputs,
|
||||
args.target,
|
||||
{
|
||||
**self.toolchain,
|
||||
"bootstrap_make": self.bootstrap_make,
|
||||
"python": Path(sys.executable),
|
||||
},
|
||||
)
|
||||
inherited_environment = {**inherited_environment, **explicit}
|
||||
if self.windows and not all(
|
||||
inherited_environment.get(key) for key in ("INCLUDE", "LIB")
|
||||
):
|
||||
raise ValueError(
|
||||
"Initialize the standard Visual Studio build environment first"
|
||||
)
|
||||
self.environment = {
|
||||
key: value
|
||||
for key, value in inherited_environment.items()
|
||||
if key
|
||||
in (
|
||||
"HOME",
|
||||
"TMPDIR",
|
||||
"TMP",
|
||||
"TEMP",
|
||||
"SYSTEMROOT",
|
||||
"SystemRoot",
|
||||
"WINDIR",
|
||||
"COMSPEC",
|
||||
"INCLUDE",
|
||||
"LIB",
|
||||
"LIBPATH",
|
||||
"HTTPS_PROXY",
|
||||
"HTTP_PROXY",
|
||||
"NO_PROXY",
|
||||
)
|
||||
or (self.windows and key == "USERPROFILE")
|
||||
}
|
||||
if windows_inputs is not None:
|
||||
self.environment.pop("LIBPATH", None)
|
||||
paths = [
|
||||
str(self.tools / "bin"),
|
||||
*(
|
||||
[]
|
||||
if windows_inputs is not None
|
||||
else [str(p.parent) for p in self.toolchain.values()]
|
||||
),
|
||||
]
|
||||
paths += (
|
||||
inherited_environment.get("PATH", "").split(os.pathsep)
|
||||
if self.windows
|
||||
else ["/usr/bin", "/bin", "/usr/sbin", "/sbin"]
|
||||
)
|
||||
self.environment.update(
|
||||
{
|
||||
"PATH": os.pathsep.join(dict.fromkeys(paths)),
|
||||
"LANG": "C",
|
||||
"LC_ALL": "C",
|
||||
"PYTHONDONTWRITEBYTECODE": "1",
|
||||
"CC": str(self.toolchain["cc"]),
|
||||
"CXX": str(self.toolchain["cxx"]),
|
||||
"PKG_CONFIG": str(self.toolchain["pkg_config"]),
|
||||
"PKG_CONFIG_PATH": "",
|
||||
"PKG_CONFIG_LIBDIR": os.pathsep.join(
|
||||
str(self.prefix / p) for p in ("lib/pkgconfig", "share/pkgconfig")
|
||||
),
|
||||
"CMAKE_PREFIX_PATH": str(self.prefix),
|
||||
"NINJA": str(
|
||||
self.tools / "bin" / ("ninja.exe" if self.windows else "ninja")
|
||||
),
|
||||
}
|
||||
)
|
||||
self.cmake_platform = []
|
||||
self.environment.update(
|
||||
(name, self.quote(flags)) for name, flags in self.flags.items() if flags
|
||||
)
|
||||
self.environment.update(
|
||||
(name.upper(), self.quote([str(self.toolchain[name])]))
|
||||
for name in ("ar", "ranlib")
|
||||
if name in self.toolchain
|
||||
)
|
||||
if args.target.endswith("apple-darwin"):
|
||||
self.environment["MACOSX_DEPLOYMENT_TARGET"] = args.deployment_target
|
||||
self.cmake_platform = [
|
||||
f"-DCMAKE_OSX_DEPLOYMENT_TARGET={args.deployment_target}",
|
||||
"-DCMAKE_INSTALL_NAME_DIR=@rpath",
|
||||
"-DCMAKE_INSTALL_RPATH=@loader_path",
|
||||
]
|
||||
elif not self.windows:
|
||||
self.cmake_platform = [
|
||||
"-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON",
|
||||
"-DCMAKE_INSTALL_RPATH=$ORIGIN",
|
||||
]
|
||||
self.record = {
|
||||
"target": args.target,
|
||||
"deployment_target": args.deployment_target,
|
||||
"flags": self.flags,
|
||||
"steps": [],
|
||||
}
|
||||
if input_record is not None:
|
||||
self.record["windows_build_inputs"] = input_record
|
||||
|
||||
def run(self, name, command, cwd=None, environment=None):
|
||||
command = [str(part) for part in command]
|
||||
step = {"name": name, "command": command}
|
||||
self.record["steps"].append(step)
|
||||
print(f"Building {name}", flush=True)
|
||||
with (self.output / f"{name}.log").open("w", encoding="utf-8") as log:
|
||||
result = subprocess.run(
|
||||
command,
|
||||
cwd=cwd or self.output,
|
||||
env=environment or self.environment,
|
||||
stdout=log,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False,
|
||||
)
|
||||
step["exit_code"] = result.returncode
|
||||
(self.output / "build-state.json").write_text(
|
||||
json.dumps(self.record, indent=2) + "\n", encoding="utf-8"
|
||||
)
|
||||
result.check_returncode()
|
||||
|
||||
def posix_path(self, path):
|
||||
if not self.windows:
|
||||
return path.as_posix()
|
||||
return subprocess.check_output(
|
||||
[self.toolchain["shell"].with_name("cygpath.exe"), "-u", str(path)],
|
||||
env=self.environment,
|
||||
text=True,
|
||||
).strip()
|
||||
|
||||
def cmake(self, name, options, *, bootstrap=False):
|
||||
directory = self.output / "build" / name
|
||||
prefix = self.tools if bootstrap else self.prefix
|
||||
generator = (
|
||||
("NMake Makefiles" if self.windows else "Unix Makefiles")
|
||||
if bootstrap
|
||||
else "Ninja"
|
||||
)
|
||||
make = self.bootstrap_make if bootstrap else self.environment["NINJA"]
|
||||
self.run(
|
||||
name + "-configure",
|
||||
[
|
||||
self.toolchain["cmake"],
|
||||
"-S",
|
||||
self.sources[name],
|
||||
"-B",
|
||||
directory,
|
||||
"-G",
|
||||
generator,
|
||||
f"-DCMAKE_MAKE_PROGRAM={make}",
|
||||
"-DCMAKE_BUILD_TYPE=Release",
|
||||
f"-DCMAKE_INSTALL_PREFIX={prefix}",
|
||||
"-DCMAKE_INSTALL_LIBDIR=lib",
|
||||
f"-DCMAKE_C_COMPILER={self.toolchain['cc']}",
|
||||
f"-DCMAKE_CXX_COMPILER={self.toolchain['cxx']}",
|
||||
*(
|
||||
f"-DCMAKE_{name.upper()}={self.toolchain[name]}"
|
||||
for name in ("ar", "ranlib")
|
||||
if name in self.toolchain
|
||||
),
|
||||
f"-DCMAKE_PREFIX_PATH={self.prefix}",
|
||||
"-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF",
|
||||
"-DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF",
|
||||
"-DCMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH=OFF",
|
||||
"-DFETCHCONTENT_FULLY_DISCONNECTED=ON",
|
||||
*self.cmake_platform,
|
||||
*options,
|
||||
],
|
||||
)
|
||||
self.run(
|
||||
name + "-build",
|
||||
[
|
||||
self.toolchain["cmake"],
|
||||
"--build",
|
||||
directory,
|
||||
"--parallel",
|
||||
self.args.jobs,
|
||||
],
|
||||
)
|
||||
self.run(name + "-install", [self.toolchain["cmake"], "--install", directory])
|
||||
|
||||
def meson(self, name, options):
|
||||
directory = self.output / "build" / name
|
||||
meson = [sys.executable, self.sources["meson"] / "meson.py"]
|
||||
include = f"{'/I' if self.windows else '-I'}{self.prefix / 'include'}"
|
||||
link = (
|
||||
[f"/LIBPATH:{self.prefix / 'lib'}"]
|
||||
if self.windows
|
||||
else [f"-L{self.prefix / 'lib'}", f"-Wl,-rpath,{self.prefix / 'lib'}"]
|
||||
)
|
||||
if self.args.target.endswith("unknown-linux-gnu"):
|
||||
link[-1] = "-Wl,-rpath,$ORIGIN:$ORIGIN/.."
|
||||
self.environment.update(
|
||||
{
|
||||
name: self.quote([*flags, *(link if name == "LDFLAGS" else [include])])
|
||||
for name, flags in self.flags.items()
|
||||
}
|
||||
)
|
||||
if self.args.target.endswith("apple-darwin"):
|
||||
self.environment["OBJC"] = str(self.toolchain["cc"])
|
||||
self.environment["OBJCFLAGS"] = self.environment["CFLAGS"]
|
||||
self.run(
|
||||
name + "-configure",
|
||||
[
|
||||
*meson,
|
||||
"setup",
|
||||
directory,
|
||||
self.sources[name],
|
||||
f"--prefix={self.prefix}",
|
||||
"--libdir=lib",
|
||||
"--buildtype=release",
|
||||
"--wrap-mode=nofallback",
|
||||
"-Dauto_features=disabled",
|
||||
"-Ddefault_library=shared",
|
||||
"-Dpkgconfig.relocatable=true",
|
||||
*options,
|
||||
],
|
||||
)
|
||||
self.run(
|
||||
name + "-build", [*meson, "compile", "-C", directory, "-j", self.args.jobs]
|
||||
)
|
||||
self.run(
|
||||
name + "-install", [*meson, "install", "-C", directory, "--no-rebuild"]
|
||||
)
|
||||
|
||||
def build(self):
|
||||
self.output.mkdir()
|
||||
manifest = MANIFEST.read_bytes()
|
||||
prepare_sources(self.args.archives, self.output / "sources", manifest)
|
||||
self.sources = {
|
||||
s.name: self.output / "sources" / s.root for s in load_sources(manifest)
|
||||
}
|
||||
self.record["manifest_sha256"] = hashlib.sha256(manifest).hexdigest()
|
||||
self.record["tools"] = {
|
||||
name: str(path) for name, path in self.toolchain.items()
|
||||
}
|
||||
self.record["python"] = sys.version
|
||||
self.run("cmake-version", [self.toolchain["cmake"], "--version"])
|
||||
self.run("pkg-config-version", [self.toolchain["pkg_config"], "--version"])
|
||||
self.cmake("ninja", ["-DBUILD_TESTING=OFF"], bootstrap=True)
|
||||
self.cmake(
|
||||
"zlib",
|
||||
[
|
||||
"-DZLIB_BUILD_TESTING=OFF",
|
||||
"-DZLIB_BUILD_SHARED=ON",
|
||||
"-DZLIB_BUILD_STATIC=OFF",
|
||||
],
|
||||
)
|
||||
self.cmake(
|
||||
"pcre2",
|
||||
[
|
||||
"-DBUILD_SHARED_LIBS=ON",
|
||||
"-DBUILD_STATIC_LIBS=OFF",
|
||||
"-DPCRE2_BUILD_TESTS=OFF",
|
||||
"-DPCRE2_BUILD_PCRE2GREP=OFF",
|
||||
"-DPCRE2_SUPPORT_LIBZ=OFF",
|
||||
"-DPCRE2_SUPPORT_LIBBZ2=OFF",
|
||||
"-DPCRE2_SUPPORT_LIBREADLINE=OFF",
|
||||
"-DPCRE2_SUPPORT_LIBEDIT=OFF",
|
||||
],
|
||||
)
|
||||
ffi_build = self.output / "build/libffi"
|
||||
ffi_build.mkdir()
|
||||
environment = self.environment.copy()
|
||||
configure_options = []
|
||||
if self.windows:
|
||||
wrapper = shlex.quote(self.posix_path(self.sources["libffi"] / "msvcc.sh"))
|
||||
architecture = (
|
||||
"-m64" if self.args.target.startswith("x86_64-") else "-marm64"
|
||||
)
|
||||
# Match upstream's MSVC recipe, including native ARM64 outputs
|
||||
# from x64-emulated Cygwin tools. Never infer the target from uname.
|
||||
host = self.args.target.partition("-")[0] + "-w64-mingw32"
|
||||
configure_options = [f"--build={host}", f"--host={host}"]
|
||||
automake = subprocess.check_output(
|
||||
[
|
||||
self.toolchain["shell"],
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-c",
|
||||
"automake-1.18 --print-libdir",
|
||||
],
|
||||
env=environment,
|
||||
text=True,
|
||||
).strip()
|
||||
environment.update(
|
||||
{
|
||||
"CC": f"{wrapper} {architecture}",
|
||||
"CXX": f"{wrapper} {architecture}",
|
||||
"AR": f"{shlex.quote(automake + '/ar-lib')} lib",
|
||||
"RANLIB": ":",
|
||||
"LD": "link",
|
||||
"NM": "dumpbin -symbols",
|
||||
"STRIP": ":",
|
||||
"LDFLAGS": "-no-undefined",
|
||||
# Libffi clears MAKEOVERRIDES. Use its recursion hook to
|
||||
# name the import library expected by libtool's installer.
|
||||
"AM_MAKEFLAGS": shlex.quote(
|
||||
"LTLDFLAGS=-no-undefined -Wc,-link,/IMPLIB:.libs/libffi.lib"
|
||||
),
|
||||
"CPP": "cl -nologo -EP",
|
||||
"CXXCPP": "cl -nologo -EP",
|
||||
"CPPFLAGS": "-DFFI_BUILDING_DLL",
|
||||
"CONFIG_SHELL": self.posix_path(self.toolchain["shell"]),
|
||||
}
|
||||
)
|
||||
else:
|
||||
if self.args.target.endswith("apple-darwin"):
|
||||
# Libtool's partial links need -r, which ld64.lld does not support.
|
||||
environment["CC"] += " -fuse-ld=/usr/bin/ld"
|
||||
for name in ("ar", "ranlib"):
|
||||
if name in self.toolchain:
|
||||
path = str(self.toolchain[name])
|
||||
if shlex.quote(path) != path:
|
||||
raise ValueError(
|
||||
f"libffi {name} path cannot require shell quoting"
|
||||
)
|
||||
# Response files preserve compiler arguments through Autoconf's word
|
||||
# splitting and Make/libtool's shell expansion without losing flags
|
||||
# added by configure (such as -fexceptions).
|
||||
for name, flags in self.flags.items():
|
||||
if any(
|
||||
any(character.isspace() for character in flag) for flag in flags
|
||||
):
|
||||
raise ValueError("libffi flags cannot contain whitespace")
|
||||
if flags:
|
||||
response = ffi_build / f"{name.lower()}.rsp"
|
||||
if shlex.quote(str(response)) != str(response):
|
||||
raise ValueError(
|
||||
"libffi response-file path cannot require shell quoting"
|
||||
)
|
||||
response.write_text(
|
||||
"\n".join(
|
||||
'"' + flag.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
||||
for flag in flags
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
environment[name] = f"@{response}"
|
||||
if self.args.target.endswith("unknown-linux-gnu"):
|
||||
# Libtool otherwise drops Clang's declared CRT/runtime options.
|
||||
environment["AM_LTLDFLAGS"] = shlex.join(
|
||||
argument
|
||||
for flag in self.flags["LDFLAGS"]
|
||||
for argument in ("-Xcompiler", flag)
|
||||
)
|
||||
self.run(
|
||||
"libffi-configure",
|
||||
[
|
||||
self.toolchain["shell"],
|
||||
self.posix_path(self.sources["libffi"] / "configure"),
|
||||
f"--prefix={self.posix_path(self.prefix)}",
|
||||
"--enable-shared",
|
||||
"--disable-static",
|
||||
"--disable-docs",
|
||||
*configure_options,
|
||||
],
|
||||
cwd=ffi_build,
|
||||
environment=environment,
|
||||
)
|
||||
self.run(
|
||||
"libffi-build",
|
||||
[self.toolchain["make"], f"-j{self.args.jobs}"],
|
||||
cwd=ffi_build,
|
||||
environment=environment,
|
||||
)
|
||||
self.run(
|
||||
"libffi-install",
|
||||
[self.toolchain["make"], "install"],
|
||||
cwd=ffi_build,
|
||||
environment=environment,
|
||||
)
|
||||
if self.windows:
|
||||
self.run(
|
||||
"libffi-pkg-config",
|
||||
[self.toolchain["pkg_config"], "--cflags", "--libs", "libffi"],
|
||||
)
|
||||
if "/cygdrive/" in (self.output / "libffi-pkg-config.log").read_text():
|
||||
raise ValueError("pkg-config did not relocate libffi to native paths")
|
||||
self.cmake(
|
||||
"opus",
|
||||
[
|
||||
"-DOPUS_BUILD_SHARED_LIBRARY=ON",
|
||||
"-DOPUS_BUILD_TESTING=OFF",
|
||||
"-DOPUS_BUILD_PROGRAMS=OFF",
|
||||
# Windows ARM64 guarantees NEON; upstream misses its ARM64 spelling.
|
||||
*(
|
||||
["-DOPUS_PRESUME_NEON=ON"]
|
||||
if self.args.target == "aarch64-pc-windows-msvc"
|
||||
else []
|
||||
),
|
||||
],
|
||||
)
|
||||
self.meson("proxy-libintl", [])
|
||||
self.meson(
|
||||
"glib",
|
||||
[
|
||||
"-Dtests=false",
|
||||
"-Dinstalled_tests=false",
|
||||
"-Dnls=disabled",
|
||||
"-Ddocumentation=false",
|
||||
"-Dintrospection=disabled",
|
||||
"-Dlibmount=disabled",
|
||||
"-Dselinux=disabled",
|
||||
"-Dxattr=false",
|
||||
],
|
||||
)
|
||||
self.meson(
|
||||
"gstreamer",
|
||||
[
|
||||
"-Dregistry=false",
|
||||
"-Doption-parsing=false",
|
||||
"-Dtracer_hooks=false",
|
||||
"-Dgst_parse=false",
|
||||
"-Dtools=disabled",
|
||||
"-Dptp-helper=disabled",
|
||||
],
|
||||
)
|
||||
self.meson(
|
||||
"gst-plugins-base",
|
||||
[
|
||||
"-Dapp=enabled",
|
||||
"-Daudioconvert=enabled",
|
||||
"-Daudioresample=enabled",
|
||||
"-Dopus=enabled",
|
||||
"-Dgl=disabled",
|
||||
],
|
||||
)
|
||||
self.meson("gst-plugins-good", ["-Drtp=enabled", "-Drtpmanager=enabled"])
|
||||
(self.output / "built.json").write_text(
|
||||
json.dumps(self.record, indent=2) + "\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
for name in (
|
||||
"archives",
|
||||
"output",
|
||||
"cc",
|
||||
"cxx",
|
||||
"cmake",
|
||||
"make",
|
||||
"pkg-config",
|
||||
"shell",
|
||||
):
|
||||
parser.add_argument(f"--{name}", type=Path, required=True)
|
||||
parser.add_argument(
|
||||
"--bootstrap-make",
|
||||
type=Path,
|
||||
help="NMake on Windows; defaults to --make elsewhere",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--windows-build-inputs",
|
||||
type=Path,
|
||||
help="Explicit Windows tool and SDK selection; no unrelated PATH fallback",
|
||||
)
|
||||
for name in ("ar", "ranlib"):
|
||||
parser.add_argument(f"--{name}", type=Path)
|
||||
for name in ("c-flag", "cxx-flag", "link-flag"):
|
||||
parser.add_argument(f"--{name}", action="append", default=[])
|
||||
parser.add_argument("--target", required=True)
|
||||
parser.add_argument(
|
||||
"--deployment-target",
|
||||
help="Required on macOS; use the existing supported release minimum",
|
||||
)
|
||||
parser.add_argument("--jobs", type=int, default=8)
|
||||
args = parser.parse_args()
|
||||
if sys.version_info < (3, 12) or args.jobs < 1:
|
||||
parser.error("Python 3.12+ and a positive --jobs value are required")
|
||||
NativeBuild(args, os.environ).build()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
85
third_party/voice/cargo-ci/produce/action.yml
vendored
Normal file
85
third_party/voice/cargo-ci/produce/action.yml
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
name: Build Cargo voice inputs
|
||||
description: Build and upload same-commit native voice SDK and runtime inputs.
|
||||
inputs:
|
||||
target:
|
||||
description: Native target triple matching the runner
|
||||
required: true
|
||||
windows-tools:
|
||||
description: Directory containing the public Windows voice bootstrap
|
||||
default: .github/scripts
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
with:
|
||||
python-version: "3.12"
|
||||
architecture: ${{ contains(inputs.target, 'aarch64') && 'arm64' || 'x64' }}
|
||||
- uses: ./.github/actions/prepare-bazel-ci
|
||||
with:
|
||||
target: ${{ inputs.target }}
|
||||
cache-scope: cargo-voice-native
|
||||
- name: Set up Windows voice build tools
|
||||
if: runner.os == 'Windows'
|
||||
uses: ./.github/actions/setup-bazel-windows
|
||||
with:
|
||||
target: ${{ inputs.target }}
|
||||
windows-tools: ${{ inputs.windows-tools }}
|
||||
- name: Build and stage native dependencies
|
||||
shell: bash
|
||||
env:
|
||||
TARGET: ${{ inputs.target }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
arch="${TARGET%%-*}"
|
||||
case "$RUNNER_OS" in
|
||||
Windows) prefix="windows_$arch"; temp="$(cygpath -u "$RUNNER_TEMP")" ;;
|
||||
macOS) prefix="macos_$arch"; temp="$RUNNER_TEMP" ;;
|
||||
Linux) prefix="linux_$arch"; temp="$RUNNER_TEMP" ;;
|
||||
*) echo "Unsupported runner OS: $RUNNER_OS" >&2; exit 1 ;;
|
||||
esac
|
||||
wrapper=(--remote-download-toplevel --print-failed-action-summary)
|
||||
flags=(--config=release --build_metadata="COMMIT_SHA=$GITHUB_SHA")
|
||||
if [[ "$RUNNER_OS" == Windows ]]; then
|
||||
wrapper+=(--windows-msvc-host-platform)
|
||||
flags+=(--platforms=//:local_windows_msvc
|
||||
--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows,@local_config_cc//:cc-toolchain-arm64_windows,//third_party/voice:windows_pkg_config_toolchain,//third_party/voice:windows_cmake_toolchain
|
||||
--repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=0 --repo_env=BAZEL_MSVC_RUNTIME_VISUAL_STUDIO_EULA=1
|
||||
--inject_repository="voice_windows_tools=$VOICE_WINDOWS_BAZEL_REPOSITORY"
|
||||
--//third_party/voice:windows_installed_tools=@voice_windows_tools//:tools
|
||||
--action_env="SystemRoot=$VOICE_WINDOWS_SYSTEM_ROOT" --host_action_env="SystemRoot=$VOICE_WINDOWS_SYSTEM_ROOT"
|
||||
--action_env="PROCESSOR_ARCHITECTURE=$VOICE_WINDOWS_HOST_ARCH" --host_action_env="PROCESSOR_ARCHITECTURE=$VOICE_WINDOWS_HOST_ARCH"
|
||||
--workspace_status_command=./scripts/workspace-status.cmd)
|
||||
elif [[ "$RUNNER_OS" == macOS ]]; then
|
||||
flags+=(--macos_minimum_os=14.0)
|
||||
fi
|
||||
./.github/scripts/run-bazel-ci.sh "${wrapper[@]}" -- build "${flags[@]}" -- \
|
||||
//third_party/voice:native_sdk //third_party/voice:native_runtime
|
||||
runtime="bazel-bin/third_party/voice/native_runtime_${prefix}"
|
||||
output="$temp/cargo-voice-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT"
|
||||
python third_party/voice/cargo_ci.py stage --sdk "${runtime}_sdk" --runtime "$runtime" --output "$output" --target "$TARGET"
|
||||
tar -czf "$temp/cargo-voice.tar.gz" -C "$output" sdk runtime
|
||||
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
||||
with:
|
||||
name: cargo-voice-${{ inputs.target }}
|
||||
path: ${{ runner.temp }}/cargo-voice.tar.gz
|
||||
if-no-files-found: error
|
||||
overwrite: true
|
||||
- name: Stage verified native pkgconf, support DLLs, and license
|
||||
if: runner.os == 'Windows'
|
||||
id: pkgconf
|
||||
shell: pwsh
|
||||
run: |
|
||||
$directory = Split-Path -Parent $env:VOICE_PKG_CONFIG
|
||||
$license = Join-Path $directory "COPYING"
|
||||
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/pkgconf/pkgconf/d97cae4e2a169916f77d9ee8a46c011b69e42a7b/COPYING" -OutFile $license
|
||||
if ((Get-FileHash $license -Algorithm SHA256).Hash.ToLowerInvariant() -ne "055a265b839672a62f590869b0a1f8e4f5147e8f073c9ba77b17b8d7ad653966") {
|
||||
throw "Pinned pkgconf license mismatch"
|
||||
}
|
||||
"directory=$directory" | Out-File $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
||||
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
||||
if: runner.os == 'Windows'
|
||||
with:
|
||||
name: cargo-voice-pkgconf-${{ runner.arch }}
|
||||
path: ${{ steps.pkgconf.outputs.directory }}
|
||||
if-no-files-found: error
|
||||
overwrite: true
|
||||
62
third_party/voice/cargo-ci/setup/action.yml
vendored
Normal file
62
third_party/voice/cargo-ci/setup/action.yml
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
name: Set up Cargo voice inputs
|
||||
description: Use the target SDK and prepared runtime from this workflow run.
|
||||
inputs:
|
||||
target:
|
||||
description: Cargo target triple
|
||||
required: true
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
with:
|
||||
python-version: "3.12"
|
||||
- name: Ensure CMake is available for the Opus build
|
||||
if: runner.os == 'Linux'
|
||||
shell: bash
|
||||
run: command -v cmake || sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake
|
||||
- name: Ensure host pkg-config is available
|
||||
if: runner.os == 'macOS'
|
||||
shell: bash
|
||||
run: command -v pkg-config || brew install pkgconf
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: cargo-voice-${{ inputs.target }}
|
||||
path: ${{ runner.temp }}/cargo-voice-inputs
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
if: runner.os == 'Windows'
|
||||
with:
|
||||
# The x64 archive builder must execute x64 pkgconf even for ARM64.
|
||||
name: cargo-voice-pkgconf-${{ runner.arch }}
|
||||
path: ${{ runner.temp }}/cargo-voice-pkgconf
|
||||
- name: Configure target libraries for Cargo
|
||||
env:
|
||||
VOICE_TARGET: ${{ inputs.target }}
|
||||
shell: python
|
||||
run: |
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
|
||||
temp = Path(os.environ["RUNNER_TEMP"])
|
||||
target_dir = Path(os.environ["CARGO_TARGET_DIR"])
|
||||
root = Path(tempfile.mkdtemp(prefix="cargo-voice-", dir=target_dir))
|
||||
with tarfile.open(temp / "cargo-voice-inputs/cargo-voice.tar.gz") as archive:
|
||||
archive.extractall(root, filter="data")
|
||||
if os.name == "nt":
|
||||
os.environ["VOICE_PKG_CONFIG"] = str(temp / "cargo-voice-pkgconf/pkgconf.exe")
|
||||
script = Path(os.environ["GITHUB_WORKSPACE"]) / "third_party/voice/cargo_ci.py"
|
||||
subprocess.run([sys.executable, str(script), "configure", "--root", str(root),
|
||||
"--target", os.environ["VOICE_TARGET"]], check=True)
|
||||
# nextest collects linked libraries itself. Include the runtime manifest
|
||||
# and plugins too so the whole runtime can move with the test binaries.
|
||||
relative = (root / "runtime").relative_to(target_dir).as_posix()
|
||||
config = root / "nextest.toml"
|
||||
config.write_text('[profile.default]\narchive.include = [{ path = ' + json.dumps(relative)
|
||||
+ ', relative-to = "target", on-missing = "error" }]\n')
|
||||
with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as env:
|
||||
print(f"CODEX_VOICE_NEXTEST_CONFIG={config}", file=env)
|
||||
print(f"CODEX_VOICE_RUNTIME_RELATIVE={relative}", file=env)
|
||||
153
third_party/voice/cargo_ci.py
vendored
Normal file
153
third_party/voice/cargo_ci.py
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
"""Stage receipt-checked voice build inputs for Cargo and configure a shard."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
from release_runtime import stage as stage_runtime
|
||||
from runtime import digest
|
||||
from sdk import MODULES
|
||||
|
||||
|
||||
def read_receipt(path: Path, target: str, commit: str) -> dict:
|
||||
receipt = json.loads(path.read_text())
|
||||
if (
|
||||
receipt["target"] != target
|
||||
or receipt["sourceCommit"] != commit
|
||||
or receipt["sourceManifestSha256"]
|
||||
!= digest(Path(__file__).with_name("sources.json"))
|
||||
):
|
||||
raise ValueError("native inputs do not match target, commit and sources")
|
||||
return receipt
|
||||
|
||||
|
||||
def stage(sdk: Path, runtime: Path, output: Path, target: str, commit: str) -> None:
|
||||
sdk, runtime, output = (
|
||||
sdk.resolve(strict=True),
|
||||
runtime.resolve(strict=True),
|
||||
output.resolve(),
|
||||
)
|
||||
if any(output.is_relative_to(source) for source in (sdk, runtime)):
|
||||
raise ValueError("output must be outside the native inputs")
|
||||
files = read_receipt(sdk / "sdk.json", target, commit)["files"]
|
||||
native = read_receipt(runtime / "runtime.json", target, commit)
|
||||
library_dir = output / "runtime" / ("bin" if target.endswith("msvc") else "lib")
|
||||
prepared = {
|
||||
entry.get("sourceSha256"): runtime / entry["path"]
|
||||
for entry in native["libraries"]
|
||||
if Path(entry["path"]).parent.name == library_dir.name
|
||||
}
|
||||
|
||||
output.mkdir(parents=True)
|
||||
try:
|
||||
stage_runtime(runtime, output / "runtime", target)
|
||||
for entry in files:
|
||||
source = (sdk / entry["path"]).resolve(strict=True)
|
||||
relative = source.relative_to(sdk)
|
||||
if digest(source) != entry["sha256"]:
|
||||
raise ValueError(f"SDK file does not match its receipt: {relative}")
|
||||
dest = output / "sdk" / relative
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
if source.suffix == ".pc":
|
||||
# Some transitive libraries retain the producer's absolute prefix.
|
||||
dest.write_text(
|
||||
re.sub(
|
||||
r"^prefix=.*$",
|
||||
"prefix=${pcfiledir}/../..",
|
||||
source.read_text(),
|
||||
flags=re.MULTILINE,
|
||||
)
|
||||
)
|
||||
else:
|
||||
shutil.copy2(source, dest)
|
||||
|
||||
# Link with the prepared runtime bytes and put MSVC import libraries
|
||||
# beside their DLLs so nextest collects a self-contained search path.
|
||||
if relative.parent == Path("lib"):
|
||||
alias = library_dir / relative.name
|
||||
payload = (
|
||||
source if source.suffix == ".lib" else prepared.get(entry["sha256"])
|
||||
)
|
||||
if payload and not alias.exists():
|
||||
shutil.copy2(payload, alias)
|
||||
except BaseException:
|
||||
# Windows cannot delete read-only files copied from Bazel.
|
||||
if os.name == "nt":
|
||||
for copied in output.rglob("*"):
|
||||
copied.chmod(copied.stat().st_mode | stat.S_IWRITE)
|
||||
shutil.rmtree(output)
|
||||
raise
|
||||
|
||||
|
||||
def environment(root: Path, target: str, pkg_config: Path) -> dict[str, str]:
|
||||
root, pkg_config = root.resolve(strict=True), pkg_config.resolve(strict=True)
|
||||
read_receipt(root / "runtime/runtime.json", target, os.environ["GITHUB_SHA"])
|
||||
suffix = target.replace("-", "_")
|
||||
values = {
|
||||
f"PKG_CONFIG_{suffix}": str(pkg_config),
|
||||
f"PKG_CONFIG_PATH_{suffix}": str(root / "sdk/lib/pkgconfig"),
|
||||
"CODEX_TEST_VOICE_RUNTIME": str(root / "runtime"),
|
||||
}
|
||||
for module in MODULES:
|
||||
key = re.sub(r"[^A-Z0-9]", "_", module.upper())
|
||||
values[f"SYSTEM_DEPS_{key}_SEARCH_NATIVE"] = str(
|
||||
root / "runtime" / ("bin" if target.endswith("msvc") else "lib")
|
||||
)
|
||||
if module.startswith("gstreamer"):
|
||||
values[f"SYSTEM_DEPS_{key}_LDFLAGS"] = ""
|
||||
if not target.endswith("windows-msvc"):
|
||||
origin = "@loader_path" if target.endswith("darwin") else "$ORIGIN"
|
||||
values[f"CARGO_TARGET_{suffix.upper()}_RUSTFLAGS"] = (
|
||||
f"-C link-arg=-Wl,-rpath,{origin}/../lib"
|
||||
)
|
||||
return values
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
sub = parser.add_subparsers(dest="command", required=True)
|
||||
producer = sub.add_parser("stage")
|
||||
producer.add_argument("--sdk", type=Path, required=True)
|
||||
producer.add_argument("--runtime", type=Path, required=True)
|
||||
producer.add_argument("--output", type=Path, required=True)
|
||||
consumer = sub.add_parser("configure")
|
||||
consumer.add_argument("--root", type=Path, required=True)
|
||||
for command in (producer, consumer):
|
||||
command.add_argument("--target", required=True)
|
||||
args = parser.parse_args()
|
||||
if args.command == "stage":
|
||||
stage(
|
||||
args.sdk, args.runtime, args.output, args.target, os.environ["GITHUB_SHA"]
|
||||
)
|
||||
return
|
||||
pkg_config = os.environ.get("VOICE_PKG_CONFIG") or shutil.which("pkg-config")
|
||||
if not pkg_config:
|
||||
parser.error("pkg-config is required on the build host")
|
||||
values = environment(args.root, args.target, Path(pkg_config))
|
||||
# Probe only the staged SDK so a missing native module cannot resolve from
|
||||
# the host. Cargo keeps its usual system search for unrelated dependencies.
|
||||
probe_env = {
|
||||
**os.environ,
|
||||
"PKG_CONFIG_PATH": "",
|
||||
"PKG_CONFIG_LIBDIR": str(args.root.resolve() / "sdk/lib/pkgconfig"),
|
||||
}
|
||||
subprocess.run(
|
||||
[pkg_config, "--exists", *MODULES, "gstreamer-1.0 >= 1.28"],
|
||||
env=probe_env,
|
||||
check=True,
|
||||
)
|
||||
with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as output:
|
||||
for key, value in values.items():
|
||||
output.write(f"{key}={value}\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
33
third_party/voice/extensions.bzl
vendored
Normal file
33
third_party/voice/extensions.bzl
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Use standard Bazel archives for the standalone builder's pinned sources."""
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
|
||||
|
||||
_BUILD_FILE = """
|
||||
filegroup(
|
||||
name = "sources",
|
||||
srcs = glob(["**"]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
"""
|
||||
|
||||
def _voice_sources_impl(module_ctx):
|
||||
manifest = json.decode(module_ctx.read(Label("//third_party/voice:sources.json")))
|
||||
for source in manifest["sources"]:
|
||||
http_file(
|
||||
name = "voice_archive_" + source["name"].replace("-", "_"),
|
||||
urls = [source["url"]],
|
||||
sha256 = source["sha256"],
|
||||
downloaded_file_path = source["archive"],
|
||||
)
|
||||
http_archive(
|
||||
name = "voice_" + source["name"].replace("-", "_"),
|
||||
urls = [source["url"]],
|
||||
sha256 = source["sha256"],
|
||||
strip_prefix = source["root"],
|
||||
# Ninja's pinned codeload URL has no archive filename extension.
|
||||
type = "tar.gz" if source["name"] == "ninja" else "",
|
||||
build_file_content = _BUILD_FILE,
|
||||
)
|
||||
return module_ctx.extension_metadata(reproducible = True)
|
||||
|
||||
voice_sources = module_extension(implementation = _voice_sources_impl)
|
||||
503
third_party/voice/licenses/LGPL-2.1.txt
vendored
Normal file
503
third_party/voice/licenses/LGPL-2.1.txt
vendored
Normal file
@@ -0,0 +1,503 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
44
third_party/voice/licenses/Opus.txt
vendored
Normal file
44
third_party/voice/licenses/Opus.txt
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
Copyright 2001-2023 Xiph.Org, Skype Limited, Octasic,
|
||||
Jean-Marc Valin, Timothy B. Terriberry,
|
||||
CSIRO, Gregory Maxwell, Mark Borgerding,
|
||||
Erik de Castro Lopo, Mozilla, Amazon
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of Internet Society, IETF or IETF Trust, nor the
|
||||
names of specific contributors, may be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Opus is subject to the royalty-free patent licenses which are
|
||||
specified at:
|
||||
|
||||
Xiph.Org Foundation:
|
||||
https://datatracker.ietf.org/ipr/1524/
|
||||
|
||||
Microsoft Corporation:
|
||||
https://datatracker.ietf.org/ipr/1914/
|
||||
|
||||
Broadcom Corporation:
|
||||
https://datatracker.ietf.org/ipr/1526/
|
||||
104
third_party/voice/licenses/PCRE2.md
vendored
Normal file
104
third_party/voice/licenses/PCRE2.md
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
PCRE2 Licence
|
||||
=============
|
||||
|
||||
| SPDX-License-Identifier: | BSD-3-Clause WITH PCRE2-exception |
|
||||
|---------|-------|
|
||||
|
||||
PCRE2 is a library of functions to support regular expressions whose syntax
|
||||
and semantics are as close as possible to those of the Perl 5 language.
|
||||
|
||||
Releases 10.00 and above of PCRE2 are distributed under the terms of the "BSD"
|
||||
licence, as specified below, with one exemption for certain binary
|
||||
redistributions. The documentation for PCRE2, supplied in the "doc" directory,
|
||||
is distributed under the same terms as the software itself. The data in the
|
||||
testdata directory is not copyrighted and is in the public domain.
|
||||
|
||||
The basic library functions are written in C and are freestanding. Also
|
||||
included in the distribution is a just-in-time compiler that can be used to
|
||||
optimize pattern matching. This is an optional feature that can be omitted when
|
||||
the library is built. The just-in-time compiler is separately licensed under the
|
||||
"2-clause BSD" licence.
|
||||
|
||||
|
||||
COPYRIGHT
|
||||
---------
|
||||
|
||||
### The basic library functions
|
||||
|
||||
Written by: Philip Hazel
|
||||
Email local part: Philip.Hazel
|
||||
Email domain: gmail.com
|
||||
|
||||
Retired from University of Cambridge Computing Service,
|
||||
Cambridge, England.
|
||||
|
||||
Copyright (c) 1997-2007 University of Cambridge
|
||||
Copyright (c) 2007-2024 Philip Hazel
|
||||
All rights reserved.
|
||||
|
||||
### PCRE2 Just-In-Time compilation support
|
||||
|
||||
Written by: Zoltan Herczeg
|
||||
Email local part: hzmester
|
||||
Email domain: freemail.hu
|
||||
|
||||
Copyright (c) 2010-2024 Zoltan Herczeg
|
||||
All rights reserved.
|
||||
|
||||
### Stack-less Just-In-Time compiler
|
||||
|
||||
Written by: Zoltan Herczeg
|
||||
Email local part: hzmester
|
||||
Email domain: freemail.hu
|
||||
|
||||
Copyright (c) 2009-2024 Zoltan Herczeg
|
||||
All rights reserved.
|
||||
|
||||
The code in the `deps/sljit` directory has its own LICENSE file.
|
||||
|
||||
### All other contributions
|
||||
|
||||
Many other contributors have participated in the authorship of PCRE2. As PCRE2
|
||||
has never required a Contributor Licensing Agreement, or other copyright
|
||||
assignment agreement, all contributions have copyright retained by each
|
||||
original contributor or their employer.
|
||||
|
||||
|
||||
THE "BSD" LICENCE
|
||||
-----------------
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notices,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notices, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the University of Cambridge nor the names of any
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
EXEMPTION FOR BINARY LIBRARY-LIKE PACKAGES
|
||||
------------------------------------------
|
||||
|
||||
The second condition in the BSD licence (covering binary redistributions) does
|
||||
not apply all the way down a chain of software. If binary package A includes
|
||||
PCRE2, it must respect the condition, but if package B is software that
|
||||
includes package A, the condition is not imposed on package B unless it uses
|
||||
PCRE2 independently.
|
||||
21
third_party/voice/licenses/libffi.txt
vendored
Normal file
21
third_party/voice/licenses/libffi.txt
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
libffi - Copyright (c) 1996-2026 Anthony Green, Red Hat, Inc and others.
|
||||
See source files for details.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
``Software''), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
482
third_party/voice/licenses/proxy-libintl.txt
vendored
Normal file
482
third_party/voice/licenses/proxy-libintl.txt
vendored
Normal file
@@ -0,0 +1,482 @@
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the library GPL. It is
|
||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Library General Public License, applies to some
|
||||
specially designated Free Software Foundation software, and to any
|
||||
other libraries whose authors decide to use it. You can use it for
|
||||
your libraries, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if
|
||||
you distribute copies of the library, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link a program with the library, you must provide
|
||||
complete object files to the recipients so that they can relink them
|
||||
with the library, after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
Our method of protecting your rights has two steps: (1) copyright
|
||||
the library, and (2) offer you this license which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
Also, for each distributor's protection, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
library. If the library is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original
|
||||
version, so that any problems introduced by others will not reflect on
|
||||
the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that companies distributing free
|
||||
software will individually obtain patent licenses, thus in effect
|
||||
transforming the program into proprietary software. To prevent this,
|
||||
we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary
|
||||
GNU General Public License, which was designed for utility programs. This
|
||||
license, the GNU Library General Public License, applies to certain
|
||||
designated libraries. This license is quite different from the ordinary
|
||||
one; be sure to read it in full, and don't assume that anything in it is
|
||||
the same as in the ordinary license.
|
||||
|
||||
The reason we have a separate public license for some libraries is that
|
||||
they blur the distinction we usually make between modifying or adding to a
|
||||
program and simply using it. Linking a program with a library, without
|
||||
changing the library, is in some sense simply using the library, and is
|
||||
analogous to running a utility program or application program. However, in
|
||||
a textual and legal sense, the linked executable is a combined work, a
|
||||
derivative of the original library, and the ordinary General Public License
|
||||
treats it as such.
|
||||
|
||||
Because of this blurred distinction, using the ordinary General
|
||||
Public License for libraries did not effectively promote software
|
||||
sharing, because most developers did not use the libraries. We
|
||||
concluded that weaker conditions might promote sharing better.
|
||||
|
||||
However, unrestricted linking of non-free programs would deprive the
|
||||
users of those programs of all benefit from the free status of the
|
||||
libraries themselves. This Library General Public License is intended to
|
||||
permit developers of non-free programs to use free libraries, while
|
||||
preserving your freedom as a user of such programs to change the free
|
||||
libraries that are incorporated in them. (We have not seen how to achieve
|
||||
this as regards changes in header files, but we have achieved it as regards
|
||||
changes in the actual functions of the Library.) The hope is that this
|
||||
will lead to faster development of free libraries.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, while the latter only
|
||||
works together with the library.
|
||||
|
||||
Note that it is possible for a library to be covered by the ordinary
|
||||
General Public License rather than by this special one.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library which
|
||||
contains a notice placed by the copyright holder or other authorized
|
||||
party saying it may be distributed under the terms of this Library
|
||||
General Public License (also called "this License"). Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also compile or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
c) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
d) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the source code distributed need not include anything that is normally
|
||||
distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Library General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
25
third_party/voice/licenses/sljit.txt
vendored
Normal file
25
third_party/voice/licenses/sljit.txt
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Stack-less Just-In-Time compiler
|
||||
*
|
||||
* Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
22
third_party/voice/licenses/zlib.txt
vendored
Normal file
22
third_party/voice/licenses/zlib.txt
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright notice:
|
||||
|
||||
(C) 1995-2026 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
155
third_party/voice/linux_runtime.py
vendored
Normal file
155
third_party/voice/linux_runtime.py
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
"""Prepare verified GNU Linux audio libraries with package-relative loader paths."""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
|
||||
# Import only this script's siblings, including under PYTHONSAFEPATH.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from runtime import Binary, PLUGINS, RuntimeFormat, prepare, required_library_paths
|
||||
|
||||
SYSTEM_IMPORTS = frozenset(
|
||||
{
|
||||
"libc.so.6",
|
||||
"libm.so.6",
|
||||
"libdl.so.2",
|
||||
"libpthread.so.0",
|
||||
"librt.so.1",
|
||||
"libresolv.so.2",
|
||||
"ld-linux-x86-64.so.2",
|
||||
"ld-linux-aarch64.so.1",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def inspect(path, target):
|
||||
machine = {"x86_64-unknown-linux-gnu": 62, "aarch64-unknown-linux-gnu": 183}[target]
|
||||
with path.open("rb") as source:
|
||||
data = source.read(64 * 1024 * 1024 + 1)
|
||||
if not 64 <= len(data) <= 64 * 1024 * 1024:
|
||||
raise ValueError("invalid ELF file size")
|
||||
header = struct.unpack_from("<16sHHIQQQIHHHHHH", data)
|
||||
if header[0][:7] != b"\x7fELF\x02\x01\x01" or header[0][7] not in (0, 3):
|
||||
raise ValueError("expected a little-endian ELF64 library")
|
||||
if header[1:4] != (3, machine, 1) or header[8:10] != (64, 56):
|
||||
raise ValueError(f"expected a {target} shared library")
|
||||
phoff, count = header[5], header[10]
|
||||
if not 1 <= count <= 128 or phoff < 64 or phoff + count * 56 > len(data):
|
||||
raise ValueError("invalid ELF program headers")
|
||||
loads, dynamic = [], []
|
||||
for index in range(count):
|
||||
kind, _, offset, address, _, size, memory_size, _ = struct.unpack_from(
|
||||
"<IIQQQQQQ", data, phoff + index * 56
|
||||
)
|
||||
if size > memory_size or offset + size > len(data):
|
||||
raise ValueError("invalid ELF segment bounds")
|
||||
if kind == 1:
|
||||
loads.append((address, offset, size))
|
||||
elif kind == 2:
|
||||
dynamic.append((offset, size, address))
|
||||
elif kind == 3:
|
||||
raise ValueError("an ELF runtime library must not name an interpreter")
|
||||
if len(dynamic) != 1 or not 16 <= dynamic[0][1] <= 65536 or dynamic[0][1] % 16:
|
||||
raise ValueError("invalid ELF dynamic table")
|
||||
tags = {}
|
||||
offset, size, address = dynamic[0]
|
||||
mappings = [
|
||||
file_offset + address - start
|
||||
for start, file_offset, length in loads
|
||||
if start <= address and address + size <= start + length
|
||||
]
|
||||
if mappings != [offset]:
|
||||
raise ValueError("ELF dynamic table must have one matching file-backed mapping")
|
||||
for cursor in range(offset, offset + size, 16):
|
||||
tag, value = struct.unpack_from("<qQ", data, cursor)
|
||||
if tag == 0:
|
||||
break
|
||||
# Auxiliary/filter libraries and audit modules are additional loader inputs.
|
||||
if tag in (0x7FFFFFFD, 0x7FFFFFFF, 0x6FFFFEFB, 0x6FFFFEFC):
|
||||
raise ValueError("unsupported ELF loader dependency")
|
||||
tags.setdefault(tag, []).append(value)
|
||||
else:
|
||||
raise ValueError("unterminated ELF dynamic table")
|
||||
if any(len(tags.get(tag, [])) != 1 for tag in (5, 10)):
|
||||
raise ValueError("invalid ELF dynamic string table")
|
||||
address, size = tags[5][0], tags[10][0]
|
||||
offsets = [
|
||||
offset + address - start
|
||||
for start, offset, length in loads
|
||||
if start <= address and address + size <= start + length
|
||||
]
|
||||
if len(offsets) != 1 or not 1 <= size <= 1024 * 1024:
|
||||
raise ValueError("invalid ELF string table bounds")
|
||||
strings = data[offsets[0] : offsets[0] + size]
|
||||
values = {}
|
||||
for tag in (1, 14, 15, 29):
|
||||
values[tag] = []
|
||||
if tag != 1 and len(tags.get(tag, [])) > 1:
|
||||
raise ValueError("duplicate ELF loader metadata")
|
||||
for offset in tags.get(tag, []):
|
||||
end = strings.find(b"\0", offset)
|
||||
if not 0 <= offset < len(strings) or end < 0:
|
||||
raise ValueError("invalid ELF loader string")
|
||||
value = (
|
||||
os.fsdecode(strings[offset:end])
|
||||
if tag in (15, 29)
|
||||
else strings[offset:end].decode("ascii")
|
||||
)
|
||||
if tag in (1, 14) and not re.fullmatch(
|
||||
r"[A-Za-z0-9_+.-]+\.so(?:\.[0-9]+)*", value
|
||||
):
|
||||
raise ValueError("ELF dependencies must be plain library names")
|
||||
values[tag].append(value)
|
||||
identity = values[14][0] if values[14] else path.name
|
||||
return Binary(
|
||||
identity,
|
||||
tuple(values[1]),
|
||||
tuple(f"{tag}={value}" for tag in (15, 29) for value in values[tag]),
|
||||
)
|
||||
|
||||
|
||||
def finalize_copy(destination, metadata, dependency_paths):
|
||||
allowed = {"29=$ORIGIN", "29=$ORIGIN:$ORIGIN/.."}
|
||||
needs_parent = destination.parent.name == "gstreamer-1.0"
|
||||
required = "29=$ORIGIN:$ORIGIN/.." if needs_parent else "29=$ORIGIN"
|
||||
if any(path not in allowed for path in metadata.rpaths) or (
|
||||
any(name not in SYSTEM_IMPORTS for name in metadata.imports)
|
||||
and required not in metadata.rpaths
|
||||
and "29=$ORIGIN:$ORIGIN/.." not in metadata.rpaths
|
||||
):
|
||||
raise ValueError("rebuild native libraries with package-relative runtime paths")
|
||||
return metadata
|
||||
|
||||
|
||||
def project(prefix, receipts, target, output):
|
||||
if sys.platform != "linux" or target not in (
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"aarch64-unknown-linux-gnu",
|
||||
):
|
||||
raise ValueError(
|
||||
"runtime preparation requires GNU Linux and an explicit GNU target"
|
||||
)
|
||||
format = RuntimeFormat(
|
||||
tuple(Path(f"lib/gstreamer-1.0/libgst{name}.so") for name in sorted(PLUGINS)),
|
||||
SYSTEM_IMPORTS,
|
||||
inspect,
|
||||
finalize_copy,
|
||||
plugin_dir="lib/gstreamer-1.0",
|
||||
required_libraries=tuple(
|
||||
Path(path).name for path in required_library_paths(target)
|
||||
),
|
||||
)
|
||||
prepare(prefix, receipts, target, output, format)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--prefix", type=Path, required=True)
|
||||
parser.add_argument("--receipts", type=Path, required=True)
|
||||
parser.add_argument("--target", required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
project(args.prefix, args.receipts, args.target, args.output)
|
||||
168
third_party/voice/macos_runtime.py
vendored
Normal file
168
third_party/voice/macos_runtime.py
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
"""Project a verified macOS prefix into a private, relocatable development runtime."""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Import only this script's siblings, including under PYTHONSAFEPATH.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from runtime import Binary as MachO
|
||||
from runtime import PLUGINS, RuntimeFormat, digest, prepare, required_library_paths
|
||||
|
||||
SYSTEM_IMPORTS = frozenset(
|
||||
{
|
||||
"/usr/lib/libSystem.B.dylib",
|
||||
"/usr/lib/libc++.1.dylib",
|
||||
"/usr/lib/libobjc.A.dylib",
|
||||
"/usr/lib/libiconv.2.dylib",
|
||||
"/usr/lib/libresolv.9.dylib",
|
||||
"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit",
|
||||
"/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation",
|
||||
"/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices",
|
||||
"/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def run(command):
|
||||
return subprocess.check_output(
|
||||
command, text=True, stderr=subprocess.STDOUT, timeout=30
|
||||
)
|
||||
|
||||
|
||||
def inspect(path, target):
|
||||
cpu = {"aarch64-apple-darwin": "ARM64", "x86_64-apple-darwin": "X86_64"}[target]
|
||||
try:
|
||||
output = run(
|
||||
[
|
||||
"/usr/bin/xcrun",
|
||||
"llvm-objdump",
|
||||
"--macho",
|
||||
"--universal-headers",
|
||||
"--private-headers",
|
||||
str(path),
|
||||
]
|
||||
)
|
||||
except subprocess.CalledProcessError as error:
|
||||
raise ValueError("LLVM rejected the Mach-O library") from error
|
||||
header, *commands = re.split(r"(?m)^Load command [0-9]+\n", output)
|
||||
match = re.fullmatch(
|
||||
r"Mach header\n[^\n]+\nMH_MAGIC_64 +"
|
||||
+ cpu
|
||||
+ r" +\S+ +\S+ +DYLIB +(\d+) +(\d+) +[^\n]+\n",
|
||||
header.removeprefix(str(path) + ":\n"),
|
||||
)
|
||||
if not match or len(commands) != int(match[1]) or int(match[2]) > 1024 * 1024:
|
||||
raise ValueError(f"expected a thin {target} dylib with bounded load commands")
|
||||
identities, imports, rpaths = [], [], []
|
||||
for block in commands:
|
||||
match = re.match(r" +cmd (\S+)\n +cmdsize ([0-9]+)\n", block)
|
||||
if not match:
|
||||
raise ValueError("unrecognized LLVM load-command output")
|
||||
command = match[1]
|
||||
if command in {
|
||||
"LC_PREBOUND_DYLIB",
|
||||
"LC_REEXPORT_DYLIB",
|
||||
"LC_LAZY_LOAD_DYLIB",
|
||||
"LC_LOAD_UPWARD_DYLIB",
|
||||
"LC_DYLD_ENVIRONMENT",
|
||||
"LC_DYLIB_CODE_SIGN_DRS",
|
||||
"LC_LAZY_LOAD_DYLIB_INFO",
|
||||
"?(0x0000003a)",
|
||||
}:
|
||||
raise ValueError(f"unsupported loader command: {command}")
|
||||
if command not in {
|
||||
"LC_ID_DYLIB",
|
||||
"LC_LOAD_DYLIB",
|
||||
"LC_LOAD_WEAK_DYLIB",
|
||||
"LC_RPATH",
|
||||
}:
|
||||
continue
|
||||
# Match the entire command to reject multiline names masquerading as metadata.
|
||||
pattern = r" +path ([^\r\n]+) \(offset [0-9]+\)\n"
|
||||
if command != "LC_RPATH":
|
||||
pattern = (
|
||||
r" +name ([^\r\n]+) \(offset [0-9]+\)\n"
|
||||
r" +time stamp [^\n]+\n +current version [^\n]+\ncompatibility version [^\n]+\n"
|
||||
)
|
||||
value = re.fullmatch(pattern, block[match.end() :])
|
||||
if not value:
|
||||
raise ValueError(
|
||||
"undeclared native dependency or unrecognized LLVM loader output"
|
||||
)
|
||||
if command == "LC_ID_DYLIB":
|
||||
identities.append(value[1])
|
||||
elif command == "LC_RPATH":
|
||||
rpaths.append(value[1])
|
||||
else:
|
||||
imports.append(value[1])
|
||||
if len(identities) != 1 or not re.fullmatch(
|
||||
r"[A-Za-z0-9_+.-]+\.dylib", Path(identities[0]).name
|
||||
):
|
||||
raise ValueError("expected one valid native library identity")
|
||||
return MachO(identities[0], tuple(imports), tuple(rpaths))
|
||||
|
||||
|
||||
def finalize_copy(destination, metadata, dependency_paths):
|
||||
identity = f"@rpath/{destination.name}"
|
||||
command = ["/usr/bin/install_name_tool", "-id", identity]
|
||||
imports = []
|
||||
for dependency in metadata.imports:
|
||||
rewritten = dependency
|
||||
if dependency not in SYSTEM_IMPORTS:
|
||||
rewritten = "@loader_path/" + os.path.relpath(
|
||||
dependency_paths[dependency], destination.parent
|
||||
)
|
||||
command.extend(["-change", dependency, rewritten])
|
||||
imports.append(rewritten)
|
||||
for rpath in metadata.rpaths:
|
||||
command.extend(["-delete_rpath", rpath])
|
||||
run([*command, str(destination)])
|
||||
# Development code signatures only; no identity, entitlement or trust-policy changes.
|
||||
run(
|
||||
[
|
||||
"/usr/bin/codesign",
|
||||
"--force",
|
||||
"--sign",
|
||||
"-",
|
||||
"--timestamp=none",
|
||||
str(destination),
|
||||
]
|
||||
)
|
||||
run(["/usr/bin/codesign", "--verify", "--strict", str(destination)])
|
||||
return MachO(identity, tuple(imports), ())
|
||||
|
||||
|
||||
def project(prefix, receipts, target, output):
|
||||
if sys.platform != "darwin" or target not in (
|
||||
"aarch64-apple-darwin",
|
||||
"x86_64-apple-darwin",
|
||||
):
|
||||
raise ValueError(
|
||||
"runtime projection requires macOS and an explicit macOS target"
|
||||
)
|
||||
format = RuntimeFormat(
|
||||
tuple(
|
||||
Path(f"lib/gstreamer-1.0/libgst{name}.dylib") for name in sorted(PLUGINS)
|
||||
),
|
||||
SYSTEM_IMPORTS,
|
||||
inspect,
|
||||
finalize_copy,
|
||||
required_libraries=tuple(
|
||||
Path(path).name for path in required_library_paths(target)
|
||||
),
|
||||
)
|
||||
prepare(prefix, receipts, target, output, format)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--prefix", type=Path, required=True)
|
||||
parser.add_argument("--receipts", type=Path, required=True)
|
||||
parser.add_argument("--target", required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
project(args.prefix, args.receipts, args.target, args.output)
|
||||
110
third_party/voice/native.bzl
vendored
Normal file
110
third_party/voice/native.bzl
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
"""Build-only native voice prefix using the same recipe as release packaging."""
|
||||
|
||||
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
|
||||
load("@rules_foreign_cc//foreign_cc/private:cc_toolchain_util.bzl", "absolutize_path_in_str", "get_env_vars", "get_flags_info", "get_tools_info")
|
||||
load("@rules_python//python:py_runtime_info.bzl", "PyRuntimeInfo")
|
||||
|
||||
def _native_prefix_impl(ctx):
|
||||
cc = find_cpp_toolchain(ctx)
|
||||
features = cc_common.configure_features(
|
||||
ctx = ctx,
|
||||
cc_toolchain = cc,
|
||||
requested_features = ctx.features,
|
||||
unsupported_features = ctx.disabled_features,
|
||||
)
|
||||
runtime = cc.static_runtime_lib(feature_configuration = features)
|
||||
tools = get_tools_info(ctx)
|
||||
flags = get_flags_info(ctx)
|
||||
minimums = [flag.removeprefix("-mmacosx-version-min=") for flag in flags.cc if flag.startswith("-mmacosx-version-min=")]
|
||||
if ctx.attr.target.endswith("apple-darwin") and len(minimums) != 1:
|
||||
fail("The native prefix requires one macOS minimum from the CcToolchain")
|
||||
python = ctx.attr._python[PyRuntimeInfo]
|
||||
if not python.interpreter:
|
||||
fail("The native prefix requires a declared Python interpreter")
|
||||
prefix = ctx.actions.declare_file(ctx.label.name + "/prefix.tar")
|
||||
receipt = ctx.actions.declare_file(ctx.label.name + "/built.json")
|
||||
config = ctx.actions.declare_file(ctx.label.name + ".json")
|
||||
values = {
|
||||
"archives": [file.path for file in ctx.files.archives],
|
||||
"prefix": prefix.path,
|
||||
"receipt": receipt.path,
|
||||
"target": ctx.attr.target,
|
||||
"deployment_target": minimums[0] if minimums else None,
|
||||
"jobs": 8,
|
||||
"cc": tools.cc,
|
||||
"cxx": tools.cxx,
|
||||
"ar": tools.cxx_linker_static,
|
||||
"ranlib": ctx.executable._ranlib.path,
|
||||
"ld": ctx.executable._ld.path,
|
||||
"shell": "/bin/bash",
|
||||
"pkg_config": ctx.file._pkg_config.path,
|
||||
}
|
||||
inputs = [cc.all_files, python.files, runtime, ctx.attr._pkg_config.files]
|
||||
for name in ("cmake", "make"):
|
||||
tool = ctx.toolchains["@rules_foreign_cc//toolchains:" + name + "_toolchain"].data
|
||||
if not tool.target:
|
||||
fail("The native prefix requires a declared " + name + " tool")
|
||||
values[name] = tool.path
|
||||
|
||||
# Prebuilt tools expose a package-relative path; built tools already
|
||||
# include their tree artifact. Match the upstream tool-access convention.
|
||||
for file in tool.target.files.to_list():
|
||||
if file.path.endswith("/" + tool.path):
|
||||
values[name] = file.path
|
||||
break
|
||||
inputs.append(tool.target.files)
|
||||
for name, arguments in {
|
||||
"c_flag": flags.cc,
|
||||
"cxx_flag": flags.cxx,
|
||||
# Upstream selects executable vs shared output. Retain their common
|
||||
# driver/SDK flags without forcing one output kind on configure probes.
|
||||
"link_flag": [flag for flag in flags.cxx_linker_shared if flag in flags.cxx_linker_executable] + [file.path for file in runtime.to_list()],
|
||||
}.items():
|
||||
values[name] = [absolutize_path_in_str(ctx.workspace_name, "@VOICE_EXECROOT@/", flag) for flag in arguments]
|
||||
ctx.actions.write(config, json.encode(values))
|
||||
ctx.actions.run(
|
||||
executable = python.interpreter,
|
||||
arguments = [ctx.file._driver.path, config.path],
|
||||
inputs = depset(
|
||||
[config, ctx.file._driver, python.interpreter] + ctx.files.archives + ctx.files._recipe,
|
||||
transitive = inputs,
|
||||
),
|
||||
tools = [
|
||||
ctx.attr._ranlib[DefaultInfo].files_to_run,
|
||||
ctx.attr._ld[DefaultInfo].files_to_run,
|
||||
],
|
||||
outputs = [prefix, receipt],
|
||||
env = get_env_vars(ctx),
|
||||
execution_requirements = {
|
||||
"no-remote-exec": "1",
|
||||
"no-remote-cache": "1",
|
||||
} if ctx.attr.target.endswith("apple-darwin") else {},
|
||||
mnemonic = "VoiceNativePrefix",
|
||||
progress_message = "Building native voice prefix for " + ctx.attr.target,
|
||||
)
|
||||
return [
|
||||
DefaultInfo(files = depset([prefix])),
|
||||
OutputGroupInfo(receipt = depset([receipt])),
|
||||
]
|
||||
|
||||
native_prefix = rule(
|
||||
implementation = _native_prefix_impl,
|
||||
attrs = {
|
||||
"archives": attr.label_list(allow_files = True, mandatory = True),
|
||||
"copts": attr.string_list(),
|
||||
"target": attr.string(mandatory = True),
|
||||
"_driver": attr.label(default = "//third_party/voice:bazel_native.py", allow_single_file = True),
|
||||
"_recipe": attr.label(default = "//third_party/voice:native_recipe"),
|
||||
"_python": attr.label(default = "@python_3_12//:py3_runtime", cfg = "exec"),
|
||||
"_ranlib": attr.label(default = "@llvm//tools:llvm-ranlib", executable = True, allow_files = True, cfg = "exec"),
|
||||
"_ld": attr.label(default = "//third_party/voice:pkg_config_linker", executable = True, allow_files = True, cfg = "exec"),
|
||||
"_pkg_config": attr.label(default = "//third_party/voice:pkg_config", allow_single_file = True, cfg = "exec"),
|
||||
},
|
||||
fragments = ["cpp"],
|
||||
toolchains = [
|
||||
"@bazel_tools//tools/cpp:toolchain_type",
|
||||
"@rules_foreign_cc//toolchains:cmake_toolchain",
|
||||
"@rules_foreign_cc//toolchains:make_toolchain",
|
||||
],
|
||||
)
|
||||
117
third_party/voice/native_link.bzl
vendored
Normal file
117
third_party/voice/native_link.bzl
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
"""Expose prepared native libraries to standard CcInfo linking and runfiles."""
|
||||
|
||||
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
|
||||
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
|
||||
load("@rules_python//python:py_runtime_info.bzl", "PyRuntimeInfo")
|
||||
|
||||
# ABI filenames from the pinned native sources. Missing outputs fail the build.
|
||||
_ABI_VERSIONS = {
|
||||
"ffi": "8",
|
||||
"gio-2.0": "0",
|
||||
"glib-2.0": "0",
|
||||
"gmodule-2.0": "0",
|
||||
"gobject-2.0": "0",
|
||||
"gstapp-1.0": "0",
|
||||
"gstaudio-1.0": "0",
|
||||
"gstbase-1.0": "0",
|
||||
"gstnet-1.0": "0",
|
||||
"gstpbutils-1.0": "0",
|
||||
"gstreamer-1.0": "0",
|
||||
"gstrtp-1.0": "0",
|
||||
"gsttag-1.0": "0",
|
||||
"gstvideo-1.0": "0",
|
||||
"intl": "8",
|
||||
"opus": "0",
|
||||
"pcre2-8": "0",
|
||||
"z": "1",
|
||||
}
|
||||
|
||||
def _native_link_impl(ctx):
|
||||
runtime = ctx.file.runtime
|
||||
versions = dict(_ABI_VERSIONS)
|
||||
macos = ctx.attr.target.endswith("apple-darwin")
|
||||
windows = ctx.attr.target.endswith("windows-msvc")
|
||||
if ctx.attr.target.endswith("unknown-linux-gnu"):
|
||||
versions["gstallocators-1.0"] = "0"
|
||||
sdk = ctx.attr.runtime[OutputGroupInfo].sdk.to_list()[0] if windows else None
|
||||
locator = ctx.actions.declare_directory(ctx.label.name + "/lib/search-path")
|
||||
originals, aliases, libraries = [], [], []
|
||||
arguments = [locator.path]
|
||||
cc = find_cpp_toolchain(ctx)
|
||||
features = cc_common.configure_features(
|
||||
ctx = ctx,
|
||||
cc_toolchain = cc,
|
||||
requested_features = ctx.features,
|
||||
unsupported_features = ctx.disabled_features,
|
||||
)
|
||||
for name, version in versions.items():
|
||||
filename = "lib" + name + ("." + version + ".dylib" if macos else ".so." + version)
|
||||
alias = "lib" + name + (".dylib" if macos else ".so")
|
||||
directory = "lib"
|
||||
if windows:
|
||||
# Windows names come from the same pinned recipe's SDK and runtime.
|
||||
filename = {"ffi": "libffi-8.dll", "intl": "intl-8.dll", "opus": "opus.dll", "pcre2-8": "pcre2-8.dll", "z": "z.dll"}.get(name, name + "-0.dll")
|
||||
alias = ("libffi" if name == "ffi" else name) + ".lib"
|
||||
directory = "bin"
|
||||
library = ctx.actions.declare_file(ctx.label.name + "/" + directory + "/" + filename)
|
||||
development = ctx.actions.declare_file(ctx.label.name + "/lib/" + alias)
|
||||
originals.append(library)
|
||||
aliases.append(development)
|
||||
arguments.extend([runtime.path + "/" + directory + "/" + filename, library.path])
|
||||
arguments.extend([sdk.path + "/lib/" + alias if windows else runtime.path + "/lib/" + filename, development.path])
|
||||
libraries.append(cc_common.create_library_to_link(
|
||||
actions = ctx.actions,
|
||||
feature_configuration = features,
|
||||
cc_toolchain = cc,
|
||||
dynamic_library = library,
|
||||
interface_library = development if windows else None,
|
||||
# @loader_path/$ORIGIN dependencies must stay beside one another.
|
||||
dynamic_library_symlink_path = "voice/" + ctx.label.name + "/" + filename,
|
||||
))
|
||||
payloads = []
|
||||
paths = ["runtime.json"] + [
|
||||
("bin/gst" + plugin + ".dll" if windows else "plugins/libgst" + plugin + ".dylib" if macos else "lib/gstreamer-1.0/libgst" + plugin + ".so")
|
||||
for plugin in "app audioconvert audioresample coreelements opus rtp rtpmanager".split(" ")
|
||||
]
|
||||
for path in paths:
|
||||
payload = ctx.actions.declare_file(ctx.label.name + "/" + path)
|
||||
payloads.append(payload)
|
||||
arguments.extend([runtime.path + "/" + path, payload.path])
|
||||
python = ctx.attr._python[PyRuntimeInfo]
|
||||
ctx.actions.run(
|
||||
executable = python.interpreter,
|
||||
inputs = depset([runtime, ctx.file._copy, python.interpreter] + ([sdk] if windows else []), transitive = [python.files]),
|
||||
outputs = [locator] + originals + aliases + payloads,
|
||||
arguments = [ctx.file._copy.path] + arguments,
|
||||
mnemonic = "VoiceNativeLinkInputs",
|
||||
)
|
||||
linker = cc_common.create_linker_input(
|
||||
owner = ctx.label,
|
||||
user_link_flags = depset([] if windows else [
|
||||
"-Wl,-rpath," + ("@loader_path/../lib" if macos else "$ORIGIN/../lib"),
|
||||
]),
|
||||
libraries = depset(libraries),
|
||||
additional_inputs = depset([locator] + aliases),
|
||||
)
|
||||
return [
|
||||
CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset([linker]))),
|
||||
DefaultInfo(
|
||||
# A real directory permits unambiguous $(execpath :native_link)/..
|
||||
# in build-script settings; a marker file followed by /.. would fail.
|
||||
files = depset([locator]),
|
||||
runfiles = ctx.runfiles(files = [locator] + originals + aliases + payloads + [lib.dynamic_library for lib in libraries]),
|
||||
),
|
||||
]
|
||||
|
||||
native_link = rule(
|
||||
implementation = _native_link_impl,
|
||||
attrs = {
|
||||
"runtime": attr.label(mandatory = True, allow_single_file = True),
|
||||
"target": attr.string(mandatory = True),
|
||||
"_copy": attr.label(default = "//third_party/voice:bazel_copy.py", allow_single_file = True),
|
||||
"_python": attr.label(default = "@python_3_12//:py3_runtime", cfg = "exec"),
|
||||
},
|
||||
fragments = ["cpp"],
|
||||
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
|
||||
)
|
||||
14
third_party/voice/opus-toolchain.cmake
vendored
Normal file
14
third_party/voice/opus-toolchain.cmake
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# CMake's generator must use the Ninja declared in the Bazel action.
|
||||
set(CMAKE_MAKE_PROGRAM "$ENV{CODEX_VOICE_NINJA}" CACHE FILEPATH "" FORCE)
|
||||
# Archiver paths from Bazel are relative to the execution root.
|
||||
get_filename_component(CMAKE_AR "$ENV{AR}" ABSOLUTE
|
||||
BASE_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
|
||||
if("$ENV{TARGET}" MATCHES "apple-darwin$")
|
||||
set(CMAKE_SYSTEM_NAME Darwin)
|
||||
elseif("$ENV{TARGET}" MATCHES "windows")
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
else()
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
endif()
|
||||
string(REGEX REPLACE "-.*" "" CMAKE_SYSTEM_PROCESSOR "$ENV{TARGET}")
|
||||
# Compiler, SDK and linker inputs remain supplied by Bazel's target toolchain.
|
||||
80
third_party/voice/package_runtime.py
vendored
Normal file
80
third_party/voice/package_runtime.py
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
"""Validate prepared runtime files before copying them into a private package.
|
||||
|
||||
The runtime receipt records preparation, not authenticity. Preserve its bytes and
|
||||
layout; native loader inspection remains the platform preparer's responsibility.
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
from runtime import PLUGINS, digest, required_library_paths
|
||||
|
||||
|
||||
def runtime_files(
|
||||
root: Path, target: str, *, public_release: bool = False
|
||||
) -> dict[str, str]:
|
||||
manifest_path = root / "runtime.json"
|
||||
if manifest_path.is_symlink() or not manifest_path.is_file():
|
||||
raise ValueError("runtime manifest must be a regular file")
|
||||
with manifest_path.open("rb") as source:
|
||||
data = source.read(1024 * 1024 + 1)
|
||||
if len(data) > 1024 * 1024:
|
||||
raise ValueError("runtime manifest exceeds limit")
|
||||
manifest = json.loads(data)
|
||||
if (
|
||||
manifest.get("schemaVersion") != 1
|
||||
or manifest.get("developmentOnly") is not (not public_release)
|
||||
or (public_release and manifest.get("distribution") != "publicRelease")
|
||||
or manifest.get("target") != target
|
||||
or manifest.get("sourceManifestSha256")
|
||||
!= digest(Path(__file__).with_name("sources.json"))
|
||||
or not re.fullmatch(r"[0-9a-f]{40}", manifest.get("sourceCommit", ""))
|
||||
):
|
||||
raise ValueError(
|
||||
"runtime receipt does not match the source inputs and helper target"
|
||||
)
|
||||
if target.endswith("-apple-darwin"):
|
||||
pattern, plugin = (
|
||||
r"(?:lib|plugins)/[A-Za-z0-9_+.-]+\.dylib",
|
||||
"plugins/libgst{}.dylib",
|
||||
)
|
||||
elif target.endswith("-unknown-linux-gnu"):
|
||||
pattern, plugin = (
|
||||
r"lib/(?:gstreamer-1\.0/)?[A-Za-z0-9_+.-]+\.so(?:\.[0-9]+)*",
|
||||
"lib/gstreamer-1.0/libgst{}.so",
|
||||
)
|
||||
elif target.endswith("-pc-windows-msvc"):
|
||||
pattern, plugin = r"bin/[A-Za-z0-9_+.-]+\.[dD][lL][lL]", "bin/gst{}.dll"
|
||||
else:
|
||||
raise ValueError("unsupported native runtime target")
|
||||
libraries = manifest.get("libraries", [])
|
||||
if not 1 <= len(libraries) <= 128:
|
||||
raise ValueError("unexpected runtime inventory size")
|
||||
files, names = {}, set()
|
||||
for record in libraries:
|
||||
name, expected = record["path"], record["sha256"]
|
||||
if not re.fullmatch(pattern, name) or name.casefold() in names:
|
||||
raise ValueError("invalid or colliding runtime path")
|
||||
path = root / name
|
||||
if (
|
||||
path.parent.is_symlink()
|
||||
or path.is_symlink()
|
||||
or not path.is_file()
|
||||
or not path.resolve().is_relative_to(root)
|
||||
):
|
||||
raise ValueError("runtime entries must be regular files inside the input")
|
||||
if not re.fullmatch(r"[0-9a-f]{64}", expected) or digest(path) != expected:
|
||||
raise ValueError("runtime file digest mismatch")
|
||||
names.add(name.casefold())
|
||||
files[name] = expected
|
||||
plugins = sorted(plugin.format(name) for name in PLUGINS)
|
||||
if sorted(manifest.get("plugins", [])) != plugins or not set(plugins).issubset(
|
||||
files
|
||||
):
|
||||
raise ValueError("runtime must include exactly the selected plugins")
|
||||
if not set(required_library_paths(target)).issubset(files):
|
||||
raise ValueError("runtime must include the required libraries")
|
||||
files["runtime.json"] = hashlib.sha256(data).hexdigest()
|
||||
return files
|
||||
33
third_party/voice/pkg_config.bzl
vendored
Normal file
33
third_party/voice/pkg_config.bzl
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Build the pinned pkg-config with native Mac configure checks."""
|
||||
|
||||
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make_variant")
|
||||
|
||||
def pkg_config(name, **kwargs):
|
||||
"""Keep Linux remote builds and select native Mac producers by OS and CPU."""
|
||||
tags = kwargs.pop("tags", [])
|
||||
configure_make_variant(
|
||||
name = name + "_default",
|
||||
tags = tags,
|
||||
**kwargs
|
||||
)
|
||||
for arch in ["aarch64", "x86_64"]:
|
||||
native.config_setting(
|
||||
name = name + "_macos_" + arch,
|
||||
constraint_values = ["@platforms//os:macos", "@platforms//cpu:" + arch],
|
||||
)
|
||||
configure_make_variant(
|
||||
name = name + "_native_macos_" + arch,
|
||||
exec_compatible_with = ["@platforms//os:macos", "@platforms//cpu:" + arch],
|
||||
tags = tags + ["no-remote-exec"],
|
||||
**kwargs
|
||||
)
|
||||
native.alias(
|
||||
name = name,
|
||||
tags = tags,
|
||||
actual = select({
|
||||
":" + name + "_macos_aarch64": ":" + name + "_native_macos_aarch64",
|
||||
":" + name + "_macos_x86_64": ":" + name + "_native_macos_x86_64",
|
||||
"//conditions:default": ":" + name + "_default",
|
||||
}),
|
||||
visibility = kwargs.get("visibility"),
|
||||
)
|
||||
129
third_party/voice/prepare_built_runtime.py
vendored
Normal file
129
third_party/voice/prepare_built_runtime.py
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
"""Prepare an inspected build output using the existing platform runtime policy.
|
||||
|
||||
Receipts describe the declared build inputs and inspection, not authenticity or
|
||||
approval. The current build commit comes from Bazel's workspace status file.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import importlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from runtime import digest
|
||||
from sdk import export_sdk
|
||||
|
||||
|
||||
def prepare_built(prefix, build_receipt, status, target, output, *, sdk_output=None):
|
||||
prefix = prefix.resolve(strict=True)
|
||||
if build_receipt.stat().st_size > 1024 * 1024 or status.stat().st_size > 65536:
|
||||
raise ValueError("native build metadata exceeds limits")
|
||||
build = json.loads(build_receipt.read_text())
|
||||
commits = [
|
||||
line.removeprefix("STABLE_GIT_COMMIT ")
|
||||
for line in status.read_text().splitlines()
|
||||
if line.startswith("STABLE_GIT_COMMIT ")
|
||||
]
|
||||
manifest_hash = digest(Path(__file__).with_name("sources.json"))
|
||||
steps = build.get("steps", [])
|
||||
if (
|
||||
len(commits) != 1
|
||||
or not re.fullmatch(r"[0-9a-f]{40}", commits[0])
|
||||
or build.get("target") != target
|
||||
or build.get("manifest_sha256") != manifest_hash
|
||||
or not 1 <= len(steps) <= 128
|
||||
or any(step.get("exit_code") != 0 for step in steps)
|
||||
or steps[-1].get("name") != "gst-plugins-good-install"
|
||||
):
|
||||
raise ValueError("native build receipt is incomplete or mismatched")
|
||||
suffix = target.partition("-")[2]
|
||||
modules = {
|
||||
"apple-darwin": "macos_runtime",
|
||||
"unknown-linux-gnu": "linux_runtime",
|
||||
"pc-windows-msvc": "windows_runtime",
|
||||
}
|
||||
if suffix not in modules or target.partition("-")[0] not in ("aarch64", "x86_64"):
|
||||
raise ValueError("unsupported native runtime target")
|
||||
platform = importlib.import_module(modules[suffix])
|
||||
records = []
|
||||
for path in sorted(prefix.rglob("*")):
|
||||
if not re.fullmatch(r".+\.(?:dylib|dll|so(?:\.[0-9]+)*)", path.name):
|
||||
continue
|
||||
if path.is_symlink():
|
||||
if not path.resolve(strict=True).is_relative_to(prefix):
|
||||
raise ValueError("native library link escapes its prefix")
|
||||
continue
|
||||
if not path.is_file():
|
||||
continue
|
||||
if len(records) >= 128:
|
||||
raise ValueError("native inventory exceeds limits")
|
||||
platform.inspect(path, target)
|
||||
records.append(
|
||||
{
|
||||
"path": path.relative_to(prefix).as_posix(),
|
||||
"target": target,
|
||||
"sha256": digest(path),
|
||||
}
|
||||
)
|
||||
if not records:
|
||||
raise ValueError("native prefix contains no libraries")
|
||||
with tempfile.TemporaryDirectory(prefix="voice-receipts-") as temporary:
|
||||
receipts = Path(temporary)
|
||||
(receipts / "inspection").mkdir()
|
||||
(receipts / "inspection/binaries.json").write_text(json.dumps(records))
|
||||
(receipts / "ci.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"commit": commits[0],
|
||||
"target": target,
|
||||
"manifest_sha256": manifest_hash,
|
||||
"build_complete": True,
|
||||
"inspection_complete": True,
|
||||
}
|
||||
)
|
||||
)
|
||||
platform.project(prefix, receipts, target, output)
|
||||
if sdk_output is not None:
|
||||
export_sdk(prefix, receipts, target, sdk_output)
|
||||
|
||||
|
||||
def prepare_archive(archive, build_receipt, status, target, output, *, sdk_output=None):
|
||||
# Archives preserve native aliases through Bazel's cache and sandbox links.
|
||||
with tempfile.TemporaryDirectory(prefix="voice-prefix-") as temporary:
|
||||
prefix = Path(temporary)
|
||||
with tarfile.open(archive) as source:
|
||||
source.extractall(prefix, filter="data")
|
||||
prepare_built(
|
||||
prefix, build_receipt, status, target, output, sdk_output=sdk_output
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
for name in ("prefix", "build-receipt", "status", "output"):
|
||||
parser.add_argument("--" + name, type=Path, required=True)
|
||||
parser.add_argument("--target", required=True)
|
||||
parser.add_argument("--sdk-output", type=Path)
|
||||
args = parser.parse_args()
|
||||
# Executors may leave the TreeArtifact absent or create an empty directory.
|
||||
try:
|
||||
args.output.rmdir()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
if args.sdk_output is not None:
|
||||
try:
|
||||
args.sdk_output.rmdir()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
prepare_archive(
|
||||
args.prefix,
|
||||
args.build_receipt,
|
||||
args.status,
|
||||
args.target,
|
||||
args.output,
|
||||
sdk_output=args.sdk_output,
|
||||
)
|
||||
130
third_party/voice/prepare_sources.py
vendored
Normal file
130
third_party/voice/prepare_sources.py
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Prepare pinned native voice sources offline; never execute archive contents."""
|
||||
|
||||
import argparse
|
||||
from dataclasses import dataclass
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path, PurePosixPath
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import tarfile
|
||||
|
||||
MANIFEST = Path(__file__).with_name("sources.json")
|
||||
MAX_ARCHIVE_BYTES = 64 * 1024 * 1024
|
||||
MAX_SOURCE_BYTES = 512 * 1024 * 1024
|
||||
MAX_MEMBERS = 100_000
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Source:
|
||||
name: str
|
||||
version: str
|
||||
role: str
|
||||
archive: str
|
||||
root: str
|
||||
url: str
|
||||
sha256: str
|
||||
provenance: str
|
||||
|
||||
|
||||
def load_sources(manifest: bytes) -> list[Source]:
|
||||
document = json.loads(manifest)
|
||||
if document["schema_version"] != 1:
|
||||
raise ValueError("Unsupported native source manifest version")
|
||||
sources = [Source(**entry) for entry in document["sources"]]
|
||||
seen = set()
|
||||
for source in sources:
|
||||
for field in (source.name, source.archive, source.root):
|
||||
if not re.fullmatch(r"[a-zA-Z0-9_-][a-zA-Z0-9_.-]*", field):
|
||||
raise ValueError(f"Invalid native source identifier: {field!r}")
|
||||
if not re.fullmatch(r"[0-9a-f]{64}", source.sha256):
|
||||
raise ValueError(f"Invalid SHA-256 for {source.name}")
|
||||
for kind, value in (
|
||||
("name", source.name),
|
||||
("archive", source.archive),
|
||||
("root", source.root),
|
||||
):
|
||||
key = (kind, value.casefold())
|
||||
if key in seen:
|
||||
raise ValueError(f"Duplicate native source {kind}: {value}")
|
||||
seen.add(key)
|
||||
if not sources:
|
||||
raise ValueError("Native source manifest is empty")
|
||||
return sources
|
||||
|
||||
|
||||
def extract_source(source: Source, archives: Path, destination: Path) -> None:
|
||||
# Use one immutable byte snapshot for both verification and extraction.
|
||||
with (archives / source.archive).open("rb") as archive:
|
||||
data = archive.read(MAX_ARCHIVE_BYTES + 1)
|
||||
if len(data) > MAX_ARCHIVE_BYTES:
|
||||
raise ValueError(f"Archive exceeds size limit: {source.name}")
|
||||
if hashlib.sha256(data).hexdigest() != source.sha256:
|
||||
raise ValueError(f"SHA-256 mismatch: {source.name}")
|
||||
with tarfile.open(fileobj=io.BytesIO(data)) as archive:
|
||||
members = []
|
||||
size = 0
|
||||
for member in archive:
|
||||
path = PurePosixPath(member.name)
|
||||
if path.parts[:1] != (source.root,) or ".." in path.parts:
|
||||
raise ValueError(f"Invalid archive path: {member.name!r}")
|
||||
size += member.size
|
||||
members.append(member)
|
||||
if size > MAX_SOURCE_BYTES or len(members) > MAX_MEMBERS:
|
||||
raise ValueError(f"Expanded source exceeds limits: {source.name}")
|
||||
if not members:
|
||||
raise ValueError(f"Empty source archive: {source.name}")
|
||||
# Bound Python's fallback copies when Windows cannot create archive links.
|
||||
links = sum(member.issym() or member.islnk() for member in members)
|
||||
if size + links * max(member.size for member in members) > MAX_SOURCE_BYTES:
|
||||
raise ValueError(f"Expanded source exceeds limits: {source.name}")
|
||||
archive.extractall(destination, members=members, filter="data")
|
||||
|
||||
|
||||
def prepare_sources(archives: Path, output: Path, manifest: bytes) -> None:
|
||||
sources = load_sources(manifest)
|
||||
# Claim a new directory exclusively; never reuse or overwrite an earlier build.
|
||||
output.mkdir()
|
||||
try:
|
||||
for source in sources:
|
||||
extract_source(source, archives, output)
|
||||
receipt = {
|
||||
"schema_version": 1,
|
||||
"manifest_sha256": hashlib.sha256(manifest).hexdigest(),
|
||||
"sources": {
|
||||
source.name: {"root": source.root, "sha256": source.sha256}
|
||||
for source in sources
|
||||
},
|
||||
}
|
||||
(output / "sources.json").write_bytes(manifest)
|
||||
# This is the completion marker; failures never leave a valid receipt.
|
||||
(output / "prepared.json").write_text(
|
||||
json.dumps(receipt, indent=2) + "\n", encoding="utf-8"
|
||||
)
|
||||
except BaseException:
|
||||
shutil.rmtree(output)
|
||||
raise
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
"--archives",
|
||||
required=True,
|
||||
type=Path,
|
||||
help="Directory containing the pinned archives",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output", required=True, type=Path, help="New directory for verified sources"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
if sys.version_info < (3, 12):
|
||||
parser.error("Native source preparation requires Python 3.12 or newer")
|
||||
prepare_sources(args.archives, args.output, MANIFEST.read_bytes())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
64
third_party/voice/release_runtime.py
vendored
Normal file
64
third_party/voice/release_runtime.py
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"""Stage verified voice libraries and seal their public-release receipt."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
from package_runtime import runtime_files
|
||||
from runtime import digest
|
||||
|
||||
|
||||
def stage(source: Path, destination: Path, target: str) -> None:
|
||||
if target not in {
|
||||
"aarch64-apple-darwin",
|
||||
"x86_64-apple-darwin",
|
||||
"aarch64-unknown-linux-gnu",
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"aarch64-pc-windows-msvc",
|
||||
"x86_64-pc-windows-msvc",
|
||||
}:
|
||||
raise ValueError("unsupported public release voice runtime target")
|
||||
source = source.resolve(strict=True)
|
||||
files = runtime_files(source, target)
|
||||
destination.mkdir()
|
||||
try:
|
||||
for relative, expected in files.items():
|
||||
copied = destination / relative
|
||||
copied.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(source / relative, copied)
|
||||
if digest(copied) != expected:
|
||||
raise ValueError("runtime changed while staging release inputs")
|
||||
except BaseException:
|
||||
shutil.rmtree(destination)
|
||||
raise
|
||||
|
||||
|
||||
def seal(root: Path, target: str) -> None:
|
||||
root = root.resolve(strict=True)
|
||||
manifest_path = root / "runtime.json"
|
||||
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
||||
if manifest.get("developmentOnly") is not True or manifest.get("target") != target:
|
||||
raise ValueError("expected an unsealed development receipt for this target")
|
||||
for record in manifest["libraries"]:
|
||||
record["sha256"] = digest(root / record["path"])
|
||||
manifest["developmentOnly"] = False
|
||||
manifest["distribution"] = "publicRelease"
|
||||
manifest_path.chmod(manifest_path.stat().st_mode | 0o200)
|
||||
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
||||
runtime_files(root, target, public_release=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("operation", choices=("stage", "seal"))
|
||||
parser.add_argument("--target", required=True)
|
||||
parser.add_argument("--source", type=Path)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
if args.operation == "stage":
|
||||
if args.source is None:
|
||||
parser.error("stage requires --source")
|
||||
stage(args.source, args.output, args.target)
|
||||
else:
|
||||
seal(args.output, args.target)
|
||||
80
third_party/voice/runtime.bzl
vendored
Normal file
80
third_party/voice/runtime.bzl
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
"""Prepare build-produced native libraries with the existing platform policy."""
|
||||
|
||||
load("@rules_python//python:py_runtime_info.bzl", "PyRuntimeInfo")
|
||||
load(":windows_native.bzl", "WindowsBuildToolsInfo")
|
||||
|
||||
def _native_runtime_impl(ctx):
|
||||
python = ctx.attr._python[PyRuntimeInfo]
|
||||
prefix = ctx.attr.prefix[DefaultInfo].files.to_list()[0]
|
||||
receipt = ctx.attr.prefix[OutputGroupInfo].receipt.to_list()[0]
|
||||
output = ctx.actions.declare_directory(ctx.label.name)
|
||||
sdk = ctx.actions.declare_directory(ctx.label.name + "_sdk")
|
||||
if ctx.attr.windows_tools:
|
||||
tools = ctx.attr.windows_tools[WindowsBuildToolsInfo]
|
||||
if tools.inputs["target"] != ctx.attr.target:
|
||||
fail("Windows runtime target must match its declared native tools")
|
||||
config = ctx.actions.declare_file(ctx.label.name + ".json")
|
||||
ctx.actions.write(config, json.encode({
|
||||
"inputs": tools.inputs,
|
||||
"manifest": tools.manifest.path,
|
||||
"installed_files": [file.path for file in tools.installed_files],
|
||||
"prefix": prefix.path,
|
||||
"receipt": receipt.path,
|
||||
"status": ctx.info_file.path,
|
||||
"output": output.path,
|
||||
"sdk": sdk.path,
|
||||
}))
|
||||
ctx.actions.run(
|
||||
executable = tools.python.interpreter,
|
||||
arguments = [ctx.file._windows_driver.path, "prepare", config.path],
|
||||
inputs = depset([config, prefix, receipt, ctx.info_file, ctx.file._driver, ctx.file._windows_driver] + ctx.files._preparers, transitive = [tools.files]),
|
||||
outputs = [output, sdk],
|
||||
env = tools.environment,
|
||||
execution_requirements = {"no-remote-exec": "1"},
|
||||
mnemonic = "VoiceWindowsRuntime",
|
||||
)
|
||||
return [DefaultInfo(files = depset([output])), OutputGroupInfo(sdk = depset([sdk]))]
|
||||
ctx.actions.run(
|
||||
executable = python.interpreter,
|
||||
arguments = [
|
||||
ctx.file._driver.path,
|
||||
"--prefix",
|
||||
prefix.path,
|
||||
"--build-receipt",
|
||||
receipt.path,
|
||||
"--status",
|
||||
ctx.info_file.path,
|
||||
"--target",
|
||||
ctx.attr.target,
|
||||
"--output",
|
||||
output.path,
|
||||
"--sdk-output",
|
||||
sdk.path,
|
||||
],
|
||||
inputs = depset(
|
||||
[prefix, receipt, ctx.info_file, ctx.file._driver, python.interpreter] + ctx.files._preparers,
|
||||
transitive = [python.files],
|
||||
),
|
||||
outputs = [output, sdk],
|
||||
env = {"PATH": "/usr/bin:/bin", "LC_ALL": "C"},
|
||||
execution_requirements = {"no-remote-exec": "1", "no-remote-cache": "1"} if ctx.attr.target.endswith("apple-darwin") else {},
|
||||
mnemonic = "VoiceNativeRuntime",
|
||||
progress_message = "Preparing private voice runtime for " + ctx.attr.target,
|
||||
)
|
||||
return [
|
||||
DefaultInfo(files = depset([output])),
|
||||
OutputGroupInfo(sdk = depset([sdk])),
|
||||
]
|
||||
|
||||
native_runtime = rule(
|
||||
implementation = _native_runtime_impl,
|
||||
attrs = {
|
||||
"prefix": attr.label(mandatory = True, allow_single_file = True),
|
||||
"target": attr.string(mandatory = True),
|
||||
"windows_tools": attr.label(cfg = "exec", providers = [WindowsBuildToolsInfo]),
|
||||
"_windows_driver": attr.label(default = "//third_party/voice:bazel_windows.py", allow_single_file = True),
|
||||
"_driver": attr.label(default = "//third_party/voice:prepare_built_runtime.py", allow_single_file = True),
|
||||
"_preparers": attr.label(default = "//third_party/voice:build_inputs"),
|
||||
"_python": attr.label(default = "@python_3_12//:py3_runtime", cfg = "exec"),
|
||||
},
|
||||
)
|
||||
200
third_party/voice/runtime.py
vendored
Normal file
200
third_party/voice/runtime.py
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
"""Prepare receipt-verified native libraries without changing their input trees."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
|
||||
PLUGINS = (
|
||||
"app",
|
||||
"audioconvert",
|
||||
"audioresample",
|
||||
"coreelements",
|
||||
"opus",
|
||||
"rtp",
|
||||
"rtpmanager",
|
||||
)
|
||||
|
||||
|
||||
def required_library_paths(target: str) -> tuple[str, ...]:
|
||||
"""Libraries needed by the bindings even when no selected plugin imports them."""
|
||||
if target.endswith("-apple-darwin"):
|
||||
return ("lib/libgio-2.0.0.dylib",)
|
||||
if target.endswith("-unknown-linux-gnu"):
|
||||
return ("lib/libgio-2.0.so.0",)
|
||||
if target.endswith("-pc-windows-msvc"):
|
||||
return ("bin/gio-2.0-0.dll",)
|
||||
raise ValueError("unsupported native runtime target")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Binary:
|
||||
identity: str
|
||||
imports: tuple[str, ...]
|
||||
rpaths: tuple[str, ...]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RuntimeFormat:
|
||||
"""Platform loader policy; inspect reads metadata, finalize_copy transforms or checks a verified copy."""
|
||||
|
||||
plugins: tuple[Path, ...]
|
||||
system_imports: frozenset[str]
|
||||
inspect: Callable
|
||||
finalize_copy: Callable
|
||||
library_dir: str = "lib"
|
||||
plugin_dir: str = "plugins"
|
||||
required_libraries: tuple[str, ...] = ()
|
||||
|
||||
|
||||
def digest(path):
|
||||
with path.open("rb") as source:
|
||||
return hashlib.file_digest(source, "sha256").hexdigest()
|
||||
|
||||
|
||||
def prepare(prefix, receipts, target, output, format):
|
||||
prefix, receipts = prefix.resolve(strict=True), receipts.resolve(strict=True)
|
||||
output = output.absolute()
|
||||
if (
|
||||
output.exists()
|
||||
or output.is_symlink()
|
||||
or any(
|
||||
parent.exists() and parent.samefile(source)
|
||||
for parent in output.resolve().parents
|
||||
for source in (prefix, receipts)
|
||||
)
|
||||
):
|
||||
raise ValueError("output must be fresh and outside the inputs")
|
||||
ci = json.loads((receipts / "ci.json").read_text())
|
||||
source_hash = digest(Path(__file__).with_name("sources.json"))
|
||||
if (
|
||||
ci.get("target") != target
|
||||
or ci.get("build_complete") is not True
|
||||
or ci.get("inspection_complete") is not True
|
||||
or ci.get("manifest_sha256") != source_hash
|
||||
or not re.fullmatch(r"[0-9a-f]{40}", ci.get("commit", ""))
|
||||
):
|
||||
raise ValueError(
|
||||
"native build receipt does not match the pinned source inputs and target"
|
||||
)
|
||||
inventory_path = receipts / "inspection/binaries.json"
|
||||
inventory = json.loads(inventory_path.read_text())
|
||||
if not 1 <= len(inventory) <= 128:
|
||||
raise ValueError("unexpected native inventory size")
|
||||
binaries, identities, destinations = {}, {}, {}
|
||||
for record in inventory:
|
||||
spelling = (
|
||||
record["path"].replace("\\", "/") if os.name == "nt" else record["path"]
|
||||
)
|
||||
relative = Path(spelling)
|
||||
if relative.anchor or ".." in relative.parts or relative.as_posix() != spelling:
|
||||
raise ValueError("native inventory path must be canonical and relative")
|
||||
path = prefix / relative
|
||||
if (
|
||||
path.is_symlink()
|
||||
or not path.is_file()
|
||||
or not path.resolve().is_relative_to(prefix)
|
||||
):
|
||||
raise ValueError(
|
||||
"native inventory entries must be regular files inside the prefix"
|
||||
)
|
||||
if record["target"] != target or digest(path) != record["sha256"]:
|
||||
raise ValueError(f"native input target/digest mismatch: {relative}")
|
||||
metadata = format.inspect(path, target)
|
||||
name = Path(metadata.identity).name
|
||||
if not re.fullmatch(r"[A-Za-z0-9_+.-]+", name):
|
||||
raise ValueError("invalid native library identity")
|
||||
if relative in format.plugins and name != relative.name:
|
||||
raise ValueError("explicit plugin identity must preserve its filename")
|
||||
if (
|
||||
metadata.identity in identities
|
||||
or metadata.identity in format.system_imports
|
||||
or relative in binaries
|
||||
):
|
||||
raise ValueError("duplicate or system native library identity")
|
||||
destination = (
|
||||
Path(
|
||||
format.plugin_dir if relative in format.plugins else format.library_dir
|
||||
)
|
||||
/ name
|
||||
)
|
||||
if any(
|
||||
destination.as_posix().casefold() == p.as_posix().casefold()
|
||||
for p in destinations.values()
|
||||
):
|
||||
raise ValueError("colliding runtime library filenames")
|
||||
binaries[relative] = (record, metadata)
|
||||
identities[metadata.identity] = relative
|
||||
destinations[relative] = destination
|
||||
libraries = {path.name: relative for relative, path in destinations.items()}
|
||||
if any(name not in libraries for name in format.required_libraries):
|
||||
raise ValueError("missing required native library")
|
||||
pending = [
|
||||
*format.plugins,
|
||||
*(libraries[name] for name in format.required_libraries),
|
||||
]
|
||||
selected = set()
|
||||
while pending:
|
||||
relative = pending.pop()
|
||||
if relative in selected:
|
||||
continue
|
||||
if relative not in binaries:
|
||||
raise ValueError(f"missing explicit plugin: {relative}")
|
||||
selected.add(relative)
|
||||
for dependency in binaries[relative][1].imports:
|
||||
if dependency in format.system_imports:
|
||||
continue
|
||||
if dependency not in identities:
|
||||
raise ValueError(f"undeclared native dependency: {dependency}")
|
||||
pending.append(identities[dependency])
|
||||
output.mkdir() # Only this exclusively created output may be removed on failure.
|
||||
try:
|
||||
records = []
|
||||
dependency_paths = {
|
||||
identity: output / destinations[path]
|
||||
for identity, path in identities.items()
|
||||
}
|
||||
for relative in sorted(selected):
|
||||
record, metadata = binaries[relative]
|
||||
destination = output / destinations[relative]
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(prefix / relative, destination)
|
||||
if (
|
||||
digest(destination) != record["sha256"]
|
||||
or format.inspect(destination, target) != metadata
|
||||
):
|
||||
raise ValueError("copied native input changed after verification")
|
||||
expected = format.finalize_copy(destination, metadata, dependency_paths)
|
||||
if format.inspect(destination, target) != expected:
|
||||
raise ValueError(
|
||||
"finalized loader commands did not match the private runtime layout"
|
||||
)
|
||||
records.append(
|
||||
{
|
||||
"path": destinations[relative].as_posix(),
|
||||
"sourcePath": relative.as_posix(),
|
||||
"sourceSha256": record["sha256"],
|
||||
"sha256": digest(destination),
|
||||
"imports": list(expected.imports),
|
||||
}
|
||||
)
|
||||
manifest = {
|
||||
"schemaVersion": 1,
|
||||
"developmentOnly": True,
|
||||
"target": target,
|
||||
"sourceCommit": ci["commit"],
|
||||
"sourceManifestSha256": source_hash,
|
||||
"inventorySha256": digest(inventory_path),
|
||||
"libraries": records,
|
||||
"plugins": [destinations[path].as_posix() for path in format.plugins],
|
||||
}
|
||||
(output / "runtime.json").write_text(
|
||||
json.dumps(manifest, indent=2) + "\n", encoding="utf-8"
|
||||
)
|
||||
except BaseException:
|
||||
shutil.rmtree(output)
|
||||
raise
|
||||
141
third_party/voice/sdk.py
vendored
Normal file
141
third_party/voice/sdk.py
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
"""Export development inputs from the same inspected build as the private runtime.
|
||||
|
||||
SDKs are build inputs, never installed user payloads. Their receipt records byte
|
||||
identity and provenance, not authenticity or approval. Native loader relocation
|
||||
and final helper linking remain the runtime preparer and consumer's jobs.
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from runtime import digest
|
||||
|
||||
MODULES = (
|
||||
"glib-2.0",
|
||||
"gobject-2.0",
|
||||
"gio-2.0",
|
||||
"gmodule-no-export-2.0",
|
||||
"gstreamer-1.0",
|
||||
"gstreamer-base-1.0",
|
||||
"gstreamer-app-1.0",
|
||||
"gstreamer-audio-1.0",
|
||||
"gstreamer-tag-1.0",
|
||||
)
|
||||
|
||||
|
||||
def export_sdk(prefix: Path, receipts: Path, target: str, output: Path):
|
||||
prefix, receipts = prefix.resolve(strict=True), receipts.resolve(strict=True)
|
||||
output = output.absolute()
|
||||
if (
|
||||
output.exists()
|
||||
or output.is_symlink()
|
||||
or any(output.resolve().is_relative_to(root) for root in (prefix, receipts))
|
||||
):
|
||||
raise ValueError("SDK output must be fresh and outside the inputs")
|
||||
if not re.fullmatch(
|
||||
r"(?:aarch64|x86_64)-(?:apple-darwin|unknown-linux-gnu|pc-windows-msvc)",
|
||||
target,
|
||||
):
|
||||
raise ValueError("unsupported SDK target")
|
||||
ci = json.loads((receipts / "ci.json").read_text())
|
||||
source_hash = digest(Path(__file__).with_name("sources.json"))
|
||||
if (
|
||||
ci.get("target") != target
|
||||
or ci.get("build_complete") is not True
|
||||
or ci.get("inspection_complete") is not True
|
||||
or ci.get("manifest_sha256") != source_hash
|
||||
or not re.fullmatch(r"[0-9a-f]{40}", ci.get("commit", ""))
|
||||
):
|
||||
raise ValueError("SDK build receipt does not match the sources and target")
|
||||
inventory = json.loads((receipts / "inspection/binaries.json").read_text())
|
||||
if not 1 <= len(inventory) <= 128:
|
||||
raise ValueError("unexpected native inventory size")
|
||||
binaries = {}
|
||||
for record in inventory:
|
||||
name = record["path"].replace("\\", "/")
|
||||
if not re.fullmatch(r"(?:lib(?:/gstreamer-1\.0)?|bin)/[A-Za-z0-9_+.-]+", name):
|
||||
raise ValueError("invalid native inventory path")
|
||||
path = prefix / name
|
||||
if (
|
||||
name in binaries
|
||||
or path.is_symlink()
|
||||
or not path.resolve(strict=True).is_relative_to(prefix)
|
||||
or record["target"] != target
|
||||
or digest(path) != record["sha256"]
|
||||
):
|
||||
raise ValueError("native SDK library does not match its receipt")
|
||||
binaries[name] = record["sha256"]
|
||||
selected = []
|
||||
names = set()
|
||||
size = 0
|
||||
for path in sorted(prefix.rglob("*")):
|
||||
name = path.relative_to(prefix).as_posix()
|
||||
if path.is_dir():
|
||||
if path.is_symlink():
|
||||
raise ValueError("SDK input directories must not be links")
|
||||
continue
|
||||
if not (
|
||||
name.startswith("include/")
|
||||
or name == "lib/glib-2.0/include/glibconfig.h"
|
||||
or name
|
||||
in {
|
||||
f"lib/pkgconfig/{module}.pc"
|
||||
for module in (*MODULES, "libffi", "libpcre2-8", "zlib")
|
||||
}
|
||||
or re.fullmatch(
|
||||
r"lib/[A-Za-z0-9_+.-]+\.(?:a|lib|dylib|so(?:\.[0-9]+)*)", name
|
||||
)
|
||||
):
|
||||
continue
|
||||
source = path.resolve(strict=True)
|
||||
if not source.is_relative_to(prefix) or not source.is_file():
|
||||
raise ValueError("SDK inputs must be files inside the prefix")
|
||||
if name.casefold() in names:
|
||||
raise ValueError("SDK paths collide across platforms")
|
||||
names.add(name.casefold())
|
||||
size += source.stat().st_size
|
||||
if len(selected) >= 4096 or size > 512 * 1024 * 1024:
|
||||
raise ValueError("SDK inputs exceed the size limit")
|
||||
source_name = source.relative_to(prefix).as_posix()
|
||||
expected = digest(source)
|
||||
if re.search(r"\.(?:dylib|so(?:\.[0-9]+)*)$", name):
|
||||
if binaries.get(source_name) != expected:
|
||||
raise ValueError("SDK shared library is missing from the receipt")
|
||||
selected.append((name, source, expected))
|
||||
for module in MODULES:
|
||||
path = prefix / f"lib/pkgconfig/{module}.pc"
|
||||
if path.relative_to(prefix).as_posix().casefold() not in names or not re.search(
|
||||
r"^prefix=\$\{pcfiledir\}/\.\./\.\.$", path.read_text(), re.MULTILINE
|
||||
):
|
||||
raise ValueError("rebuild the SDK with relocatable Meson pkg-config files")
|
||||
if "lib/glib-2.0/include/glibconfig.h" not in names:
|
||||
raise ValueError("SDK is missing the target's GLib configuration header")
|
||||
output.mkdir()
|
||||
try:
|
||||
files = []
|
||||
for name, source, expected in selected:
|
||||
destination = output / name
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(source, destination)
|
||||
if digest(destination) != expected:
|
||||
raise ValueError("SDK input changed while copying")
|
||||
files.append({"path": name, "sha256": expected})
|
||||
(output / "sdk.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"target": target,
|
||||
"sourceCommit": ci["commit"],
|
||||
"sourceManifestSha256": source_hash,
|
||||
"files": files,
|
||||
},
|
||||
indent=2,
|
||||
)
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
except BaseException:
|
||||
shutil.rmtree(output)
|
||||
raise
|
||||
124
third_party/voice/sources.json
vendored
Normal file
124
third_party/voice/sources.json
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"sources": [
|
||||
{
|
||||
"name": "meson",
|
||||
"version": "1.12.0",
|
||||
"role": "build-tool",
|
||||
"archive": "meson-1.12.0.tar",
|
||||
"root": "meson-1.12.0",
|
||||
"url": "https://github.com/mesonbuild/meson/releases/download/1.12.0/meson-1.12.0.tar.gz",
|
||||
"sha256": "88afe0c20e52030218924ac37d0c81c59b4b5f3ae3752c8c6d7470c7d365886c",
|
||||
"provenance": "GitHub release asset digest"
|
||||
},
|
||||
{
|
||||
"name": "ninja",
|
||||
"version": "1.13.2",
|
||||
"role": "build-tool",
|
||||
"archive": "ninja-1.13.2.tar",
|
||||
"root": "ninja-3441b633c2fe2c494e958780ba0f4227b1327634",
|
||||
"url": "https://codeload.github.com/ninja-build/ninja/tar.gz/3441b633c2fe2c494e958780ba0f4227b1327634",
|
||||
"sha256": "bccc6197cd8c3ac2a439e26d6bf41506fe49c430cf3d593269a15379f24266ee",
|
||||
"provenance": "GitHub v1.13.2 tag -> commit3441b633c2fe2c494e958780ba0f4227b1327634; archive SHA recorded after fetch"
|
||||
},
|
||||
{
|
||||
"name": "libffi",
|
||||
"version": "3.8.0",
|
||||
"role": "native-library",
|
||||
"archive": "libffi-3.8.0.tar",
|
||||
"root": "libffi-3.8.0",
|
||||
"url": "https://github.com/libffi/libffi/releases/download/v3.8.0/libffi-3.8.0.tar.gz",
|
||||
"sha256": "7da3e2d9a171eb0a038f592ecad3ff2bb2550f3496d87b3b29ad0cf4430c0db4",
|
||||
"provenance": "GitHub release asset digest"
|
||||
},
|
||||
{
|
||||
"name": "pcre2",
|
||||
"version": "10.47",
|
||||
"role": "native-library",
|
||||
"archive": "pcre2-10.47.tar",
|
||||
"root": "pcre2-10.47",
|
||||
"url": "https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.47/pcre2-10.47.tar.gz",
|
||||
"sha256": "c08ae2388ef333e8403e670ad70c0a11f1eed021fd88308d7e02f596fcd9dc16",
|
||||
"provenance": "GitHub release asset digest"
|
||||
},
|
||||
{
|
||||
"name": "zlib",
|
||||
"version": "1.3.2",
|
||||
"role": "native-library",
|
||||
"archive": "zlib-1.3.2.tar",
|
||||
"root": "zlib-1.3.2",
|
||||
"url": "https://github.com/madler/zlib/releases/download/v1.3.2/zlib-1.3.2.tar.gz",
|
||||
"sha256": "bb329a0a2cd0274d05519d61c667c062e06990d72e125ee2dfa8de64f0119d16",
|
||||
"provenance": "GitHub release asset digest"
|
||||
},
|
||||
{
|
||||
"name": "opus",
|
||||
"version": "1.6.1",
|
||||
"role": "native-library",
|
||||
"archive": "opus-1.6.1.tar",
|
||||
"root": "opus-1.6.1",
|
||||
"url": "https://downloads.xiph.org/releases/opus/opus-1.6.1.tar.gz",
|
||||
"sha256": "6ffcb593207be92584df15b32466ed64bbec99109f007c82205f0194572411a1",
|
||||
"provenance": "https://downloads.xiph.org/releases/opus/SHA256SUMS.txt"
|
||||
},
|
||||
{
|
||||
"name": "glib",
|
||||
"version": "2.88.3",
|
||||
"role": "native-library",
|
||||
"archive": "glib-2.88.3.tar",
|
||||
"root": "glib-2.88.3",
|
||||
"url": "https://download.gnome.org/sources/glib/2.88/glib-2.88.3.tar.xz",
|
||||
"sha256": "ab24d24e698dfa1e408b7bcdb508f4aafc906185a8b8ce72fdf79bbbdc9b383b",
|
||||
"provenance": "https://download.gnome.org/sources/glib/2.88/glib-2.88.3.sha256sum"
|
||||
},
|
||||
{
|
||||
"name": "proxy-libintl",
|
||||
"version": "0.5",
|
||||
"role": "native-library",
|
||||
"archive": "proxy-libintl-0.5.tar",
|
||||
"root": "proxy-libintl-0.5",
|
||||
"url": "https://github.com/frida/proxy-libintl/archive/refs/tags/0.5.tar.gz",
|
||||
"sha256": "f7a1cbd7579baaf575c66f9d99fb6295e9b0684a28b095967cfda17857595303",
|
||||
"provenance": "GStreamer1.28.6 upstream wrap SHA; upstream tag commit33934de09af6a6627eb44e310a8079df009abdbb"
|
||||
},
|
||||
{
|
||||
"name": "gstreamer",
|
||||
"version": "1.28.6",
|
||||
"role": "native-library",
|
||||
"archive": "gstreamer-1.28.6.tar",
|
||||
"root": "gstreamer-1.28.6",
|
||||
"url": "https://gstreamer.freedesktop.org/src/gstreamer/gstreamer-1.28.6.tar.xz",
|
||||
"sha256": "62b6b9f0ad3147a6dd6420ac64a91180b14e990695bddd353b96041611d052ca",
|
||||
"provenance": "Official adjacent .sha256sum"
|
||||
},
|
||||
{
|
||||
"name": "gst-plugins-base",
|
||||
"version": "1.28.6",
|
||||
"role": "native-library",
|
||||
"archive": "gst-plugins-base-1.28.6.tar",
|
||||
"root": "gst-plugins-base-1.28.6",
|
||||
"url": "https://gstreamer.freedesktop.org/src/gst-plugins-base/gst-plugins-base-1.28.6.tar.xz",
|
||||
"sha256": "0ba699c7c6c66f4ba640be78cb38a24715add9683f3e3a199f5369dc5a4f04ac",
|
||||
"provenance": "Official adjacent .sha256sum"
|
||||
},
|
||||
{
|
||||
"name": "gst-plugins-good",
|
||||
"version": "1.28.6",
|
||||
"role": "native-library",
|
||||
"archive": "gst-plugins-good-1.28.6.tar",
|
||||
"root": "gst-plugins-good-1.28.6",
|
||||
"url": "https://gstreamer.freedesktop.org/src/gst-plugins-good/gst-plugins-good-1.28.6.tar.xz",
|
||||
"sha256": "b0c620a4b18b6ee931b4c43bbf1760d308666dc37f730a7e7f1ad327e59ce2df",
|
||||
"provenance": "Official adjacent .sha256sum"
|
||||
}
|
||||
],
|
||||
"bundled_sources": [
|
||||
{
|
||||
"name": "gvdb",
|
||||
"included_by": "glib",
|
||||
"revision": "2b42fc75f09dbe1cd1057580b5782b08f2dcb400",
|
||||
"path": "subprojects/gvdb",
|
||||
"provenance": "Included in the pinned GLib release archive; no separate fetch"
|
||||
}
|
||||
]
|
||||
}
|
||||
637
third_party/voice/test_assemble_package.py
vendored
Normal file
637
third_party/voice/test_assemble_package.py
vendored
Normal file
@@ -0,0 +1,637 @@
|
||||
"""Exercise private package copies, target pairing, provenance, and failure cleanup."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from assemble_package import assemble
|
||||
from package_runtime import runtime_files
|
||||
from release_runtime import seal
|
||||
from release_runtime import stage
|
||||
from runtime import PLUGINS, digest, required_library_paths
|
||||
|
||||
|
||||
class AssembleTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory(prefix="voice package ")
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.package = self.root / "app"
|
||||
(self.package / "bin").mkdir(parents=True)
|
||||
(self.package / "codex-resources").mkdir()
|
||||
(self.package / "codex-path").mkdir()
|
||||
self.commit = "a" * 40
|
||||
self.metadata = {
|
||||
"layoutVersion": 1,
|
||||
"version": f"0.0.0+{self.commit}",
|
||||
"target": "aarch64-unknown-linux-musl",
|
||||
"variant": "codex",
|
||||
"entrypoint": "bin/codex",
|
||||
"resourcesDir": "codex-resources",
|
||||
"pathDir": "codex-path",
|
||||
}
|
||||
(self.package / "codex-package.json").write_text(json.dumps(self.metadata))
|
||||
(self.package / "bin/codex").write_bytes(b"unchanged app")
|
||||
self.helper = self.root / "helper.exe"
|
||||
self.helper.write_bytes(b"private helper")
|
||||
self.helper.chmod(0o755)
|
||||
self.output = self.root / "installed copy"
|
||||
|
||||
def make_runtime(
|
||||
self, target="aarch64-unknown-linux-gnu", plugin="lib/gstreamer-1.0/libgst{}.so"
|
||||
):
|
||||
root = self.root / target
|
||||
root.mkdir()
|
||||
libraries = []
|
||||
for name in PLUGINS:
|
||||
path = root / plugin.format(name)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(f"prepared {name}".encode())
|
||||
libraries.append(
|
||||
{"path": path.relative_to(root).as_posix(), "sha256": digest(path)}
|
||||
)
|
||||
plugins = [record["path"] for record in libraries]
|
||||
for name in required_library_paths(target):
|
||||
path = root / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(b"prepared required library")
|
||||
libraries.append({"path": name, "sha256": digest(path)})
|
||||
manifest = {
|
||||
"schemaVersion": 1,
|
||||
"developmentOnly": True,
|
||||
"target": target,
|
||||
"sourceCommit": "b" * 40,
|
||||
"sourceManifestSha256": digest(Path(__file__).with_name("sources.json")),
|
||||
"plugins": plugins,
|
||||
"libraries": libraries,
|
||||
}
|
||||
(root / "runtime.json").write_text(json.dumps(manifest))
|
||||
return root, manifest
|
||||
|
||||
def test_cli_packages_each_runtime_layout_without_changing_bytes(self):
|
||||
for target, plugin in (
|
||||
("aarch64-unknown-linux-gnu", "lib/gstreamer-1.0/libgst{}.so"),
|
||||
("aarch64-apple-darwin", "plugins/libgst{}.dylib"),
|
||||
("aarch64-pc-windows-msvc", "bin/gst{}.dll"),
|
||||
):
|
||||
with self.subTest(target=target):
|
||||
runtime, receipt = self.make_runtime(target, plugin)
|
||||
(runtime / "unlisted-file").write_bytes(b"must not ship")
|
||||
windows = target.endswith("windows-msvc")
|
||||
entrypoint = "bin/codex.exe" if windows else "bin/codex"
|
||||
self.metadata.update(target=target, entrypoint=entrypoint)
|
||||
(self.package / entrypoint).write_bytes(b"unchanged app")
|
||||
(self.package / "codex-package.json").write_text(
|
||||
json.dumps(self.metadata)
|
||||
)
|
||||
output = self.root / (target + " packaged")
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(Path(__file__).with_name("assemble_package.py").resolve()),
|
||||
"--package",
|
||||
str(self.package),
|
||||
"--helper",
|
||||
str(self.helper),
|
||||
"--voice-target",
|
||||
target,
|
||||
"--build-commit",
|
||||
self.commit,
|
||||
"--output",
|
||||
str(output),
|
||||
"--runtime",
|
||||
str(runtime),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
cwd=self.root,
|
||||
env={**os.environ, "PYTHONSAFEPATH": "1"},
|
||||
)
|
||||
voice = output / "codex-resources/voice"
|
||||
self.assertFalse((voice / "unlisted-file").exists())
|
||||
expected = {r["path"]: r["sha256"] for r in receipt["libraries"]}
|
||||
expected["runtime.json"] = digest(runtime / "runtime.json")
|
||||
self.assertEqual(
|
||||
{name: digest(voice / name) for name in expected}, expected
|
||||
)
|
||||
self.assertEqual(
|
||||
{name: digest(runtime / name) for name in expected}, expected
|
||||
)
|
||||
manifest = json.loads((voice / "manifest.json").read_text())
|
||||
helper_name = "codex-voice-host.exe" if windows else "codex-voice-host"
|
||||
self.assertEqual(
|
||||
manifest["sha256"],
|
||||
{
|
||||
entrypoint: digest(self.package / entrypoint),
|
||||
f"codex-resources/voice/bin/{helper_name}": digest(self.helper),
|
||||
**{
|
||||
f"codex-resources/voice/{name}": value
|
||||
for name, value in expected.items()
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
def test_rejects_stale_runtime_without_gio_for_each_platform(self):
|
||||
for target, plugin, gio in (
|
||||
(
|
||||
"aarch64-unknown-linux-gnu",
|
||||
"lib/gstreamer-1.0/libgst{}.so",
|
||||
"lib/libgio-2.0.so.0",
|
||||
),
|
||||
(
|
||||
"aarch64-apple-darwin",
|
||||
"plugins/libgst{}.dylib",
|
||||
"lib/libgio-2.0.0.dylib",
|
||||
),
|
||||
("aarch64-pc-windows-msvc", "bin/gst{}.dll", "bin/gio-2.0-0.dll"),
|
||||
):
|
||||
with self.subTest(target=target):
|
||||
root, receipt = self.make_runtime(target, plugin)
|
||||
receipt["libraries"] = [
|
||||
r for r in receipt["libraries"] if r["path"] != gio
|
||||
]
|
||||
(root / gio).unlink()
|
||||
(root / "runtime.json").write_text(json.dumps(receipt))
|
||||
with self.assertRaisesRegex(ValueError, "required libraries"):
|
||||
runtime_files(root.resolve(), target)
|
||||
|
||||
def test_alpha_package_preserves_release_version_and_matching_build(self):
|
||||
self.commit = "b" * 40
|
||||
target = "aarch64-apple-darwin"
|
||||
runtime, _ = self.make_runtime(target, "plugins/libgst{}.dylib")
|
||||
staged = self.root / "staged"
|
||||
stage(runtime, staged, target)
|
||||
signed_library = staged / "lib/libgio-2.0.0.dylib"
|
||||
signed_library.write_bytes(signed_library.read_bytes() + b"signed")
|
||||
seal(staged, target)
|
||||
self.metadata["version"] = "0.154.0-alpha.8"
|
||||
self.metadata["target"] = target
|
||||
(self.package / "codex-package.json").write_text(json.dumps(self.metadata))
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
target,
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=staged,
|
||||
release_version="0.154.0-alpha.8",
|
||||
)
|
||||
manifest = json.loads(
|
||||
(self.output / "codex-resources/voice/manifest.json").read_text()
|
||||
)
|
||||
self.assertEqual(manifest["appVersion"], "0.154.0-alpha.8")
|
||||
self.assertEqual(manifest["buildCommit"], self.commit)
|
||||
notice_root = self.output / "codex-resources/voice"
|
||||
for source in (Path(__file__).with_name("licenses")).iterdir():
|
||||
relative = f"codex-resources/voice/licenses/{source.name}"
|
||||
self.assertEqual(
|
||||
(notice_root / "licenses" / source.name).read_bytes(),
|
||||
source.read_bytes(),
|
||||
)
|
||||
self.assertEqual(manifest["sha256"][relative], digest(source))
|
||||
self.assertEqual(
|
||||
(self.output / "codex-resources/voice/lib/libgio-2.0.0.dylib").read_bytes(),
|
||||
signed_library.read_bytes(),
|
||||
)
|
||||
|
||||
self.output.rename(self.root / "previous output")
|
||||
with self.assertRaisesRegex(ValueError, "package version"):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
target,
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=staged,
|
||||
release_version="0.154.0-alpha.7",
|
||||
)
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "runtime receipt"):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
target,
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=runtime,
|
||||
release_version="0.154.0-alpha.8",
|
||||
)
|
||||
|
||||
def test_alpha_receipt_requires_matching_signed_hashes(self):
|
||||
target = "x86_64-apple-darwin"
|
||||
runtime, _ = self.make_runtime(target, "plugins/libgst{}.dylib")
|
||||
secret = self.root / "outside-secret"
|
||||
secret.write_bytes(b"must not enter signing artifacts")
|
||||
(runtime / "unlisted-file").write_bytes(b"unlisted")
|
||||
try:
|
||||
(runtime / "unlisted-secret").symlink_to(secret)
|
||||
except OSError:
|
||||
# Windows runners may not grant symlink creation to this process.
|
||||
pass
|
||||
staged = self.root / "staged"
|
||||
stage(runtime, staged, target)
|
||||
self.assertFalse((staged / "unlisted-file").exists())
|
||||
self.assertFalse((staged / "unlisted-secret").exists())
|
||||
seal(staged, target)
|
||||
self.assertTrue(runtime_files(staged.resolve(), target, public_release=True))
|
||||
with self.assertRaisesRegex(ValueError, "runtime receipt"):
|
||||
runtime_files(staged.resolve(), target)
|
||||
(staged / "lib/libgio-2.0.0.dylib").write_bytes(b"tampered")
|
||||
with self.assertRaisesRegex(ValueError, "digest mismatch"):
|
||||
runtime_files(staged.resolve(), target, public_release=True)
|
||||
|
||||
def test_beta_and_stable_release_versions_package_the_same_runtime(self):
|
||||
self.commit = "b" * 40
|
||||
target = "aarch64-apple-darwin"
|
||||
runtime, _ = self.make_runtime(target, "plugins/libgst{}.dylib")
|
||||
staged = self.root / "staged"
|
||||
stage(runtime, staged, target)
|
||||
seal(staged, target)
|
||||
self.metadata["target"] = target
|
||||
for version in ("0.154.0-beta.2", "0.154.0"):
|
||||
with self.subTest(version=version):
|
||||
self.metadata["version"] = version
|
||||
(self.package / "codex-package.json").write_text(
|
||||
json.dumps(self.metadata)
|
||||
)
|
||||
output = self.root / f"package-{version}"
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
target,
|
||||
self.commit,
|
||||
output,
|
||||
runtime=staged,
|
||||
release_version=version,
|
||||
)
|
||||
manifest = json.loads(
|
||||
(output / "codex-resources/voice/manifest.json").read_text()
|
||||
)
|
||||
self.assertEqual(manifest["appVersion"], version)
|
||||
|
||||
def test_linux_release_pairs_musl_app_with_gnu_voice_runtime(self):
|
||||
self.commit = "b" * 40
|
||||
target = "aarch64-unknown-linux-gnu"
|
||||
runtime, _ = self.make_runtime(target)
|
||||
staged = self.root / "staged"
|
||||
stage(runtime, staged, target)
|
||||
seal(staged, target)
|
||||
for version in ("0.154.0-alpha.8", "0.154.0-beta.2", "0.154.0"):
|
||||
with self.subTest(version=version):
|
||||
self.metadata["version"] = version
|
||||
(self.package / "codex-package.json").write_text(
|
||||
json.dumps(self.metadata)
|
||||
)
|
||||
output = self.root / f"linux-{version}"
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
target,
|
||||
self.commit,
|
||||
output,
|
||||
runtime=staged,
|
||||
release_version=version,
|
||||
)
|
||||
voice = output / "codex-resources/voice"
|
||||
manifest = json.loads((voice / "manifest.json").read_text())
|
||||
self.assertEqual(manifest["appTarget"], "aarch64-unknown-linux-musl")
|
||||
self.assertEqual(manifest["voiceTarget"], target)
|
||||
self.assertEqual(
|
||||
manifest["sha256"]["codex-resources/voice/runtime.json"],
|
||||
digest(staged / "runtime.json"),
|
||||
)
|
||||
|
||||
def test_windows_release_packages_signed_receipt_and_exe_helper(self):
|
||||
self.commit = "b" * 40
|
||||
for target in ("x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc"):
|
||||
with self.subTest(target=target):
|
||||
runtime, _ = self.make_runtime(target, "bin/gst{}.dll")
|
||||
staged = self.root / f"signed-{target}"
|
||||
stage(runtime, staged, target)
|
||||
library = staged / "bin/gio-2.0-0.dll"
|
||||
library.write_bytes(library.read_bytes() + b"signed")
|
||||
seal(staged, target)
|
||||
self.metadata.update(
|
||||
target=target,
|
||||
entrypoint="bin/codex.exe",
|
||||
version="0.154.0-beta.2",
|
||||
)
|
||||
(self.package / "bin/codex.exe").write_bytes(b"unchanged app")
|
||||
(self.package / "codex-package.json").write_text(
|
||||
json.dumps(self.metadata)
|
||||
)
|
||||
output = self.root / f"windows-{target}"
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
target,
|
||||
self.commit,
|
||||
output,
|
||||
runtime=staged,
|
||||
release_version="0.154.0-beta.2",
|
||||
)
|
||||
voice = output / "codex-resources/voice"
|
||||
self.assertEqual(
|
||||
(voice / "bin/codex-voice-host.exe").read_bytes(),
|
||||
self.helper.read_bytes(),
|
||||
)
|
||||
self.assertEqual(
|
||||
(voice / "bin/gio-2.0-0.dll").read_bytes(), library.read_bytes()
|
||||
)
|
||||
self.assertTrue(
|
||||
runtime_files(voice.resolve(), target, public_release=True)
|
||||
)
|
||||
|
||||
def test_rejects_invalid_runtime_receipts_before_creating_package(self):
|
||||
runtime, original = self.make_runtime()
|
||||
changes = [
|
||||
{"target": "x86_64-unknown-linux-gnu"},
|
||||
{"developmentOnly": False},
|
||||
{"sourceManifestSha256": "0" * 64},
|
||||
{"sourceCommit": "dev"},
|
||||
{"plugins": original["plugins"][:-1]},
|
||||
{"libraries": []},
|
||||
{"libraries": original["libraries"] * 20},
|
||||
{"libraries": original["libraries"] + [original["libraries"][0]]},
|
||||
]
|
||||
for name in (
|
||||
"../outside.so",
|
||||
"lib/../outside.so",
|
||||
"bin/codex-voice-host",
|
||||
"lib/evil:stream.so",
|
||||
):
|
||||
changes.append({"libraries": [{**original["libraries"][0], "path": name}]})
|
||||
for change in changes:
|
||||
with self.subTest(change=change), self.assertRaises(ValueError):
|
||||
(runtime / "runtime.json").write_text(
|
||||
json.dumps({**original, **change})
|
||||
)
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
original["target"],
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_rejects_runtime_digest_changes_and_nested_output(self):
|
||||
runtime, receipt = self.make_runtime()
|
||||
nested = runtime / "new package"
|
||||
with self.assertRaisesRegex(ValueError, "outside the runtime"):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
receipt["target"],
|
||||
self.commit,
|
||||
nested,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertFalse(nested.exists())
|
||||
(runtime / receipt["plugins"][0]).write_bytes(b"changed")
|
||||
with self.assertRaisesRegex(ValueError, "digest mismatch"):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
receipt["target"],
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_rejects_runtime_inside_input_package(self):
|
||||
runtime, receipt = self.make_runtime()
|
||||
nested = self.package / "runtime-staging"
|
||||
runtime.rename(nested)
|
||||
(nested / "unlisted-file").write_bytes(b"must not ship")
|
||||
sources = [nested, self.package]
|
||||
alias = self.package.with_name("APP") / "runtime-staging"
|
||||
if alias.exists():
|
||||
sources.append(alias)
|
||||
for source in sources:
|
||||
with (
|
||||
self.subTest(source=source),
|
||||
self.assertRaisesRegex(ValueError, "outside the input package"),
|
||||
):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
receipt["target"],
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=source,
|
||||
)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_rejects_symlinked_runtime_library_directories(self):
|
||||
runtime, receipt = self.make_runtime()
|
||||
outside = self.root / "outside"
|
||||
(runtime / "lib/gstreamer-1.0").rename(outside)
|
||||
try:
|
||||
(runtime / "lib/gstreamer-1.0").symlink_to(
|
||||
outside, target_is_directory=True
|
||||
)
|
||||
except OSError as error:
|
||||
self.skipTest(f"symlink creation unavailable: {error}")
|
||||
with self.assertRaisesRegex(ValueError, "regular files"):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
receipt["target"],
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_copy_revalidation_removes_only_new_output(self):
|
||||
runtime, receipt = self.make_runtime()
|
||||
original_copy = shutil.copy2
|
||||
for changed_name in (receipt["plugins"][0], "runtime.json"):
|
||||
|
||||
def changed_copy(source, destination, **kwargs):
|
||||
result = original_copy(source, destination, **kwargs)
|
||||
if source == runtime.resolve() / changed_name:
|
||||
Path(destination).write_bytes(b"changed after validation")
|
||||
return result
|
||||
|
||||
with (
|
||||
self.subTest(changed_name=changed_name),
|
||||
patch("assemble_package.shutil.copy2", changed_copy),
|
||||
):
|
||||
with self.assertRaisesRegex(ValueError, "changed during copying"):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
receipt["target"],
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertFalse(self.output.exists())
|
||||
self.assertEqual(
|
||||
json.loads((runtime / "runtime.json").read_text()), receipt
|
||||
)
|
||||
self.assertEqual(
|
||||
(self.package / "bin/codex").read_bytes(), b"unchanged app"
|
||||
)
|
||||
|
||||
def test_copies_app_unchanged_and_records_distinct_linux_targets(self):
|
||||
runtime, receipt = self.make_runtime()
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
"aarch64-unknown-linux-gnu",
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertEqual((self.output / "bin/codex").read_bytes(), b"unchanged app")
|
||||
self.assertEqual((self.package / "bin/codex").read_bytes(), b"unchanged app")
|
||||
self.assertFalse((self.package / "codex-resources/voice").exists())
|
||||
self.assertEqual(
|
||||
(self.output / "codex-package.json").read_bytes(),
|
||||
(self.package / "codex-package.json").read_bytes(),
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads(
|
||||
(self.output / "codex-resources/voice/manifest.json").read_text()
|
||||
),
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"buildCommit": self.commit,
|
||||
"appTarget": self.metadata["target"],
|
||||
"voiceTarget": "aarch64-unknown-linux-gnu",
|
||||
"appVersion": self.metadata["version"],
|
||||
"sha256": {
|
||||
"bin/codex": hashlib.sha256(b"unchanged app").hexdigest(),
|
||||
"codex-resources/voice/bin/codex-voice-host": hashlib.sha256(
|
||||
b"private helper"
|
||||
).hexdigest(),
|
||||
**{
|
||||
f"codex-resources/voice/{r['path']}": r["sha256"]
|
||||
for r in receipt["libraries"]
|
||||
},
|
||||
"codex-resources/voice/runtime.json": digest(
|
||||
runtime / "runtime.json"
|
||||
),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
def test_rejects_incompatible_targets_and_unstamped_or_mixed_builds(self):
|
||||
runtime, _ = self.make_runtime()
|
||||
for target, commit in [
|
||||
("aarch64-unknown-linux-musl", self.commit),
|
||||
("x86_64-unknown-linux-gnu", self.commit),
|
||||
("aarch64-unknown-linux-gnu", "dev"),
|
||||
("aarch64-unknown-linux-gnu", "b" * 40),
|
||||
]:
|
||||
with (
|
||||
self.subTest(target=target, commit=commit),
|
||||
self.assertRaises(ValueError),
|
||||
):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
target,
|
||||
commit,
|
||||
self.output,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_assembles_matching_gnu_linux_app_and_helper_targets(self):
|
||||
for architecture in ("aarch64", "x86_64"):
|
||||
target = f"{architecture}-unknown-linux-gnu"
|
||||
with self.subTest(target=target):
|
||||
self.metadata["target"] = target
|
||||
(self.package / "codex-package.json").write_text(
|
||||
json.dumps(self.metadata)
|
||||
)
|
||||
runtime, receipt = self.make_runtime(target)
|
||||
output = self.root / (target + " packaged")
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
target,
|
||||
self.commit,
|
||||
output,
|
||||
runtime=runtime,
|
||||
)
|
||||
manifest = json.loads(
|
||||
(output / "codex-resources/voice/manifest.json").read_text()
|
||||
)
|
||||
self.assertEqual(
|
||||
manifest,
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"buildCommit": self.commit,
|
||||
"appTarget": target,
|
||||
"voiceTarget": target,
|
||||
"appVersion": self.metadata["version"],
|
||||
"sha256": {
|
||||
"bin/codex": hashlib.sha256(b"unchanged app").hexdigest(),
|
||||
"codex-resources/voice/bin/codex-voice-host": hashlib.sha256(
|
||||
b"private helper"
|
||||
).hexdigest(),
|
||||
**{
|
||||
f"codex-resources/voice/{r['path']}": r["sha256"]
|
||||
for r in receipt["libraries"]
|
||||
},
|
||||
"codex-resources/voice/runtime.json": digest(
|
||||
runtime / "runtime.json"
|
||||
),
|
||||
},
|
||||
},
|
||||
)
|
||||
self.assertEqual((output / "bin/codex").read_bytes(), b"unchanged app")
|
||||
self.assertEqual(
|
||||
(
|
||||
output / "codex-resources/voice/bin/codex-voice-host"
|
||||
).read_bytes(),
|
||||
self.helper.read_bytes(),
|
||||
)
|
||||
|
||||
def test_never_replaces_existing_or_nested_outputs(self):
|
||||
runtime, _ = self.make_runtime()
|
||||
for output in (self.package, self.package / "nested", self.helper):
|
||||
with self.subTest(output=output), self.assertRaises(ValueError):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
"aarch64-unknown-linux-gnu",
|
||||
self.commit,
|
||||
output,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertEqual(self.helper.read_bytes(), b"private helper")
|
||||
self.assertFalse((self.package / "nested").exists())
|
||||
|
||||
def test_cleans_only_its_new_copy_on_failure(self):
|
||||
runtime, _ = self.make_runtime()
|
||||
with patch("assemble_package.shutil.copy2", side_effect=OSError("copy failed")):
|
||||
with self.assertRaises(OSError):
|
||||
assemble(
|
||||
self.package,
|
||||
self.helper,
|
||||
"aarch64-unknown-linux-gnu",
|
||||
self.commit,
|
||||
self.output,
|
||||
runtime=runtime,
|
||||
)
|
||||
self.assertFalse(self.output.exists())
|
||||
self.assertEqual((self.package / "bin/codex").read_bytes(), b"unchanged app")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
213
third_party/voice/test_bazel_windows.py
vendored
Normal file
213
third_party/voice/test_bazel_windows.py
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
"""Exercise declared tool selection and the platform-independent payload copy action."""
|
||||
|
||||
import copy
|
||||
import errno
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import bazel_windows
|
||||
|
||||
from bazel_copy import copy_payloads
|
||||
from bazel_windows import selected_inputs
|
||||
|
||||
|
||||
class WindowsInputsTests(unittest.TestCase):
|
||||
def test_adapter_preserves_host_architecture_without_developer_path(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
config = Path(directory) / "action.json"
|
||||
config.write_text("{}")
|
||||
for architecture in ("AMD64", "ARM64"):
|
||||
environment = {"PROCESSOR_ARCHITECTURE": architecture, "PATH": "unsafe"}
|
||||
with (
|
||||
self.subTest(architecture=architecture),
|
||||
patch.object(
|
||||
bazel_windows, "os", SimpleNamespace(environ=environment)
|
||||
),
|
||||
patch.object(
|
||||
bazel_windows.sys, "argv", ["driver", "unknown", str(config)]
|
||||
),
|
||||
patch.object(
|
||||
bazel_windows,
|
||||
"selected_inputs",
|
||||
return_value={"target": "unused"},
|
||||
),
|
||||
patch.object(
|
||||
bazel_windows,
|
||||
"build_environment",
|
||||
return_value=({"PATH": "declared"}, {}),
|
||||
),
|
||||
):
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "unknown Windows native action"
|
||||
):
|
||||
bazel_windows.main()
|
||||
self.assertEqual(
|
||||
environment,
|
||||
{
|
||||
"PROCESSOR_ARCHITECTURE": architecture,
|
||||
"PATH": "declared",
|
||||
"HOME": environment["HOME"],
|
||||
"USERPROFILE": environment["HOME"],
|
||||
},
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.repository = self.root / "external/installed tools"
|
||||
self.names = {
|
||||
"shell": "cygwin/bin/bash.exe",
|
||||
"make": "cygwin/bin/make.exe",
|
||||
"cygpath": "cygwin/bin/cygpath.exe",
|
||||
"automake": "cygwin/bin/automake-1.18",
|
||||
"pkg_config": "pkgconf-image/PFiles64/pkgconf 3.0.6/pkgconf.exe",
|
||||
}
|
||||
for name in self.names.values():
|
||||
path = self.repository / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(b"synthetic declared executable")
|
||||
self.manifest = self.repository / "voice-tools.json"
|
||||
self.metadata = {
|
||||
"schemaVersion": 1,
|
||||
"target": "aarch64-pc-windows-msvc",
|
||||
"cygwinArchitecture": "x86_64",
|
||||
"tools": self.names,
|
||||
}
|
||||
self.manifest.write_text(json.dumps(self.metadata))
|
||||
self.config = {
|
||||
"inputs": {
|
||||
"schemaVersion": 1,
|
||||
"target": "aarch64-pc-windows-msvc",
|
||||
"systemRoot": "C:/Windows",
|
||||
"tools": {
|
||||
"cc": "external/msvc/cl.exe",
|
||||
"pkg_config": str(
|
||||
(self.repository / self.names["pkg_config"]).relative_to(
|
||||
self.root
|
||||
)
|
||||
),
|
||||
},
|
||||
"INCLUDE": ["external/sdk/include"],
|
||||
"LIB": ["external/sdk/lib"],
|
||||
},
|
||||
"manifest": str(self.manifest.relative_to(self.root)),
|
||||
"installed_files": [
|
||||
str((self.repository / name).relative_to(self.root))
|
||||
for name in self.names.values()
|
||||
],
|
||||
}
|
||||
|
||||
def test_paths_are_anchored_before_recipe_changes_directory(self):
|
||||
before = copy.deepcopy(self.config)
|
||||
expected = {
|
||||
**self.config["inputs"],
|
||||
"tools": {
|
||||
"cc": str(self.root / "external/msvc/cl.exe"),
|
||||
**{
|
||||
name: str(self.repository / path)
|
||||
for name, path in self.names.items()
|
||||
},
|
||||
},
|
||||
"INCLUDE": [str(self.root / "external/sdk/include")],
|
||||
"LIB": [str(self.root / "external/sdk/lib")],
|
||||
}
|
||||
self.assertEqual(selected_inputs(self.config, self.root), expected)
|
||||
self.assertEqual(self.config, before)
|
||||
|
||||
def test_manifest_cannot_select_a_file_omitted_from_action_inputs(self):
|
||||
self.config["installed_files"].pop()
|
||||
with self.assertRaisesRegex(ValueError, "selection differs: pkg_config"):
|
||||
selected_inputs(self.config, self.root)
|
||||
|
||||
def test_manifest_cannot_escape_installed_tree(self):
|
||||
outside = self.repository.parent / "outside.exe"
|
||||
outside.write_bytes(b"not part of the installed support tree")
|
||||
inside = self.repository / "cygwin/bin/other-bash.exe"
|
||||
try:
|
||||
inside.symlink_to(outside)
|
||||
except OSError as error:
|
||||
if error.errno not in (errno.EPERM, errno.EACCES):
|
||||
raise
|
||||
self.skipTest("creating symlinks requires OS permission")
|
||||
self.config["installed_files"].append(str(inside.relative_to(self.root)))
|
||||
self.metadata["tools"]["shell"] = str(inside.relative_to(self.repository))
|
||||
self.manifest.write_text(json.dumps(self.metadata))
|
||||
with self.assertRaisesRegex(ValueError, "selection differs: shell"):
|
||||
selected_inputs(self.config, self.root)
|
||||
|
||||
def test_manifest_cannot_replace_the_build_script_executable(self):
|
||||
alternative = self.repository / "pkgconf-image/another/pkgconf.exe"
|
||||
alternative.parent.mkdir(parents=True)
|
||||
alternative.write_bytes(b"different declared executable")
|
||||
self.config["installed_files"].append(str(alternative.relative_to(self.root)))
|
||||
self.metadata["tools"]["pkg_config"] = str(
|
||||
alternative.relative_to(self.repository)
|
||||
)
|
||||
self.manifest.write_text(json.dumps(self.metadata))
|
||||
with self.assertRaisesRegex(ValueError, "selection differs: pkg_config"):
|
||||
selected_inputs(self.config, self.root)
|
||||
|
||||
def test_wrong_target_or_emulation_contract_is_rejected(self):
|
||||
for key, value in (
|
||||
("target", "x86_64-pc-windows-msvc"),
|
||||
("cygwinArchitecture", "aarch64"),
|
||||
):
|
||||
with self.subTest(key=key):
|
||||
self.manifest.write_text(json.dumps({**self.metadata, key: value}))
|
||||
with self.assertRaisesRegex(ValueError, "selected target"):
|
||||
selected_inputs(self.config, self.root)
|
||||
|
||||
def test_missing_declared_executable_does_not_fall_back_to_path(self):
|
||||
(self.repository / self.names["shell"]).unlink()
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
selected_inputs(self.config, self.root)
|
||||
|
||||
|
||||
class LibraryCopiesTests(unittest.TestCase):
|
||||
def test_import_library_and_dll_bytes_remain_distinct(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
root = Path(temporary)
|
||||
dll = root / "source.dll"
|
||||
library = root / "source.lib"
|
||||
dll.write_bytes(b"DLL payload")
|
||||
library.write_bytes(b"import library payload")
|
||||
locator = root / "package/lib/search-path"
|
||||
copy_payloads(
|
||||
locator,
|
||||
[
|
||||
dll,
|
||||
root / "package/bin/audio.dll",
|
||||
library,
|
||||
root / "package/lib/audio.lib",
|
||||
],
|
||||
)
|
||||
self.assertTrue(locator.is_dir())
|
||||
self.assertEqual(
|
||||
{
|
||||
path.relative_to(root / "package").as_posix(): path.read_bytes()
|
||||
for path in (root / "package").rglob("*")
|
||||
if path.is_file()
|
||||
},
|
||||
{
|
||||
"bin/audio.dll": b"DLL payload",
|
||||
"lib/audio.lib": b"import library payload",
|
||||
},
|
||||
)
|
||||
|
||||
def test_missing_payload_fails_the_action(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
root = Path(temporary)
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
copy_payloads(
|
||||
root / "lib/search-path",
|
||||
[root / "missing.dll", root / "bin/audio.dll"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
568
third_party/voice/test_build_native.py
vendored
Normal file
568
third_party/voice/test_build_native.py
vendored
Normal file
@@ -0,0 +1,568 @@
|
||||
"""Check native build preconditions and subprocess failure propagation."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from build_native import NativeBuild, validate_target
|
||||
|
||||
|
||||
class NativeBuildTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
machine = platform.machine().lower()
|
||||
architecture = {"arm64": "aarch64", "amd64": "x86_64"}.get(machine, machine)
|
||||
suffix = {
|
||||
"Darwin": "apple-darwin",
|
||||
"Linux": "unknown-linux-gnu",
|
||||
"Windows": "pc-windows-msvc",
|
||||
}[platform.system()]
|
||||
self.args = SimpleNamespace(
|
||||
target=f"{architecture}-{suffix}",
|
||||
deployment_target="11.0",
|
||||
output=self.root / "build output",
|
||||
archives=self.root / "archives",
|
||||
cc=Path(sys.executable),
|
||||
cxx=Path(sys.executable),
|
||||
cmake=Path(sys.executable),
|
||||
make=Path(sys.executable),
|
||||
pkg_config=Path(sys.executable),
|
||||
shell=Path(sys.executable),
|
||||
bootstrap_make=None,
|
||||
jobs=2,
|
||||
)
|
||||
self.environment = {
|
||||
**os.environ,
|
||||
"INCLUDE": "fixture include",
|
||||
"LIB": "fixture lib",
|
||||
}
|
||||
|
||||
def test_cli_entrypoint_imports_its_sibling_with_safe_path_enabled(self):
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-P",
|
||||
str(Path(__file__).with_name("build_native.py")),
|
||||
"--help",
|
||||
],
|
||||
cwd=self.root,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("--archives", result.stdout)
|
||||
|
||||
def test_rejects_cross_host_and_musl_builds(self):
|
||||
for target, system, machine, libc in [
|
||||
("x86_64-pc-windows-msvc", "Darwin", "x86_64", ""),
|
||||
("aarch64-apple-darwin", "Darwin", "x86_64", ""),
|
||||
("x86_64-unknown-linux-gnu", "Linux", "x86_64", "musl"),
|
||||
("x86_64-unknown-linux-musl", "Linux", "x86_64", "musl"),
|
||||
]:
|
||||
with self.subTest(target=target, system=system):
|
||||
with self.assertRaises(ValueError):
|
||||
validate_target(target, system, machine, libc, "11.0")
|
||||
|
||||
def test_requires_explicit_macos_deployment_target(self):
|
||||
with self.assertRaisesRegex(ValueError, "Declare the macOS deployment target"):
|
||||
validate_target("aarch64-apple-darwin", "Darwin", "arm64", "", None)
|
||||
|
||||
def test_missing_tool_does_not_create_output(self):
|
||||
self.args.cc = self.root / "missing compiler"
|
||||
with self.assertRaisesRegex(ValueError, "Missing build tool"):
|
||||
NativeBuild(self.args, self.environment)
|
||||
self.assertFalse(self.args.output.exists())
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Exercises the Unix clang++ driver symlink")
|
||||
def test_bootstrap_links_cpp_runtime_through_compiler_symlink(self):
|
||||
tools = {name: shutil.which(name) for name in ("clang", "cmake", "make")}
|
||||
if not all(tools.values()):
|
||||
self.skipTest("Requires clang, CMake and make")
|
||||
compiler = self.root / "clang++"
|
||||
compiler.symlink_to(Path(tools["clang"]).resolve())
|
||||
self.args.cc = Path(tools["clang"])
|
||||
self.args.cxx = compiler
|
||||
self.args.cmake = Path(tools["cmake"])
|
||||
self.args.make = Path(tools["make"])
|
||||
headers = self.root / "declared headers"
|
||||
headers.mkdir()
|
||||
(headers / "build_flag.h").write_text(
|
||||
'#define BUILD_FLAG "linked with flags"\n'
|
||||
)
|
||||
self.args.cxx_flag = [f"-I{headers}"]
|
||||
for name in ("ar", "ranlib"):
|
||||
tool = shutil.which(name)
|
||||
if tool is None:
|
||||
self.skipTest(f"Requires {name}")
|
||||
wrapper = self.root / f"declared {name}"
|
||||
wrapper.write_text(
|
||||
"#!/bin/sh\n"
|
||||
f"touch {shlex.quote(str(self.root / (name + '.used')))}\n"
|
||||
f'exec {shlex.quote(tool)} "$@"\n'
|
||||
)
|
||||
wrapper.chmod(0o755)
|
||||
setattr(self.args, name, wrapper)
|
||||
source = self.root / "cpp-source"
|
||||
source.mkdir()
|
||||
(source / "CMakeLists.txt").write_text(
|
||||
"cmake_minimum_required(VERSION 3.15)\n"
|
||||
"project(cpp_driver LANGUAGES CXX)\n"
|
||||
"add_library(message STATIC message.cpp)\n"
|
||||
"add_executable(cpp_driver main.cpp)\n"
|
||||
"target_link_libraries(cpp_driver PRIVATE message)\n"
|
||||
"install(TARGETS cpp_driver DESTINATION bin)\n"
|
||||
)
|
||||
(source / "main.cpp").write_text(
|
||||
"#include <iostream>\nconst char* message();\nint main() { std::cout << message(); }\n"
|
||||
)
|
||||
(source / "message.cpp").write_text(
|
||||
'#include "build_flag.h"\nconst char* message() { return BUILD_FLAG; }\n'
|
||||
)
|
||||
build = NativeBuild(self.args, self.environment)
|
||||
build.output.mkdir()
|
||||
build.sources = {"cpp-driver": source}
|
||||
build.cmake("cpp-driver", [], bootstrap=True)
|
||||
result = subprocess.run(
|
||||
[build.tools / "bin" / "cpp_driver"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(result.stdout, "linked with flags")
|
||||
self.assertTrue(
|
||||
all((self.root / (name + ".used")).is_file() for name in ("ar", "ranlib"))
|
||||
)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Exercises Autoconf's Unix tool expansion")
|
||||
def test_libffi_rejects_quoted_archive_tool_paths(self):
|
||||
for name in ("ar", "ranlib"):
|
||||
for index, path in enumerate(("declared tool", "declared'tool")):
|
||||
with self.subTest(name=name, path=path):
|
||||
(self.root / path).touch()
|
||||
setattr(self.args, name, self.root / path)
|
||||
self.args.output = self.root / f"{name}-{index}"
|
||||
build = NativeBuild(self.args, self.environment)
|
||||
with (
|
||||
patch(
|
||||
"build_native.prepare_sources",
|
||||
side_effect=lambda *args: (build.output / "build").mkdir(),
|
||||
),
|
||||
patch.object(build, "cmake"),
|
||||
patch.object(build, "meson"),
|
||||
patch.object(build, "run"),
|
||||
self.assertRaisesRegex(ValueError, "libffi .* path"),
|
||||
):
|
||||
build.build()
|
||||
setattr(self.args, name, None)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Exercises Autoconf's Unix flag expansion")
|
||||
def test_libffi_compiler_receives_literal_defines_without_shell_quotes(self):
|
||||
compiler = shutil.which("cc")
|
||||
if compiler is None:
|
||||
self.skipTest("Requires a C compiler")
|
||||
self.args.cc = Path(compiler)
|
||||
make = shutil.which("make")
|
||||
if make is None:
|
||||
self.skipTest("Requires Make")
|
||||
for index, (flag, expected) in enumerate(
|
||||
[
|
||||
('-DBUILD_FLAG="redacted"', "redacted\n"),
|
||||
(r'-DBUILD_FLAG="C:\\voice"', "C:\\voice\n"),
|
||||
('-DBUILD_FLAG="two words"', None),
|
||||
]
|
||||
):
|
||||
with self.subTest(flag=flag):
|
||||
self.args.c_flag = [flag]
|
||||
self.args.output = self.root / str(index)
|
||||
build = NativeBuild(self.args, self.environment)
|
||||
with (
|
||||
patch(
|
||||
"build_native.prepare_sources",
|
||||
side_effect=lambda *args: (build.output / "build").mkdir(),
|
||||
),
|
||||
patch.object(build, "cmake"),
|
||||
patch.object(build, "meson"),
|
||||
patch.object(build, "run") as run,
|
||||
):
|
||||
if " " in flag:
|
||||
with self.assertRaisesRegex(ValueError, "libffi flags"):
|
||||
build.build()
|
||||
continue
|
||||
build.build()
|
||||
environment = next(
|
||||
call.kwargs["environment"]
|
||||
for call in run.call_args_list
|
||||
if call.args[0] == "libffi-configure"
|
||||
)
|
||||
(build.output / "probe.c").write_text(
|
||||
"#include <stdio.h>\nint main(void) { puts(BUILD_FLAG); }\n"
|
||||
)
|
||||
subprocess.run(
|
||||
["/bin/sh", "-c", "$CC $CFLAGS probe.c -o probe"],
|
||||
cwd=build.output,
|
||||
env=environment,
|
||||
check=True,
|
||||
)
|
||||
result = subprocess.run(
|
||||
[build.output / "probe"], check=True, capture_output=True, text=True
|
||||
)
|
||||
self.assertEqual(result.stdout, expected)
|
||||
(build.output / "Makefile").write_text(
|
||||
f"CC={compiler}\nCFLAGS={environment['CFLAGS']} -fexceptions\n"
|
||||
"MAKEOVERRIDES=\nall:\n\t$(MAKE) nested\n"
|
||||
"nested:\n\t$(CC) $(CFLAGS) probe.c -o probe\n\t./probe\n"
|
||||
)
|
||||
result = subprocess.run(
|
||||
[make, "--silent"],
|
||||
cwd=build.output,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(result.stdout, expected)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Unix install paths; Windows layout is unchanged")
|
||||
def test_cmake_installs_relative_library_paths(self):
|
||||
for argument, tool in (
|
||||
("cc", "cc"),
|
||||
("cxx", "c++"),
|
||||
("cmake", "cmake"),
|
||||
("make", "make"),
|
||||
):
|
||||
setattr(self.args, argument, Path(shutil.which(tool)))
|
||||
source = self.root / "library-source"
|
||||
source.mkdir()
|
||||
self.args.c_flag = ["-DBUILD_FLAG=42"]
|
||||
self.args.link_flag = ["-Wl,-rpath,declared-relative-path"]
|
||||
(source / "CMakeLists.txt").write_text(
|
||||
"cmake_minimum_required(VERSION 3.15)\nproject(relative_paths LANGUAGES C)\n"
|
||||
"add_library(fixture SHARED fixture.c)\ninstall(TARGETS fixture DESTINATION lib)\n"
|
||||
)
|
||||
(source / "fixture.c").write_text("int fixture(void) { return BUILD_FLAG; }\n")
|
||||
build = NativeBuild(self.args, self.environment)
|
||||
build.output.mkdir()
|
||||
build.sources = {"fixture": source}
|
||||
build.cmake("fixture", [], bootstrap=True)
|
||||
if sys.platform == "darwin":
|
||||
from macos_runtime import inspect
|
||||
|
||||
metadata = inspect(build.tools / "lib/libfixture.dylib", self.args.target)
|
||||
self.assertEqual(
|
||||
(metadata.identity, metadata.rpaths),
|
||||
("@rpath/libfixture.dylib", ("declared-relative-path", "@loader_path")),
|
||||
)
|
||||
else:
|
||||
from linux_runtime import inspect
|
||||
|
||||
metadata = inspect(build.tools / "lib/libfixture.so", self.args.target)
|
||||
self.assertEqual(
|
||||
(metadata.identity, metadata.rpaths),
|
||||
("libfixture.so", ("29=declared-relative-path:$ORIGIN",)),
|
||||
)
|
||||
|
||||
def test_build_refuses_existing_output_before_reading_sources(self):
|
||||
self.args.output.mkdir()
|
||||
(self.args.output / "keep").write_text("untouched")
|
||||
with self.assertRaises(FileExistsError):
|
||||
NativeBuild(self.args, self.environment).build()
|
||||
self.assertEqual(
|
||||
{p.name: p.read_text() for p in self.args.output.iterdir()},
|
||||
{"keep": "untouched"},
|
||||
)
|
||||
|
||||
def test_failure_retains_log_and_state_without_completion_marker(self):
|
||||
build = NativeBuild(self.args, self.environment)
|
||||
build.output.mkdir()
|
||||
command = [
|
||||
sys.executable,
|
||||
"-c",
|
||||
"print('synthetic failure'); raise SystemExit(23)",
|
||||
]
|
||||
with self.assertRaises(subprocess.CalledProcessError) as error:
|
||||
build.run("failure", command)
|
||||
self.assertEqual(error.exception.returncode, 23)
|
||||
self.assertEqual(
|
||||
(build.output / "failure.log").read_text().strip(), "synthetic failure"
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads((build.output / "build-state.json").read_text()),
|
||||
{
|
||||
"target": self.args.target,
|
||||
"deployment_target": "11.0",
|
||||
"flags": {"CFLAGS": [], "CXXFLAGS": [], "LDFLAGS": []},
|
||||
"steps": [{"name": "failure", "command": command, "exit_code": 23}],
|
||||
},
|
||||
)
|
||||
self.assertFalse((build.output / "built.json").exists())
|
||||
|
||||
def test_ambient_native_discovery_variables_are_not_inherited(self):
|
||||
inherited = {
|
||||
**self.environment,
|
||||
"PKG_CONFIG_PATH": "/ambient",
|
||||
"CMAKE_PREFIX_PATH": "/ambient",
|
||||
"CPATH": "/ambient",
|
||||
"CFLAGS": "-I/ambient",
|
||||
"LDFLAGS": "-L/ambient",
|
||||
}
|
||||
environment = NativeBuild(self.args, inherited).environment
|
||||
self.assertFalse(any("/ambient" in value for value in environment.values()))
|
||||
self.assertEqual(environment["PKG_CONFIG_PATH"], "")
|
||||
|
||||
def test_meson_receives_private_link_inputs_with_spaces(self):
|
||||
if platform.system() == "Darwin":
|
||||
self.args.cc = Path(shutil.which("cc"))
|
||||
self.args.c_flag = [] if os.name == "nt" else ["-DDECLARED_C=1"]
|
||||
self.args.cxx_flag = [] if os.name == "nt" else ["-DDECLARED_CXX=1"]
|
||||
self.args.link_flag = (
|
||||
[] if os.name == "nt" else ["-Ldeclared input with spaces"]
|
||||
)
|
||||
build = NativeBuild(self.args, self.environment)
|
||||
self.assertEqual(
|
||||
build.record["flags"],
|
||||
{
|
||||
"CFLAGS": self.args.c_flag,
|
||||
"CXXFLAGS": self.args.cxx_flag,
|
||||
"LDFLAGS": self.args.link_flag,
|
||||
},
|
||||
)
|
||||
build.sources = {"meson": self.root / "meson", "glib": self.root / "glib"}
|
||||
with patch.object(build, "run"):
|
||||
build.meson("glib", [])
|
||||
if platform.system() == "Darwin":
|
||||
subprocess.run(
|
||||
[
|
||||
build.environment["OBJC"],
|
||||
*shlex.split(build.environment["OBJCFLAGS"]),
|
||||
"-x",
|
||||
"objective-c",
|
||||
"-fsyntax-only",
|
||||
"-",
|
||||
],
|
||||
input="#if DECLARED_C != 1\n#error missing declared flags\n#endif\n",
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
quote = subprocess.list2cmdline if build.windows else shlex.join
|
||||
include = f"{'/I' if build.windows else '-I'}{build.prefix / 'include'}"
|
||||
self.assertEqual(
|
||||
{name: build.environment[name] for name in ("CFLAGS", "CXXFLAGS")},
|
||||
{
|
||||
"CFLAGS": quote([*self.args.c_flag, include]),
|
||||
"CXXFLAGS": quote([*self.args.cxx_flag, include]),
|
||||
},
|
||||
)
|
||||
if build.windows:
|
||||
self.assertEqual(
|
||||
build.environment["LDFLAGS"],
|
||||
quote([*self.args.link_flag, f"/LIBPATH:{build.prefix / 'lib'}"]),
|
||||
)
|
||||
else:
|
||||
self.assertEqual(
|
||||
shlex.split(build.environment["LDFLAGS"]),
|
||||
[
|
||||
*self.args.link_flag,
|
||||
f"-L{build.prefix / 'lib'}",
|
||||
(
|
||||
"-Wl,-rpath,$ORIGIN:$ORIGIN/.."
|
||||
if build.args.target.endswith("unknown-linux-gnu")
|
||||
else f"-Wl,-rpath,{build.prefix / 'lib'}"
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_windows_paths_use_cygpath_and_propagate_failure(self):
|
||||
build = NativeBuild(self.args, self.environment)
|
||||
build.windows = True
|
||||
path = Path("D:/build output/source")
|
||||
with patch(
|
||||
"build_native.subprocess.check_output",
|
||||
return_value="/cygdrive/d/build output/source\n",
|
||||
) as convert:
|
||||
self.assertEqual(build.posix_path(path), "/cygdrive/d/build output/source")
|
||||
self.assertEqual(
|
||||
convert.call_args.args[0],
|
||||
[build.toolchain["shell"].with_name("cygpath.exe"), "-u", str(path)],
|
||||
)
|
||||
with patch(
|
||||
"build_native.subprocess.check_output",
|
||||
side_effect=subprocess.CalledProcessError(1, "cygpath"),
|
||||
):
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
build.posix_path(path)
|
||||
|
||||
def test_windows_rejects_unix_overrides_before_creating_output(self):
|
||||
self.args.target = "x86_64-pc-windows-msvc"
|
||||
for name, value in (
|
||||
("c_flag", [r"/IC:\SDK\include"]),
|
||||
("ranlib", Path(sys.executable)),
|
||||
):
|
||||
with patch("build_native.validate_target"):
|
||||
setattr(self.args, name, value)
|
||||
with self.assertRaisesRegex(ValueError, "Unix build host"):
|
||||
NativeBuild(self.args, self.environment)
|
||||
delattr(self.args, name)
|
||||
self.assertFalse(self.args.output.exists())
|
||||
|
||||
def test_windows_recipes_use_explicit_targets_and_posix_paths(self):
|
||||
self.environment["USERPROFILE"] = str(self.root / "user profile")
|
||||
for architecture, flag in (("x86_64", "-m64"), ("aarch64", "-marm64")):
|
||||
with self.subTest(architecture=architecture):
|
||||
self.args.target = f"{architecture}-pc-windows-msvc"
|
||||
self.args.output = self.root / architecture
|
||||
with (
|
||||
patch("build_native.platform.system", return_value="Windows"),
|
||||
patch("build_native.platform.machine", return_value=architecture),
|
||||
):
|
||||
build = NativeBuild(self.args, self.environment)
|
||||
self.assertEqual(
|
||||
build.environment["USERPROFILE"], self.environment["USERPROFILE"]
|
||||
)
|
||||
calls = {}
|
||||
|
||||
def record(name, command, **kwargs):
|
||||
calls[name] = (command, kwargs)
|
||||
(build.output / f"{name}.log").write_text(
|
||||
"-ID:/private/include -LD:/private/lib -lffi\n"
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"build_native.prepare_sources",
|
||||
side_effect=lambda *args: (build.output / "build").mkdir(),
|
||||
),
|
||||
patch.object(build, "cmake") as cmake,
|
||||
patch.object(build, "meson"),
|
||||
patch.object(build, "run", side_effect=record),
|
||||
patch.object(
|
||||
build,
|
||||
"posix_path",
|
||||
side_effect=lambda path: "/cygdrive/d/" + path.name,
|
||||
),
|
||||
patch(
|
||||
"build_native.subprocess.check_output",
|
||||
return_value="/usr/share/automake-1.18\n",
|
||||
),
|
||||
):
|
||||
build.build()
|
||||
opus_options = next(
|
||||
call.args[1]
|
||||
for call in cmake.call_args_list
|
||||
if call.args[0] == "opus"
|
||||
)
|
||||
self.assertEqual(
|
||||
"-DOPUS_PRESUME_NEON=ON" in opus_options, architecture == "aarch64"
|
||||
)
|
||||
command, kwargs = calls["libffi-configure"]
|
||||
host = f"{architecture}-w64-mingw32"
|
||||
linker_flags = "-no-undefined -Wc,-link,/IMPLIB:.libs/libffi.lib"
|
||||
self.assertEqual(
|
||||
command,
|
||||
[
|
||||
build.toolchain["shell"],
|
||||
"/cygdrive/d/configure",
|
||||
"--prefix=/cygdrive/d/prefix",
|
||||
"--enable-shared",
|
||||
"--disable-static",
|
||||
"--disable-docs",
|
||||
f"--build={host}",
|
||||
f"--host={host}",
|
||||
],
|
||||
)
|
||||
expected = {
|
||||
**build.environment,
|
||||
"CC": f"/cygdrive/d/msvcc.sh {flag}",
|
||||
"CXX": f"/cygdrive/d/msvcc.sh {flag}",
|
||||
"AR": "/usr/share/automake-1.18/ar-lib lib",
|
||||
"RANLIB": ":",
|
||||
"LD": "link",
|
||||
"NM": "dumpbin -symbols",
|
||||
"STRIP": ":",
|
||||
"LDFLAGS": "-no-undefined",
|
||||
"AM_MAKEFLAGS": shlex.quote(f"LTLDFLAGS={linker_flags}"),
|
||||
"CPP": "cl -nologo -EP",
|
||||
"CXXCPP": "cl -nologo -EP",
|
||||
"CPPFLAGS": "-DFFI_BUILDING_DLL",
|
||||
"CONFIG_SHELL": "/cygdrive/d/" + build.toolchain["shell"].name,
|
||||
}
|
||||
self.assertEqual(
|
||||
kwargs,
|
||||
{"cwd": build.output / "build/libffi", "environment": expected},
|
||||
)
|
||||
self.assertEqual(calls["libffi-install"][1]["environment"], expected)
|
||||
if platform.system() == "Windows":
|
||||
cygwin = os.environ.get("VOICE_CYGWIN_ROOT")
|
||||
make = str(Path(cygwin) / "bin/make.exe") if cygwin else None
|
||||
else:
|
||||
make = shutil.which("make")
|
||||
if make is None:
|
||||
self.skipTest("GNU make is required for the recursive build check")
|
||||
# Mirror libffi's MAKEOVERRIDES reset and recursive hook, without
|
||||
# running a compiler or requiring the native source archives.
|
||||
directory = build.output / "build/libffi"
|
||||
(directory / "Makefile").write_text(
|
||||
"MAKEOVERRIDES =\nLTLDFLAGS = default\n"
|
||||
"all:\n\t@$(MAKE) --no-print-directory $(AM_MAKEFLAGS) nested\n"
|
||||
"nested:\n\t@$(MAKE) --no-print-directory $(AM_MAKEFLAGS) observe\n"
|
||||
"observe:\n\t@printf '%s\\n' \"$(LTLDFLAGS)\"\n"
|
||||
)
|
||||
result = subprocess.run(
|
||||
[make, "--no-print-directory"],
|
||||
cwd=directory,
|
||||
env={
|
||||
**os.environ,
|
||||
"AM_MAKEFLAGS": kwargs["environment"]["AM_MAKEFLAGS"],
|
||||
"PATH": os.pathsep.join(
|
||||
[str(Path(make).parent), os.environ.get("PATH", "")]
|
||||
),
|
||||
},
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
result.stdout.strip(),
|
||||
linker_flags,
|
||||
)
|
||||
|
||||
def test_explicit_windows_inputs_replace_ambient_sdk_and_search_paths(self):
|
||||
self.args.target = "x86_64-pc-windows-msvc"
|
||||
self.args.windows_build_inputs = self.root / "inputs.json"
|
||||
selected = {
|
||||
"PATH": str(self.root / "selected tools"),
|
||||
"INCLUDE": str(self.root / "selected include"),
|
||||
"LIB": str(self.root / "selected lib"),
|
||||
}
|
||||
with (
|
||||
patch("build_native.validate_target"),
|
||||
patch(
|
||||
"build_native.build_environment",
|
||||
return_value=(selected, {"target": self.args.target}),
|
||||
),
|
||||
):
|
||||
build = NativeBuild(
|
||||
self.args,
|
||||
{"PATH": "/unrelated", "LIBPATH": "/unrelated"},
|
||||
)
|
||||
self.assertFalse(
|
||||
any("/unrelated" in value for value in build.environment.values())
|
||||
)
|
||||
self.assertEqual(
|
||||
{name: build.environment[name] for name in ("INCLUDE", "LIB")},
|
||||
{name: selected[name] for name in ("INCLUDE", "LIB")},
|
||||
)
|
||||
self.assertEqual(
|
||||
build.record["windows_build_inputs"], {"target": self.args.target}
|
||||
)
|
||||
self.assertFalse(build.output.exists())
|
||||
158
third_party/voice/test_cargo_ci.py
vendored
Normal file
158
third_party/voice/test_cargo_ci.py
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
"""Exercise how full Cargo CI consumes prepared native inputs."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from cargo_ci import environment, main, stage
|
||||
from package_runtime import runtime_files
|
||||
from runtime import PLUGINS, digest, required_library_paths
|
||||
from sdk import MODULES
|
||||
|
||||
|
||||
def write_files(root, contents):
|
||||
records = []
|
||||
for name, data in contents.items():
|
||||
path = root / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(data)
|
||||
path.chmod(0o444) # Bazel materializes these inputs read-only.
|
||||
records.append({"path": name, "sha256": digest(path)})
|
||||
return records
|
||||
|
||||
|
||||
class CargoCiTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory(prefix="voice cargo ")
|
||||
self.addCleanup(temp.cleanup)
|
||||
self.root = Path(temp.name).resolve()
|
||||
self.sdk = self.root / "sdk"
|
||||
self.runtime = self.root / "runtime"
|
||||
self.output = self.root / "stage"
|
||||
self.commit = "a" * 40
|
||||
|
||||
def inputs(self, target, alias, plugin):
|
||||
canonical = required_library_paths(target)[0]
|
||||
plugins = [plugin.format(name) for name in PLUGINS]
|
||||
metadata = (
|
||||
"prefix=/producer\nName: {name}\nDescription: fixture\nVersion: 1.28\n"
|
||||
)
|
||||
sdk = {alias: b"original", "lib/glib-2.0/include/glibconfig.h": b"header"}
|
||||
for name in MODULES:
|
||||
sdk[f"lib/pkgconfig/{name}.pc"] = metadata.format(name=name).encode()
|
||||
if not target.endswith("msvc"):
|
||||
sdk[canonical] = sdk[alias]
|
||||
sdk_files = write_files(self.sdk, sdk)
|
||||
libraries = write_files(
|
||||
self.runtime, {name: b"prepared" for name in [canonical, *plugins]}
|
||||
)
|
||||
libraries[0]["sourceSha256"] = digest(self.sdk / alias)
|
||||
identity = dict(
|
||||
schemaVersion=1,
|
||||
target=target,
|
||||
sourceCommit=self.commit,
|
||||
sourceManifestSha256=digest(Path(__file__).with_name("sources.json")),
|
||||
)
|
||||
(self.sdk / "sdk.json").write_text(json.dumps(dict(identity, files=sdk_files)))
|
||||
receipt = dict(
|
||||
identity, developmentOnly=True, libraries=libraries, plugins=plugins
|
||||
)
|
||||
(self.runtime / "runtime.json").write_text(json.dumps(receipt))
|
||||
return canonical
|
||||
|
||||
def test_relocated_metadata_runtime_and_cargo_probe(self):
|
||||
target = "aarch64-apple-darwin"
|
||||
alias = "lib/libgio-2.0.dylib"
|
||||
canonical = self.inputs(target, alias, "plugins/libgst{}.dylib")
|
||||
stage(self.sdk, self.runtime, self.output, target, self.commit)
|
||||
moved = self.root / "moved native inputs"
|
||||
self.output.rename(moved)
|
||||
native = moved / "runtime"
|
||||
self.assertEqual(
|
||||
(native / alias).read_bytes(), (self.runtime / canonical).read_bytes()
|
||||
)
|
||||
self.assertEqual(
|
||||
runtime_files(native, target), runtime_files(self.runtime, target)
|
||||
)
|
||||
|
||||
host = (
|
||||
os.environ.get("VOICE_PKG_CONFIG")
|
||||
or shutil.which("pkg-config")
|
||||
or shutil.which("pkgconf")
|
||||
)
|
||||
if not host:
|
||||
self.skipTest("host pkg-config is required to probe relocated metadata")
|
||||
pkgdir = moved / "sdk/lib/pkgconfig"
|
||||
probe_env = dict(os.environ, PKG_CONFIG_PATH="", PKG_CONFIG_LIBDIR=str(pkgdir))
|
||||
result = subprocess.check_output(
|
||||
[host, "--variable=prefix", "gio-2.0"], env=probe_env, text=True
|
||||
)
|
||||
# pkgconf can escape spaces while pkg-config can print the raw path.
|
||||
raw = result.strip()
|
||||
words = shlex.split(raw)
|
||||
self.assertEqual(
|
||||
Path(words[0] if len(words) == 1 else raw).resolve(), moved / "sdk"
|
||||
)
|
||||
|
||||
env_file = self.root / "github env"
|
||||
ci_env = dict(
|
||||
GITHUB_SHA=self.commit, GITHUB_ENV=str(env_file), VOICE_PKG_CONFIG=host
|
||||
)
|
||||
argv = ["cargo_ci", "configure", "--root", str(moved), "--target", target]
|
||||
with patch.dict(os.environ, ci_env), patch.object(sys, "argv", argv):
|
||||
main()
|
||||
written = env_file.read_text()
|
||||
values = dict(line.split("=", 1) for line in written.splitlines())
|
||||
self.assertEqual(
|
||||
values["PKG_CONFIG_PATH_aarch64_apple_darwin"], str(pkgdir)
|
||||
)
|
||||
self.assertNotIn("PKG_CONFIG_LIBDIR_aarch64_apple_darwin", values)
|
||||
(pkgdir / "gio-2.0.pc").unlink()
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
main()
|
||||
self.assertEqual(env_file.read_text(), written)
|
||||
|
||||
def test_arm64_import_library_and_dll_with_x64_host_pkgconf(self):
|
||||
target = "aarch64-pc-windows-msvc"
|
||||
alias = "lib/gio-2.0.lib"
|
||||
canonical = self.inputs(target, alias, "bin/gst{}.dll")
|
||||
stage(self.sdk, self.runtime, self.output, target, self.commit)
|
||||
native = self.output / "runtime"
|
||||
self.assertEqual(
|
||||
(native / "bin/gio-2.0.lib").read_bytes(), (self.sdk / alias).read_bytes()
|
||||
)
|
||||
self.assertEqual(
|
||||
(native / canonical).read_bytes(), (self.runtime / canonical).read_bytes()
|
||||
)
|
||||
tool = self.root / "x64 pkgconf.exe"
|
||||
tool.touch()
|
||||
with patch.dict(os.environ, GITHUB_SHA=self.commit):
|
||||
values = environment(self.output, target, tool)
|
||||
self.assertEqual(values["PKG_CONFIG_aarch64_pc_windows_msvc"], str(tool))
|
||||
self.assertEqual(
|
||||
values["SYSTEM_DEPS_GSTREAMER_1_0_SEARCH_NATIVE"], str(native / "bin")
|
||||
)
|
||||
|
||||
def test_mismatched_receipt_and_corrupt_sdk_fail_staging(self):
|
||||
target = "x86_64-unknown-linux-gnu"
|
||||
alias = "lib/libgio-2.0.so"
|
||||
self.inputs(target, alias, "lib/gstreamer-1.0/libgst{}.so")
|
||||
for triple, commit in [
|
||||
(target, "b" * 40),
|
||||
("aarch64-unknown-linux-gnu", self.commit),
|
||||
]:
|
||||
with self.assertRaisesRegex(ValueError, "do not match"):
|
||||
stage(self.sdk, self.runtime, self.output, triple, commit)
|
||||
source = self.sdk / alias
|
||||
source.chmod(0o644)
|
||||
source.write_bytes(b"corrupt")
|
||||
with self.assertRaisesRegex(ValueError, "receipt"):
|
||||
stage(self.sdk, self.runtime, self.output, target, self.commit)
|
||||
self.assertFalse(self.output.exists())
|
||||
302
third_party/voice/test_linux_runtime.py
vendored
Normal file
302
third_party/voice/test_linux_runtime.py
vendored
Normal file
@@ -0,0 +1,302 @@
|
||||
"""Exercise real ELF relocation and rejection of unsafe native build inputs."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from linux_runtime import inspect, project
|
||||
from runtime import PLUGINS, digest
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "linux", "GNU Linux native runtime preparation")
|
||||
class RuntimeTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory(prefix="native voice ")
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.prefix, self.receipts, self.output = (
|
||||
self.root / name for name in ("input é", "receipts", "runtime")
|
||||
)
|
||||
self.target = (
|
||||
"aarch64" if platform.machine() == "aarch64" else "x86_64"
|
||||
) + "-unknown-linux-gnu"
|
||||
(self.prefix / "lib/gstreamer-1.0").mkdir(parents=True)
|
||||
(self.receipts / "inspection").mkdir(parents=True)
|
||||
source = self.root / "fixture.c"
|
||||
source.write_text("int voice_fixture(void) { return 42; }\n")
|
||||
self.library = self.prefix / "lib/libfixture.so.1.2"
|
||||
subprocess.run(
|
||||
[
|
||||
"cc",
|
||||
"-shared",
|
||||
"-fPIC",
|
||||
str(source),
|
||||
"-o",
|
||||
str(self.library),
|
||||
"-Wl,-soname,libfixture.so.1",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
source.write_text("int voice_gio_dependency(void) { return 84; }\n")
|
||||
gio_dependency = self.prefix / "lib/libgiofixture.so.1.2"
|
||||
subprocess.run(
|
||||
[
|
||||
"cc",
|
||||
"-shared",
|
||||
"-fPIC",
|
||||
str(source),
|
||||
"-o",
|
||||
str(gio_dependency),
|
||||
"-Wl,-soname,libgiofixture.so.1",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
source.write_text(
|
||||
"extern int voice_gio_dependency(void); "
|
||||
"int voice_gio_fixture(void) { return voice_gio_dependency(); }\n"
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
"cc",
|
||||
"-shared",
|
||||
"-fPIC",
|
||||
str(source),
|
||||
str(gio_dependency),
|
||||
"-Wl,-rpath,$ORIGIN",
|
||||
"-o",
|
||||
str(self.prefix / "lib/libgio-2.0.so.0.8800.3"),
|
||||
"-Wl,-soname,libgio-2.0.so.0",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
source.write_text(
|
||||
"extern int voice_fixture(void); int voice_plugin(void) { return voice_fixture(); }\n"
|
||||
)
|
||||
for name in PLUGINS:
|
||||
plugin = self.prefix / f"lib/gstreamer-1.0/libgst{name}.so"
|
||||
subprocess.run(
|
||||
[
|
||||
"cc",
|
||||
"-shared",
|
||||
"-fPIC",
|
||||
str(source),
|
||||
str(self.library),
|
||||
"-o",
|
||||
str(plugin),
|
||||
f"-Wl,-soname,{plugin.name}",
|
||||
"-Wl,-rpath,$ORIGIN:$ORIGIN/..",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
self.inventory_path = self.receipts / "inspection/binaries.json"
|
||||
self.inventory = [
|
||||
{
|
||||
"path": p.relative_to(self.prefix).as_posix(),
|
||||
"sha256": digest(p),
|
||||
"target": self.target,
|
||||
}
|
||||
for p in sorted(self.prefix.rglob("*.so*"))
|
||||
if p.is_file()
|
||||
]
|
||||
self.inventory_path.write_text(json.dumps(self.inventory))
|
||||
(self.receipts / "ci.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"commit": "a" * 40,
|
||||
"target": self.target,
|
||||
"build_complete": True,
|
||||
"inspection_complete": True,
|
||||
"manifest_sha256": digest(Path(__file__).with_name("sources.json")),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def test_relocated_libraries_load_without_original_prefix(self):
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(Path(__file__).with_name("linux_runtime.py").resolve()),
|
||||
"--prefix",
|
||||
str(self.prefix),
|
||||
"--receipts",
|
||||
str(self.receipts),
|
||||
"--target",
|
||||
self.target,
|
||||
"--output",
|
||||
str(self.output),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
cwd=self.root,
|
||||
env={**os.environ, "PYTHONSAFEPATH": "1"},
|
||||
)
|
||||
self.assertEqual(
|
||||
{r["path"]: digest(self.prefix / r["path"]) for r in self.inventory},
|
||||
{r["path"]: r["sha256"] for r in self.inventory},
|
||||
)
|
||||
moved = self.root / "moved runtime"
|
||||
self.output.rename(moved)
|
||||
shutil.rmtree(self.prefix)
|
||||
environment = {k: v for k, v in os.environ.items() if not k.startswith("LD_")}
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-c",
|
||||
"import ctypes,json,pathlib,sys; root=pathlib.Path(sys.argv[1]); "
|
||||
"manifest=json.loads((root/'runtime.json').read_text()); "
|
||||
"print([ctypes.CDLL(str(root/p)).voice_plugin() for p in manifest['plugins']] + "
|
||||
"[ctypes.CDLL(str(root/'lib/libgio-2.0.so.0')).voice_gio_fixture()])",
|
||||
str(moved),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env=environment,
|
||||
cwd=self.root,
|
||||
)
|
||||
self.assertEqual(json.loads(result.stdout), [42] * len(PLUGINS) + [84])
|
||||
manifest = json.loads((moved / "runtime.json").read_text())
|
||||
self.assertEqual(
|
||||
{record["path"] for record in manifest["libraries"]},
|
||||
{
|
||||
"lib/libfixture.so.1",
|
||||
"lib/libgio-2.0.so.0",
|
||||
"lib/libgiofixture.so.1",
|
||||
*(f"lib/gstreamer-1.0/libgst{name}.so" for name in PLUGINS),
|
||||
},
|
||||
)
|
||||
for record in manifest["libraries"]:
|
||||
path = moved / record["path"]
|
||||
expected = (
|
||||
("29=$ORIGIN:$ORIGIN/..",)
|
||||
if path.parent.name == "gstreamer-1.0"
|
||||
else ()
|
||||
)
|
||||
if path.name == "libgio-2.0.so.0":
|
||||
expected = ("29=$ORIGIN",)
|
||||
self.assertEqual(inspect(path, self.target).rpaths, expected)
|
||||
self.assertEqual(digest(path), record["sourceSha256"])
|
||||
self.assertEqual(record["sha256"], record["sourceSha256"])
|
||||
|
||||
def test_absolute_build_paths_require_a_new_native_build(self):
|
||||
plugin = self.prefix / "lib/gstreamer-1.0/libgstapp.so"
|
||||
subprocess.run(
|
||||
["patchelf", "--set-rpath", str(self.prefix / "lib"), str(plugin)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
for record in self.inventory:
|
||||
record["sha256"] = digest(self.prefix / record["path"])
|
||||
self.inventory_path.write_text(json.dumps(self.inventory))
|
||||
with self.assertRaisesRegex(ValueError, "rebuild native libraries"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_missing_dependency_and_digest_mismatch_leave_no_output(self):
|
||||
for records in (
|
||||
[r for r in self.inventory if "libgio" not in r["path"]],
|
||||
[r for r in self.inventory if "libfixture" not in r["path"]],
|
||||
[r for r in self.inventory if "libgiofixture" not in r["path"]],
|
||||
[{**r, "sha256": "b" * 64} for r in self.inventory],
|
||||
):
|
||||
with self.subTest(records=records), self.assertRaises(ValueError):
|
||||
self.inventory_path.write_text(json.dumps(records))
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_path_import_is_not_treated_as_a_system_library(self):
|
||||
plugin = self.prefix / "lib/gstreamer-1.0/libgstapp.so"
|
||||
subprocess.run(
|
||||
[
|
||||
"patchelf",
|
||||
"--replace-needed",
|
||||
"libfixture.so.1",
|
||||
"outside\nlibc.so.6",
|
||||
str(plugin),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "plain library names"):
|
||||
inspect(plugin, self.target)
|
||||
|
||||
def test_malformed_header_and_segment_bounds_are_rejected(self):
|
||||
original = self.library.read_bytes()
|
||||
for offset, replacement in (
|
||||
(18, b"\x00\x00"),
|
||||
(32, struct.pack("<Q", len(original))),
|
||||
(56, b"\xff\xff"),
|
||||
):
|
||||
data = bytearray(original)
|
||||
data[offset : offset + len(replacement)] = replacement
|
||||
self.library.write_bytes(data)
|
||||
with self.subTest(offset=offset), self.assertRaises(ValueError):
|
||||
inspect(self.library, self.target)
|
||||
|
||||
def test_additional_loader_dependencies_are_rejected(self):
|
||||
data = bytearray(self.library.read_bytes())
|
||||
header = struct.unpack_from("<16sHHIQQQIHHHHHH", data)
|
||||
for index in range(header[10]):
|
||||
segment = struct.unpack_from("<IIQQQQQQ", data, header[5] + index * 56)
|
||||
if segment[0] == 2:
|
||||
struct.pack_into("<qQ", data, segment[2], 0x7FFFFFFF, 0)
|
||||
break
|
||||
self.library.write_bytes(data)
|
||||
with self.assertRaisesRegex(ValueError, "unsupported ELF loader"):
|
||||
inspect(self.library, self.target)
|
||||
|
||||
def test_dynamic_table_mapping_is_checked_before_creating_output(self):
|
||||
# An existing intended runpath can make patchelf leave this malformed table untouched.
|
||||
subprocess.run(
|
||||
["patchelf", "--set-rpath", "$ORIGIN", str(self.library)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
original = self.library.read_bytes()
|
||||
header = struct.unpack_from("<16sHHIQQQIHHHHHH", original)
|
||||
dynamic_offset = next(
|
||||
header[5] + index * 56
|
||||
for index in range(header[10])
|
||||
if struct.unpack_from("<I", original, header[5] + index * 56)[0] == 2
|
||||
)
|
||||
address = struct.unpack_from("<Q", original, dynamic_offset + 16)[0]
|
||||
for invalid_address in (address + 8, 0x77770000):
|
||||
data = bytearray(original)
|
||||
struct.pack_into("<Q", data, dynamic_offset + 16, invalid_address)
|
||||
self.library.write_bytes(data)
|
||||
self.inventory_path.write_text(
|
||||
json.dumps(
|
||||
[
|
||||
{**record, "sha256": digest(self.prefix / record["path"])}
|
||||
for record in self.inventory
|
||||
]
|
||||
)
|
||||
)
|
||||
with (
|
||||
self.subTest(address=invalid_address),
|
||||
self.assertRaisesRegex(ValueError, "dynamic table.*mapping"),
|
||||
):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_failed_copy_removes_only_fresh_output(self):
|
||||
before = {r["path"]: digest(self.prefix / r["path"]) for r in self.inventory}
|
||||
with patch("runtime.shutil.copy2", side_effect=RuntimeError("copy failed")):
|
||||
with self.assertRaisesRegex(RuntimeError, "copy failed"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
self.assertEqual(
|
||||
before, {r["path"]: digest(self.prefix / r["path"]) for r in self.inventory}
|
||||
)
|
||||
342
third_party/voice/test_macos_runtime.py
vendored
Normal file
342
third_party/voice/test_macos_runtime.py
vendored
Normal file
@@ -0,0 +1,342 @@
|
||||
"""Check real Mach-O relocation and fail-closed native input handling."""
|
||||
|
||||
import ctypes
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from macos_runtime import PLUGINS, digest, inspect, project
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "darwin", "macOS native runtime projection")
|
||||
class RuntimeTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory(prefix="native voice ")
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.prefix = self.root / "input"
|
||||
self.receipts = self.root / "receipts"
|
||||
self.output = self.root / "runtime"
|
||||
self.target = (
|
||||
"aarch64" if platform.machine() == "arm64" else "x86_64"
|
||||
) + "-apple-darwin"
|
||||
(self.prefix / "lib/gstreamer-1.0").mkdir(parents=True)
|
||||
(self.receipts / "inspection").mkdir(parents=True)
|
||||
source = self.root / "fixture.c"
|
||||
source.write_text("int voice_fixture(void) { return 42; }\n")
|
||||
self.library = self.prefix / "lib/libfixture.1.2.dylib"
|
||||
subprocess.run(
|
||||
[
|
||||
"/usr/bin/cc",
|
||||
"-dynamiclib",
|
||||
str(source),
|
||||
"-o",
|
||||
str(self.library),
|
||||
"-Wl,-install_name,@rpath/libfixture.1.dylib",
|
||||
"-Wl,-headerpad_max_install_names",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
(self.prefix / "lib/libfixture.1.dylib").symlink_to(self.library.name)
|
||||
gio = self.prefix / "lib/libgio-2.0.0.dylib"
|
||||
shutil.copy2(self.library, gio)
|
||||
subprocess.run(
|
||||
["/usr/bin/install_name_tool", "-id", "@rpath/" + gio.name, str(gio)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
source.write_text(
|
||||
"extern int voice_fixture(void); int voice_plugin(void) { return voice_fixture(); }\n"
|
||||
)
|
||||
prototype = self.prefix / f"lib/gstreamer-1.0/libgst{PLUGINS[0]}.dylib"
|
||||
subprocess.run(
|
||||
[
|
||||
"/usr/bin/cc",
|
||||
"-dynamiclib",
|
||||
str(source),
|
||||
str(self.library),
|
||||
"-o",
|
||||
str(prototype),
|
||||
f"-Wl,-install_name,{prototype}",
|
||||
f"-Wl,-rpath,{self.prefix / 'lib'}",
|
||||
"-Wl,-headerpad_max_install_names",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
for name in PLUGINS[1:]:
|
||||
path = self.prefix / f"lib/gstreamer-1.0/libgst{name}.dylib"
|
||||
shutil.copy2(prototype, path)
|
||||
subprocess.run(
|
||||
["/usr/bin/install_name_tool", "-id", str(path), str(path)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
self.ci = {
|
||||
"commit": "a" * 40,
|
||||
"target": self.target,
|
||||
"build_complete": True,
|
||||
"inspection_complete": True,
|
||||
"manifest_sha256": digest(Path(__file__).with_name("sources.json")),
|
||||
}
|
||||
(self.receipts / "ci.json").write_text(json.dumps(self.ci))
|
||||
self.inventory = [
|
||||
{
|
||||
"path": p.relative_to(self.prefix).as_posix(),
|
||||
"target": self.target,
|
||||
"sha256": digest(p),
|
||||
}
|
||||
for p in sorted(self.prefix.rglob("*.dylib"))
|
||||
if not p.is_symlink()
|
||||
]
|
||||
self.inventory_path = self.receipts / "inspection/binaries.json"
|
||||
self.inventory_path.write_text(json.dumps(self.inventory))
|
||||
|
||||
def test_relocated_payload_loads_after_original_prefix_is_removed(self):
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(Path(__file__).with_name("macos_runtime.py").resolve()),
|
||||
"--prefix",
|
||||
str(self.prefix),
|
||||
"--receipts",
|
||||
str(self.receipts),
|
||||
"--target",
|
||||
self.target,
|
||||
"--output",
|
||||
str(self.output),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
cwd=self.root,
|
||||
env={**os.environ, "PYTHONSAFEPATH": "1"},
|
||||
)
|
||||
manifest = json.loads((self.output / "runtime.json").read_text())
|
||||
before = {r["path"]: digest(self.prefix / r["path"]) for r in self.inventory}
|
||||
self.assertEqual(before, {r["path"]: r["sha256"] for r in self.inventory})
|
||||
self.assertEqual(
|
||||
{r["path"] for r in manifest["libraries"]},
|
||||
{
|
||||
"lib/libfixture.1.dylib",
|
||||
"lib/libgio-2.0.0.dylib",
|
||||
*(f"plugins/libgst{name}.dylib" for name in PLUGINS),
|
||||
},
|
||||
)
|
||||
moved = self.root / "relocated package"
|
||||
self.output.rename(moved)
|
||||
shutil.rmtree(self.prefix)
|
||||
for relative in manifest["plugins"]:
|
||||
plugin = ctypes.CDLL(str(moved / relative))
|
||||
self.assertEqual(plugin.voice_plugin(), 42)
|
||||
for record in manifest["libraries"]:
|
||||
metadata = inspect(moved / record["path"], self.target)
|
||||
self.assertEqual(metadata.rpaths, ())
|
||||
self.assertEqual(metadata.imports, tuple(record["imports"]))
|
||||
self.assertEqual(digest(moved / record["path"]), record["sha256"])
|
||||
|
||||
def test_input_digest_target_and_receipt_must_match(self):
|
||||
for key, value in [
|
||||
("build_complete", False),
|
||||
("manifest_sha256", "b" * 64),
|
||||
("target", "wrong"),
|
||||
]:
|
||||
with self.subTest(key=key), self.assertRaises(ValueError):
|
||||
(self.receipts / "ci.json").write_text(
|
||||
json.dumps({**self.ci, key: value})
|
||||
)
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
(self.receipts / "ci.json").write_text(json.dumps(self.ci))
|
||||
self.library.write_bytes(b"tampered")
|
||||
with self.assertRaisesRegex(ValueError, "digest mismatch"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_case_alias_cannot_place_output_inside_inputs(self):
|
||||
for source in (self.prefix, self.receipts):
|
||||
alias = source.with_name(source.name.upper())
|
||||
if not alias.exists():
|
||||
self.skipTest("requires a case-insensitive filesystem")
|
||||
with (
|
||||
self.subTest(source=source),
|
||||
self.assertRaisesRegex(ValueError, "outside the inputs"),
|
||||
):
|
||||
project(self.prefix, self.receipts, self.target, alias / "runtime")
|
||||
self.assertFalse((source / "runtime").exists())
|
||||
|
||||
def test_case_colliding_library_destinations_are_rejected(self):
|
||||
duplicate = self.prefix / "lib/another.dylib"
|
||||
shutil.copy2(self.library, duplicate)
|
||||
subprocess.run(
|
||||
[
|
||||
"/usr/bin/install_name_tool",
|
||||
"-id",
|
||||
"@rpath/LIBFIXTURE.1.dylib",
|
||||
str(duplicate),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
self.inventory.append(
|
||||
{
|
||||
"path": duplicate.relative_to(self.prefix).as_posix(),
|
||||
"target": self.target,
|
||||
"sha256": digest(duplicate),
|
||||
}
|
||||
)
|
||||
self.inventory_path.write_text(json.dumps(self.inventory))
|
||||
with self.assertRaisesRegex(ValueError, "colliding runtime library filenames"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_changed_source_at_copy_is_rejected(self):
|
||||
copy = shutil.copy2
|
||||
|
||||
def change_then_copy(source, destination):
|
||||
source.write_bytes(source.read_bytes() + b"changed after verification")
|
||||
return copy(source, destination)
|
||||
|
||||
with patch("runtime.shutil.copy2", side_effect=change_then_copy):
|
||||
with self.assertRaisesRegex(ValueError, "copied native input changed"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_missing_dependency_and_duplicate_identity_fail_before_output_creation(
|
||||
self,
|
||||
):
|
||||
self.inventory_path.write_text(
|
||||
json.dumps([r for r in self.inventory if "libgio" not in r["path"]])
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "missing required native library"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
self.inventory_path.write_text(
|
||||
json.dumps([r for r in self.inventory if "libfixture" not in r["path"]])
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "undeclared native dependency"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.inventory_path.write_text(json.dumps([*self.inventory, self.inventory[0]]))
|
||||
with self.assertRaisesRegex(ValueError, "duplicate"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_inventory_cannot_escape_prefix(self):
|
||||
for relative in (
|
||||
"../fixture.c",
|
||||
str(self.library),
|
||||
"lib/../lib/libfixture.1.2.dylib",
|
||||
):
|
||||
self.inventory_path.write_text(
|
||||
json.dumps([{**self.inventory[0], "path": relative}])
|
||||
)
|
||||
with self.subTest(path=relative), self.assertRaises(ValueError):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_multiline_import_cannot_impersonate_a_system_library(self):
|
||||
external = self.root / "outside\n name /usr/lib/libSystem.B.dylib"
|
||||
external.parent.mkdir(parents=True)
|
||||
shutil.copy2(self.library, external)
|
||||
plugin = self.prefix / f"lib/gstreamer-1.0/libgst{PLUGINS[0]}.dylib"
|
||||
subprocess.run(
|
||||
[
|
||||
"/usr/bin/install_name_tool",
|
||||
"-change",
|
||||
"@rpath/libfixture.1.dylib",
|
||||
str(external),
|
||||
str(plugin),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
for record in self.inventory:
|
||||
record["sha256"] = digest(self.prefix / record["path"])
|
||||
self.inventory_path.write_text(json.dumps(self.inventory))
|
||||
with self.assertRaisesRegex(ValueError, "undeclared native dependency"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_malformed_load_command_bounds_and_strings_are_rejected(self):
|
||||
command = struct.pack("<6I", 0xD, 32, 24, 0, 0, 0) + b"test\0\0\0\0"
|
||||
for count, size, payload in (
|
||||
(1, 1024 * 1024 + 1, command),
|
||||
(2, 32, command),
|
||||
(1, 32, command[:-1]),
|
||||
(1, 32, struct.pack("<3I", 0xD, 40, 24) + command[12:]),
|
||||
(1, 32, struct.pack("<3I", 0xD, 32, 8) + command[12:]),
|
||||
(1, 32, command[:24] + b"no null!"),
|
||||
):
|
||||
with self.subTest(count=count, size=size, payload=payload):
|
||||
cpu = 0x100000C if self.target.startswith("aarch64") else 0x1000007
|
||||
self.library.write_bytes(
|
||||
struct.pack("<8I", 0xFEEDFACF, cpu, 0, 6, count, size, 0, 0)
|
||||
+ payload
|
||||
)
|
||||
with self.assertRaises(ValueError):
|
||||
inspect(self.library, self.target)
|
||||
|
||||
def test_tool_cannot_hide_other_architectures_or_loader_commands(self):
|
||||
cpu = 0x100000C if self.target.startswith("aarch64") else 0x1000007
|
||||
name = b"@rpath/libtest.dylib\0"
|
||||
command = (
|
||||
struct.pack("<6I", 0xD, 48, 24, 0, 0, 0) + name + bytes(24 - len(name))
|
||||
)
|
||||
thin = struct.pack("<8I", 0xFEEDFACF, cpu, 0, 6, 1, 48, 0, 0) + command
|
||||
for tag in (0x2B, 0x3A):
|
||||
self.library.write_bytes(
|
||||
struct.pack("<8I", 0xFEEDFACF, cpu, 0, 6, 2, 64, 0, 0)
|
||||
+ command
|
||||
+ struct.pack("<4I", tag, 16, 0, 0)
|
||||
)
|
||||
with self.subTest(tag=tag), self.assertRaises(ValueError):
|
||||
inspect(self.library, self.target)
|
||||
fat = struct.pack(">7I", 0xCAFEBABE, 1, cpu, 0, 4096, len(thin), 12)
|
||||
self.library.write_bytes(fat + bytes(4096 - len(fat)) + thin)
|
||||
with self.assertRaises(ValueError):
|
||||
inspect(self.library, self.target)
|
||||
fake_cpu = "X86_64" if cpu == 0x100000C else "ARM64"
|
||||
fake_target = (
|
||||
"x86_64-apple-darwin" if cpu == 0x100000C else "aarch64-apple-darwin"
|
||||
)
|
||||
path = (
|
||||
self.root
|
||||
/ f"fake\nMH_MAGIC_64 {fake_cpu} ALL 0x00 DYLIB 1 48 0x00000000\n\n.dylib"
|
||||
)
|
||||
path.write_bytes(thin)
|
||||
with self.assertRaises(ValueError):
|
||||
inspect(path, fake_target)
|
||||
|
||||
def test_existing_outputs_and_failed_transform_preserve_inputs(self):
|
||||
for output in (self.prefix, self.prefix / "nested", self.receipts / "nested"):
|
||||
with self.subTest(output=output), self.assertRaises(ValueError):
|
||||
project(self.prefix, self.receipts, self.target, output)
|
||||
import macos_runtime
|
||||
|
||||
original_run = macos_runtime.run
|
||||
|
||||
def fail_transform(command):
|
||||
if command[0].endswith("install_name_tool"):
|
||||
raise subprocess.CalledProcessError(1, command)
|
||||
return original_run(command)
|
||||
|
||||
with patch("macos_runtime.run", side_effect=fail_transform):
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
self.assertEqual(
|
||||
{r["path"]: digest(self.prefix / r["path"]) for r in self.inventory},
|
||||
{r["path"]: r["sha256"] for r in self.inventory},
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
209
third_party/voice/test_prepare_built_runtime.py
vendored
Normal file
209
third_party/voice/test_prepare_built_runtime.py
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
"""Exercise the build receipt boundary and real runtime preparation adapter."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import subprocess
|
||||
import shutil
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import macos_runtime
|
||||
from prepare_built_runtime import prepare_archive, prepare_built
|
||||
from runtime import digest
|
||||
import test_macos_runtime
|
||||
import test_sdk
|
||||
|
||||
|
||||
class BuiltRuntimeTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.prefix = self.root / "prefix"
|
||||
self.prefix.mkdir()
|
||||
self.library = self.prefix / "libfixture.dylib"
|
||||
self.library.write_bytes(b"synthetic inventory fixture")
|
||||
self.target = "aarch64-apple-darwin"
|
||||
self.status = self.root / "status"
|
||||
self.status.write_text("STABLE_GIT_COMMIT " + "a" * 40 + "\n")
|
||||
self.receipt = self.root / "built.json"
|
||||
self.build = {
|
||||
"target": self.target,
|
||||
"manifest_sha256": digest(Path(__file__).with_name("sources.json")),
|
||||
"steps": [{"name": "gst-plugins-good-install", "exit_code": 0}],
|
||||
}
|
||||
self.receipt.write_text(json.dumps(self.build))
|
||||
|
||||
def test_inspection_precedes_truthful_receipts_and_projection(self):
|
||||
def project(prefix, receipts, target, output):
|
||||
inspect.assert_called_once_with(self.library.resolve(), target)
|
||||
self.assertEqual(
|
||||
json.loads((receipts / "ci.json").read_text()),
|
||||
{
|
||||
"commit": "a" * 40,
|
||||
"target": self.target,
|
||||
"manifest_sha256": self.build["manifest_sha256"],
|
||||
"build_complete": True,
|
||||
"inspection_complete": True,
|
||||
},
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads((receipts / "inspection/binaries.json").read_text()),
|
||||
[
|
||||
{
|
||||
"path": self.library.name,
|
||||
"target": self.target,
|
||||
"sha256": digest(self.library),
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
with (
|
||||
patch.object(macos_runtime, "inspect") as inspect,
|
||||
patch.object(macos_runtime, "project", side_effect=project),
|
||||
):
|
||||
prepare_built(
|
||||
self.prefix, self.receipt, self.status, self.target, self.root / "out"
|
||||
)
|
||||
|
||||
def test_rejects_failed_incomplete_and_mismatched_builds_before_inspection(self):
|
||||
for change in (
|
||||
{"target": "x86_64-apple-darwin"},
|
||||
{"manifest_sha256": "0" * 64},
|
||||
{"steps": []},
|
||||
{"steps": [{"name": "glib-install", "exit_code": 0}]},
|
||||
{"steps": [{"name": "gst-plugins-good-install", "exit_code": 1}]},
|
||||
):
|
||||
with (
|
||||
self.subTest(change=change),
|
||||
patch.object(macos_runtime, "inspect") as inspect,
|
||||
):
|
||||
self.receipt.write_text(json.dumps({**self.build, **change}))
|
||||
with self.assertRaises(ValueError):
|
||||
prepare_built(
|
||||
self.prefix,
|
||||
self.receipt,
|
||||
self.status,
|
||||
self.target,
|
||||
self.root / "out",
|
||||
)
|
||||
inspect.assert_not_called()
|
||||
|
||||
def test_rejects_unknown_or_ambiguous_build_commit(self):
|
||||
for text in ("STABLE_GIT_COMMIT unknown\n", self.status.read_text() * 2):
|
||||
self.status.write_text(text)
|
||||
with self.assertRaises(ValueError):
|
||||
prepare_built(
|
||||
self.prefix,
|
||||
self.receipt,
|
||||
self.status,
|
||||
self.target,
|
||||
self.root / "out",
|
||||
)
|
||||
|
||||
def test_inspection_failure_never_reaches_projection(self):
|
||||
with (
|
||||
patch.object(
|
||||
macos_runtime, "inspect", side_effect=ValueError("bad library")
|
||||
),
|
||||
patch.object(macos_runtime, "project") as project,
|
||||
):
|
||||
with self.assertRaisesRegex(ValueError, "bad library"):
|
||||
prepare_built(
|
||||
self.prefix,
|
||||
self.receipt,
|
||||
self.status,
|
||||
self.target,
|
||||
self.root / "out",
|
||||
)
|
||||
project.assert_not_called()
|
||||
|
||||
@unittest.skipUnless(sys.platform == "darwin", "Uses real Mach-O fixture libraries")
|
||||
def test_projects_archive_through_sandbox_link_with_native_aliases(self):
|
||||
fixture = test_macos_runtime.RuntimeTests("runTest")
|
||||
self.addCleanup(fixture.doCleanups)
|
||||
fixture.setUp()
|
||||
sdk_fixture = test_sdk.SdkTests("runTest")
|
||||
self.addCleanup(sdk_fixture.doCleanups)
|
||||
sdk_fixture.setUp()
|
||||
for relative in ("include", "lib/glib-2.0", "lib/pkgconfig"):
|
||||
shutil.copytree(sdk_fixture.prefix / relative, fixture.prefix / relative)
|
||||
self.receipt.write_text(json.dumps({**self.build, "target": fixture.target}))
|
||||
library = next((fixture.prefix / "lib").glob("*.dylib"))
|
||||
(library.parent / "development-alias.dylib").symlink_to(library.name)
|
||||
archive = self.root / "prefix.tar"
|
||||
with tarfile.open(archive, "w") as source:
|
||||
source.add(fixture.prefix, arcname=".")
|
||||
sandbox_input = self.root / "sandbox-input.tar"
|
||||
sandbox_input.symlink_to(archive)
|
||||
for state in ("absent", "empty"):
|
||||
with self.subTest(output_state=state):
|
||||
output = self.root / f"runtime-{state}"
|
||||
if state == "empty":
|
||||
output.mkdir()
|
||||
sdk_output = self.root / f"sdk-{state}"
|
||||
if state == "empty":
|
||||
sdk_output.mkdir()
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(Path(__file__).with_name("prepare_built_runtime.py")),
|
||||
"--prefix",
|
||||
str(sandbox_input),
|
||||
"--build-receipt",
|
||||
str(self.receipt),
|
||||
"--status",
|
||||
str(self.status),
|
||||
"--target",
|
||||
fixture.target,
|
||||
"--output",
|
||||
str(output),
|
||||
"--sdk-output",
|
||||
str(sdk_output),
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
sdk_manifest = json.loads((sdk_output / "sdk.json").read_text())
|
||||
self.assertEqual(
|
||||
{
|
||||
record["path"]: record["sha256"]
|
||||
for record in sdk_manifest["files"]
|
||||
},
|
||||
{
|
||||
path.relative_to(sdk_output).as_posix(): digest(path)
|
||||
for path in sdk_output.rglob("*")
|
||||
if path.is_file() and path.name != "sdk.json"
|
||||
},
|
||||
)
|
||||
manifest = json.loads((output / "runtime.json").read_text())
|
||||
self.assertEqual(
|
||||
(sdk_manifest["sourceCommit"], sdk_manifest["target"]),
|
||||
(manifest["sourceCommit"], manifest["target"]),
|
||||
)
|
||||
self.assertEqual(manifest["sourceCommit"], "a" * 40)
|
||||
self.assertEqual(manifest["target"], fixture.target)
|
||||
self.assertTrue(
|
||||
all(
|
||||
not macos_runtime.inspect(
|
||||
output / record["path"], fixture.target
|
||||
).rpaths
|
||||
for record in manifest["libraries"]
|
||||
)
|
||||
)
|
||||
|
||||
def test_archive_rejects_escaping_native_alias_before_inspection(self):
|
||||
archive = self.root / "prefix.tar"
|
||||
with tarfile.open(archive, "w") as source:
|
||||
link = tarfile.TarInfo("lib/escape.dylib")
|
||||
link.type = tarfile.SYMTYPE
|
||||
link.linkname = "../../outside.dylib"
|
||||
source.addfile(link)
|
||||
with patch.object(macos_runtime, "inspect") as inspect:
|
||||
with self.assertRaises(tarfile.LinkOutsideDestinationError):
|
||||
prepare_archive(
|
||||
archive, self.receipt, self.status, self.target, self.root / "out"
|
||||
)
|
||||
inspect.assert_not_called()
|
||||
123
third_party/voice/test_prepare_sources.py
vendored
Normal file
123
third_party/voice/test_prepare_sources.py
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
"""Exercise source identity and extraction boundaries with synthetic archives."""
|
||||
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import prepare_sources as preparation
|
||||
|
||||
|
||||
class PreparationTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(directory.cleanup)
|
||||
self.root = Path(directory.name)
|
||||
self.output = self.root / "prepared sources"
|
||||
|
||||
def source(self, entries):
|
||||
archive_path = self.root / "fixture.tar"
|
||||
with tarfile.open(archive_path, "w") as archive:
|
||||
for name, kind, payload in entries:
|
||||
member = tarfile.TarInfo(name)
|
||||
member.type = kind
|
||||
if kind == tarfile.SYMTYPE:
|
||||
member.linkname = payload
|
||||
archive.addfile(member)
|
||||
else:
|
||||
member.size = len(payload)
|
||||
archive.addfile(member, io.BytesIO(payload))
|
||||
return {
|
||||
"name": "fixture",
|
||||
"version": "1",
|
||||
"role": "native-library",
|
||||
"archive": archive_path.name,
|
||||
"root": "fixture-1",
|
||||
"url": "https://example.invalid/fixture.tar",
|
||||
"sha256": hashlib.sha256(archive_path.read_bytes()).hexdigest(),
|
||||
"provenance": "Synthetic test input",
|
||||
}
|
||||
|
||||
def prepare(self, source):
|
||||
manifest = json.dumps({"schema_version": 1, "sources": [source]}).encode()
|
||||
preparation.prepare_sources(self.root, self.output, manifest)
|
||||
return manifest
|
||||
|
||||
def test_preserves_files_licenses_when_symlinks_are_unavailable(self):
|
||||
source = self.source(
|
||||
[
|
||||
("fixture-1/LICENSES/license.txt", tarfile.REGTYPE, b"License text\n"),
|
||||
("fixture-1/COPYING", tarfile.SYMTYPE, "LICENSES/license.txt"),
|
||||
]
|
||||
)
|
||||
with patch("tarfile.os.symlink", side_effect=OSError("No symlink privilege")):
|
||||
manifest = self.prepare(source)
|
||||
files = {
|
||||
p.relative_to(self.output / source["root"]).as_posix(): p.read_bytes()
|
||||
for p in (self.output / source["root"]).rglob("*")
|
||||
if p.is_file()
|
||||
}
|
||||
self.assertEqual(
|
||||
files,
|
||||
{
|
||||
"LICENSES/license.txt": b"License text\n",
|
||||
"COPYING": b"License text\n",
|
||||
},
|
||||
)
|
||||
self.assertFalse(any(p.is_symlink() for p in self.output.rglob("*")))
|
||||
self.assertEqual((self.output / "sources.json").read_bytes(), manifest)
|
||||
self.assertEqual(
|
||||
json.loads((self.output / "prepared.json").read_text()),
|
||||
{
|
||||
"schema_version": 1,
|
||||
"manifest_sha256": hashlib.sha256(manifest).hexdigest(),
|
||||
"sources": {
|
||||
"fixture": {"root": "fixture-1", "sha256": source["sha256"]}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
def test_rejects_changed_archive_before_extracting(self):
|
||||
source = self.source([("fixture-1/file", tarfile.REGTYPE, b"original")])
|
||||
(self.root / source["archive"]).write_bytes(b"changed")
|
||||
with self.assertRaisesRegex(ValueError, "SHA-256 mismatch"):
|
||||
self.prepare(source)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_filter_failure_cleans_incomplete_output(self):
|
||||
source = self.source(
|
||||
[
|
||||
("fixture-1/file", tarfile.REGTYPE, b"safe"),
|
||||
("fixture-1/link", tarfile.SYMTYPE, "../../outside"),
|
||||
]
|
||||
)
|
||||
with self.assertRaises(tarfile.FilterError):
|
||||
self.prepare(source)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_materialized_links_cannot_bypass_expansion_limit(self):
|
||||
source = self.source(
|
||||
[
|
||||
("fixture-1/file", tarfile.REGTYPE, b"123456"),
|
||||
("fixture-1/link", tarfile.SYMTYPE, "file"),
|
||||
]
|
||||
)
|
||||
with patch.object(preparation, "MAX_SOURCE_BYTES", 10):
|
||||
with self.assertRaisesRegex(ValueError, "Expanded source exceeds limits"):
|
||||
self.prepare(source)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_preserves_existing_output(self):
|
||||
source = self.source([("fixture-1/file", tarfile.REGTYPE, b"data")])
|
||||
self.output.mkdir()
|
||||
(self.output / "keep").write_text("unchanged")
|
||||
with self.assertRaises(FileExistsError):
|
||||
self.prepare(source)
|
||||
self.assertEqual(
|
||||
{p.name: p.read_text() for p in self.output.iterdir()},
|
||||
{"keep": "unchanged"},
|
||||
)
|
||||
154
third_party/voice/test_sdk.py
vendored
Normal file
154
third_party/voice/test_sdk.py
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
"""Exercise exported bytes, development aliases and moved pkg-config inputs."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from runtime import digest
|
||||
from sdk import MODULES, export_sdk
|
||||
|
||||
|
||||
class SdkTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory(prefix="voice SDK ")
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.prefix = self.root / "prefix"
|
||||
self.receipts = self.root / "receipts"
|
||||
self.output = self.root / "sdk"
|
||||
self.target = "aarch64-apple-darwin"
|
||||
for name in ("include/glib-2.0", "lib/glib-2.0/include", "lib/pkgconfig"):
|
||||
(self.prefix / name).mkdir(parents=True)
|
||||
(self.prefix / "include/glib-2.0/glib.h").write_text("/* SDK fixture */")
|
||||
(self.prefix / "lib/glib-2.0/include/glibconfig.h").write_text("/* target */")
|
||||
self.library = self.prefix / "lib/libfixture.0.dylib"
|
||||
self.library.write_bytes(b"receipt-verified fixture bytes")
|
||||
for module in (*MODULES, "zlib"):
|
||||
(self.prefix / f"lib/pkgconfig/{module}.pc").write_text(
|
||||
"prefix=${pcfiledir}/../..\n"
|
||||
f"Name: {module}\nDescription: SDK fixture\nVersion: 1.0\n"
|
||||
"Cflags: -I${prefix}/include\nLibs: -L${prefix}/lib -lfixture\n"
|
||||
)
|
||||
audio = self.prefix / "lib/pkgconfig/gstreamer-audio-1.0.pc"
|
||||
audio.write_text(
|
||||
audio.read_text() + "Requires.private: gstreamer-tag-1.0, zlib\n"
|
||||
)
|
||||
(self.receipts / "inspection").mkdir(parents=True)
|
||||
self.ci = {
|
||||
"target": self.target,
|
||||
"build_complete": True,
|
||||
"inspection_complete": True,
|
||||
"manifest_sha256": digest(Path(__file__).with_name("sources.json")),
|
||||
"commit": "a" * 40,
|
||||
}
|
||||
(self.receipts / "ci.json").write_text(json.dumps(self.ci))
|
||||
(self.receipts / "inspection/binaries.json").write_text(
|
||||
json.dumps(
|
||||
[
|
||||
{
|
||||
"path": "lib/libfixture.0.dylib",
|
||||
"target": self.target,
|
||||
"sha256": digest(self.library),
|
||||
}
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
def test_exported_bytes_and_receipt_survive_move_without_original(self):
|
||||
export_sdk(self.prefix, self.receipts, self.target, self.output)
|
||||
moved = self.root / "moved SDK"
|
||||
self.output.rename(moved)
|
||||
shutil.rmtree(self.prefix)
|
||||
manifest = json.loads((moved / "sdk.json").read_text())
|
||||
actual = {
|
||||
path.relative_to(moved).as_posix(): digest(path)
|
||||
for path in moved.rglob("*")
|
||||
if path.is_file() and path.name != "sdk.json"
|
||||
}
|
||||
self.assertEqual(
|
||||
manifest,
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"target": self.target,
|
||||
"sourceCommit": "a" * 40,
|
||||
"sourceManifestSha256": self.ci["manifest_sha256"],
|
||||
"files": [
|
||||
{"path": name, "sha256": actual[name]} for name in sorted(actual)
|
||||
],
|
||||
},
|
||||
)
|
||||
pkg_config = os.environ.get("VOICE_PKG_CONFIG") or shutil.which("pkg-config")
|
||||
if not pkg_config:
|
||||
self.skipTest("pkg-config required for the moved development-input probe")
|
||||
result = subprocess.check_output(
|
||||
[
|
||||
pkg_config,
|
||||
"--define-prefix",
|
||||
"--cflags",
|
||||
"--libs",
|
||||
"gstreamer-audio-1.0",
|
||||
"gio-2.0",
|
||||
],
|
||||
env={
|
||||
**os.environ,
|
||||
"PKG_CONFIG_PATH": "",
|
||||
"PKG_CONFIG_LIBDIR": str(moved / "lib/pkgconfig"),
|
||||
},
|
||||
text=True,
|
||||
).strip()
|
||||
self.assertEqual(
|
||||
shlex.split(result),
|
||||
[f"-I{moved.as_posix()}/include", f"-L{moved.as_posix()}/lib", "-lfixture"],
|
||||
)
|
||||
|
||||
def test_native_mutation_and_wrong_target_are_rejected(self):
|
||||
with self.assertRaisesRegex(ValueError, "sources and target"):
|
||||
export_sdk(self.prefix, self.receipts, "x86_64-apple-darwin", self.output)
|
||||
self.library.write_bytes(b"changed")
|
||||
with self.assertRaisesRegex(ValueError, "does not match"):
|
||||
export_sdk(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_development_alias_is_materialized_and_escape_is_rejected(self):
|
||||
alias = self.prefix / "lib/libfixture.dylib"
|
||||
try:
|
||||
alias.symlink_to(self.library.name)
|
||||
except OSError:
|
||||
self.skipTest("host cannot create the SDK's development symlink")
|
||||
export_sdk(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse((self.output / "lib/libfixture.dylib").is_symlink())
|
||||
self.assertEqual(
|
||||
(self.output / "lib/libfixture.dylib").read_bytes(),
|
||||
self.library.read_bytes(),
|
||||
)
|
||||
shutil.rmtree(self.output)
|
||||
alias.unlink()
|
||||
alias.symlink_to(self.receipts / "ci.json")
|
||||
with self.assertRaisesRegex(ValueError, "inside the prefix"):
|
||||
export_sdk(self.prefix, self.receipts, self.target, self.output)
|
||||
|
||||
def test_nonrelocatable_metadata_and_failed_copy_leave_no_output(self):
|
||||
metadata = self.prefix / "lib/pkgconfig/gstreamer-1.0.pc"
|
||||
original = metadata.read_text()
|
||||
metadata.write_text(original.replace("${pcfiledir}/../..", "/old/build"))
|
||||
with self.assertRaisesRegex(ValueError, "rebuild the SDK"):
|
||||
export_sdk(self.prefix, self.receipts, self.target, self.output)
|
||||
metadata.write_text(original)
|
||||
with patch("sdk.shutil.copy2", side_effect=OSError("copy failed")):
|
||||
with self.assertRaises(OSError):
|
||||
export_sdk(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_output_cannot_overwrite_or_nest_inside_inputs(self):
|
||||
for output in (self.prefix, self.prefix / "sdk", self.receipts / "sdk"):
|
||||
with (
|
||||
self.subTest(output=output),
|
||||
self.assertRaisesRegex(ValueError, "fresh"),
|
||||
):
|
||||
export_sdk(self.prefix, self.receipts, self.target, output)
|
||||
148
third_party/voice/test_windows_build_inputs.py
vendored
Normal file
148
third_party/voice/test_windows_build_inputs.py
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
"""Exercise explicit Windows tool selection and rejection before native builds."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from windows_build_inputs import build_environment
|
||||
|
||||
|
||||
class WindowsInputsTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory(prefix="voice selected tools ")
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.target = "x86_64-pc-windows-msvc"
|
||||
self.selected = {}
|
||||
for directory, names in {
|
||||
"msvc": [
|
||||
"cl.exe",
|
||||
"link.exe",
|
||||
"lib.exe",
|
||||
"dumpbin.exe",
|
||||
"ml64.exe",
|
||||
"nmake.exe",
|
||||
],
|
||||
"sdk": ["rc.exe", "mt.exe"],
|
||||
"cygwin": [
|
||||
"bash.exe",
|
||||
"cygpath.exe",
|
||||
"automake-1.18",
|
||||
"make.exe",
|
||||
"link.exe",
|
||||
],
|
||||
"cmake": ["cmake.exe"],
|
||||
"pkgconf": ["pkgconf.exe"],
|
||||
"Windows/System32": ["cmd.exe"],
|
||||
}.items():
|
||||
parent = self.root / directory
|
||||
parent.mkdir(parents=True)
|
||||
for name in names:
|
||||
(parent / name).touch()
|
||||
self.tools = {
|
||||
"cc": self.root / "msvc/cl.exe",
|
||||
"cxx": self.root / "msvc/cl.exe",
|
||||
"link": self.root / "msvc/link.exe",
|
||||
"lib": self.root / "msvc/lib.exe",
|
||||
"dumpbin": self.root / "msvc/dumpbin.exe",
|
||||
"assembler": self.root / "msvc/ml64.exe",
|
||||
"bootstrap_make": self.root / "msvc/nmake.exe",
|
||||
"rc": self.root / "sdk/rc.exe",
|
||||
"mt": self.root / "sdk/mt.exe",
|
||||
"make": self.root / "cygwin/make.exe",
|
||||
"shell": self.root / "cygwin/bash.exe",
|
||||
"cygpath": self.root / "cygwin/cygpath.exe",
|
||||
"automake": self.root / "cygwin/automake-1.18",
|
||||
"cmake": self.root / "cmake/cmake.exe",
|
||||
"pkg_config": self.root / "pkgconf/pkgconf.exe",
|
||||
"python": Path(sys.executable),
|
||||
}
|
||||
self.document = {
|
||||
"schemaVersion": 1,
|
||||
"target": self.target,
|
||||
"tools": {key: str(value) for key, value in self.tools.items()},
|
||||
"systemRoot": str(self.root / "Windows"),
|
||||
"INCLUDE": [str(self.root / "sdk")],
|
||||
"LIB": [str(self.root / "msvc")],
|
||||
}
|
||||
self.path = self.root / "inputs.json"
|
||||
|
||||
def environment(self):
|
||||
self.path.write_text(json.dumps(self.document), encoding="utf-8")
|
||||
return build_environment(self.path, self.target, self.selected)[0]
|
||||
|
||||
def test_msvc_link_precedes_same_named_cygwin_tool(self):
|
||||
environment = self.environment()
|
||||
first = next(
|
||||
Path(directory) / "link.exe"
|
||||
for directory in environment["PATH"].split(os.pathsep)
|
||||
if (Path(directory) / "link.exe").exists()
|
||||
)
|
||||
self.assertEqual(first, self.tools["link"])
|
||||
self.assertEqual(
|
||||
{name: environment[name] for name in ("INCLUDE", "LIB", "COMSPEC")},
|
||||
{
|
||||
"INCLUDE": str(self.root / "sdk"),
|
||||
"LIB": str(self.root / "msvc"),
|
||||
"COMSPEC": str(self.root / "Windows/System32/cmd.exe"),
|
||||
},
|
||||
)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Portable shell subprocess selection probe")
|
||||
def test_subprocess_uses_selected_tool_without_ambient_path(self):
|
||||
# Execute the name upstream uses, with a conflicting Cygwin executable.
|
||||
for path, text in (
|
||||
(self.tools["link"], "msvc"),
|
||||
(self.root / "cygwin/link.exe", "cygwin"),
|
||||
):
|
||||
path.write_text(f"#!/bin/sh\nprintf '{text}'\n")
|
||||
path.chmod(0o755)
|
||||
result = subprocess.run(
|
||||
["link.exe"],
|
||||
env=self.environment(),
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(result.stdout, "msvc")
|
||||
|
||||
def test_missing_or_wrong_architecture_assembler_is_rejected(self):
|
||||
self.tools["assembler"].unlink()
|
||||
with self.assertRaisesRegex(ValueError, "assembler"):
|
||||
self.environment()
|
||||
self.tools["assembler"].touch()
|
||||
self.target = "aarch64-pc-windows-msvc"
|
||||
self.document["target"] = self.target
|
||||
with self.assertRaisesRegex(ValueError, "assembler"):
|
||||
self.environment()
|
||||
arm = self.tools["assembler"].with_name("armasm64.exe")
|
||||
arm.touch()
|
||||
self.document["tools"]["assembler"] = str(arm)
|
||||
self.environment()
|
||||
|
||||
def test_shadowed_sdk_tool_is_rejected(self):
|
||||
shutil.copyfile(self.tools["rc"], self.root / "msvc/rc.exe")
|
||||
with self.assertRaisesRegex(ValueError, "shadowed: rc"):
|
||||
self.environment()
|
||||
|
||||
def test_cli_tool_must_match_recorded_selection(self):
|
||||
self.selected["cc"] = self.tools["cmake"]
|
||||
with self.assertRaisesRegex(ValueError, "disagrees with --cc"):
|
||||
self.environment()
|
||||
|
||||
def test_missing_sdk_and_relative_paths_are_rejected(self):
|
||||
for value in ([], ["relative"], [str(self.root / "missing")]):
|
||||
with self.subTest(value=value):
|
||||
self.document["INCLUDE"] = value
|
||||
with self.assertRaises(ValueError):
|
||||
self.environment()
|
||||
|
||||
def test_target_mismatch_cannot_reuse_other_inputs(self):
|
||||
self.document["target"] = "aarch64-pc-windows-msvc"
|
||||
with self.assertRaisesRegex(ValueError, "target"):
|
||||
self.environment()
|
||||
250
third_party/voice/test_windows_runtime.py
vendored
Normal file
250
third_party/voice/test_windows_runtime.py
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
"""Exercise native MSVC DLL preparation and restricted-search loading."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from runtime import PLUGINS, digest
|
||||
from windows_runtime import inspect, project
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "win32", "Windows native runtime preparation")
|
||||
class RuntimeTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory(prefix="native voice ")
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.prefix, self.receipts, self.output = (
|
||||
self.root / name for name in ("input", "receipts", "runtime")
|
||||
)
|
||||
self.target = (
|
||||
"aarch64"
|
||||
if platform.machine().lower() in ("arm64", "aarch64")
|
||||
else "x86_64"
|
||||
) + "-pc-windows-msvc"
|
||||
(self.prefix / "lib/gstreamer-1.0").mkdir(parents=True)
|
||||
(self.prefix / "bin").mkdir()
|
||||
(self.receipts / "inspection").mkdir(parents=True)
|
||||
source = self.root / "fixture.c"
|
||||
source.write_text(
|
||||
"__declspec(dllexport) int voice_fixture(void) { return 42; }\n"
|
||||
)
|
||||
self.library = self.prefix / "bin/fixture.dll"
|
||||
import_library = self.root / "fixture.lib"
|
||||
subprocess.run(
|
||||
[
|
||||
"cl",
|
||||
"/nologo",
|
||||
"/LD",
|
||||
"/MD",
|
||||
str(source),
|
||||
"/link",
|
||||
f"/OUT:{self.library}",
|
||||
f"/IMPLIB:{import_library}",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
cwd=self.root,
|
||||
)
|
||||
shutil.copy2(self.library, self.prefix / "bin/gio-2.0-0.dll")
|
||||
source = self.root / "plugin.c"
|
||||
source.write_text(
|
||||
"__declspec(dllimport) int voice_fixture(void); "
|
||||
"__declspec(dllexport) int voice_plugin(void) { return voice_fixture(); }\n"
|
||||
)
|
||||
for name in PLUGINS:
|
||||
plugin = self.prefix / f"lib/gstreamer-1.0/gst{name}.dll"
|
||||
subprocess.run(
|
||||
[
|
||||
"cl",
|
||||
"/nologo",
|
||||
"/LD",
|
||||
"/MD",
|
||||
str(source),
|
||||
str(import_library),
|
||||
"/link",
|
||||
f"/OUT:{plugin}",
|
||||
f"/IMPLIB:{self.root / (name + '.lib')}",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
cwd=self.root,
|
||||
)
|
||||
self.inventory_path = self.receipts / "inspection/binaries.json"
|
||||
self.inventory = [
|
||||
{
|
||||
"path": str(p.relative_to(self.prefix)),
|
||||
"sha256": digest(p),
|
||||
"target": self.target,
|
||||
}
|
||||
for p in sorted(self.prefix.rglob("*.dll"))
|
||||
]
|
||||
self.inventory_path.write_text(json.dumps(self.inventory))
|
||||
(self.receipts / "ci.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"commit": "a" * 40,
|
||||
"target": self.target,
|
||||
"build_complete": True,
|
||||
"inspection_complete": True,
|
||||
"manifest_sha256": digest(Path(__file__).with_name("sources.json")),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def test_receipts_match_across_checkout_line_endings(self):
|
||||
source = Path(__file__).with_name("sources.json")
|
||||
checkout = self.root / "checkout"
|
||||
manifest = checkout / "third_party/voice/sources.json"
|
||||
manifest.parent.mkdir(parents=True)
|
||||
manifest.write_bytes(source.read_bytes().replace(b"\r\n", b"\n"))
|
||||
shutil.copy2(source.parents[2] / ".gitattributes", checkout)
|
||||
git = ["git", "-C", str(checkout), "-c", "core.autocrlf=false"]
|
||||
subprocess.run([*git, "init", "-q"], check=True, capture_output=True)
|
||||
subprocess.run([*git, "add", "."], check=True, capture_output=True)
|
||||
hashes = []
|
||||
for autocrlf in ("true", "false"):
|
||||
manifest.unlink()
|
||||
subprocess.run(
|
||||
[*git, "-c", f"core.autocrlf={autocrlf}", "checkout-index", "-a", "-f"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
hashes.append(digest(manifest))
|
||||
self.assertEqual(hashes, [digest(source), digest(source)])
|
||||
receipt_path = self.receipts / "ci.json"
|
||||
receipt = json.loads(receipt_path.read_text())
|
||||
receipt["manifest_sha256"] = hashes[0]
|
||||
receipt_path.write_text(json.dumps(receipt))
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
|
||||
def test_moved_dlls_load_with_private_directory_and_system_search_only(self):
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(Path(__file__).with_name("windows_runtime.py").resolve()),
|
||||
"--prefix",
|
||||
str(self.prefix),
|
||||
"--receipts",
|
||||
str(self.receipts),
|
||||
"--target",
|
||||
self.target,
|
||||
"--output",
|
||||
str(self.output),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
cwd=self.root,
|
||||
env={**os.environ, "PYTHONSAFEPATH": "1"},
|
||||
)
|
||||
self.assertEqual(
|
||||
{r["path"]: digest(self.prefix / r["path"]) for r in self.inventory},
|
||||
{r["path"]: r["sha256"] for r in self.inventory},
|
||||
)
|
||||
moved = self.root / "moved runtime"
|
||||
self.output.rename(moved)
|
||||
shutil.rmtree(self.prefix)
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-c",
|
||||
"import ctypes,json,pathlib,sys; root=pathlib.Path(sys.argv[1]); "
|
||||
"manifest=json.loads((root/'runtime.json').read_text()); "
|
||||
"print([ctypes.CDLL(str(root/p),winmode=0x100|0x800).voice_plugin() for p in manifest['plugins']])",
|
||||
str(moved),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
cwd=self.root,
|
||||
)
|
||||
self.assertEqual(json.loads(result.stdout), [42] * len(PLUGINS))
|
||||
manifest = json.loads((moved / "runtime.json").read_text())
|
||||
self.assertEqual(
|
||||
{record["path"] for record in manifest["libraries"]},
|
||||
{
|
||||
"bin/fixture.dll",
|
||||
"bin/gio-2.0-0.dll",
|
||||
*(f"bin/gst{name}.dll" for name in PLUGINS),
|
||||
},
|
||||
)
|
||||
for record in manifest["libraries"]:
|
||||
self.assertEqual(digest(moved / record["path"]), record["sourceSha256"])
|
||||
|
||||
def test_missing_dependency_and_digest_mismatch_leave_no_output(self):
|
||||
for records in (
|
||||
[r for r in self.inventory if "gio-2.0" not in r["path"]],
|
||||
[r for r in self.inventory if "fixture.dll" not in r["path"]],
|
||||
[{**r, "sha256": "b" * 64} for r in self.inventory],
|
||||
):
|
||||
with self.subTest(records=records), self.assertRaises(ValueError):
|
||||
self.inventory_path.write_text(json.dumps(records))
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_case_alias_dll_identities_are_rejected(self):
|
||||
duplicate = self.prefix / "lib/FIXTURE.dll"
|
||||
shutil.copy2(self.library, duplicate)
|
||||
records = self.inventory + [
|
||||
{
|
||||
"path": str(duplicate.relative_to(self.prefix)),
|
||||
"sha256": digest(duplicate),
|
||||
"target": self.target,
|
||||
}
|
||||
]
|
||||
self.inventory_path.write_text(json.dumps(records))
|
||||
with self.assertRaisesRegex(ValueError, "duplicate"):
|
||||
project(self.prefix, self.receipts, self.target, self.output)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_malformed_headers_and_delayed_imports_are_rejected(self):
|
||||
original = self.library.read_bytes()
|
||||
pe = struct.unpack_from("<I", original, 60)[0]
|
||||
for offset, replacement in (
|
||||
(60, struct.pack("<I", len(original))),
|
||||
(pe + 4, b"\0\0"),
|
||||
(pe + 6, b"\xff\xff"),
|
||||
(pe + 24 + 112 + 13 * 8, struct.pack("<II", 1, 32)),
|
||||
):
|
||||
data = bytearray(original)
|
||||
data[offset : offset + len(replacement)] = replacement
|
||||
self.library.write_bytes(data)
|
||||
with self.subTest(offset=offset), self.assertRaises(ValueError):
|
||||
inspect(self.library, self.target)
|
||||
|
||||
def test_path_bearing_import_is_rejected(self):
|
||||
plugin = self.prefix / "lib/gstreamer-1.0/gstapp.dll"
|
||||
original = plugin.read_bytes()
|
||||
self.assertIn(b"fixture.dll\0", original)
|
||||
plugin.write_bytes(original.replace(b"fixture.dll\0", b"/ixture.dll\0"))
|
||||
with self.assertRaisesRegex(ValueError, "plain DLL names"):
|
||||
inspect(plugin, self.target)
|
||||
|
||||
def test_forwarded_exports_are_rejected(self):
|
||||
definition = self.root / "forward.def"
|
||||
definition.write_text("EXPORTS\nforwarded=KERNEL32.Sleep\n")
|
||||
destination = self.root / "forward.dll"
|
||||
machine = "ARM64" if self.target.startswith("aarch64") else "X64"
|
||||
subprocess.run(
|
||||
[
|
||||
"link",
|
||||
"/NOLOGO",
|
||||
"/DLL",
|
||||
"/NOENTRY",
|
||||
f"/MACHINE:{machine}",
|
||||
f"/DEF:{definition}",
|
||||
f"/OUT:{destination}",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
cwd=self.root,
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "forwarded DLL exports"):
|
||||
inspect(destination, self.target)
|
||||
18
third_party/voice/windows-crt.json
vendored
Normal file
18
third_party/voice/windows-crt.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"version": "14.50.35719",
|
||||
"license": "https://visualstudio.microsoft.com/license-terms/vs2026-ga-visualcpp-v14-redist-runtime/",
|
||||
"developerLicense": "https://visualstudio.microsoft.com/license-terms/vs2026-ga-community/",
|
||||
"redistribution": "https://learn.microsoft.com/en-us/visualstudio/releases/2026/redistribution",
|
||||
"x86_64-pc-windows-msvc": {
|
||||
"url": "https://download.visualstudio.microsoft.com/download/pr/a424e95b-20f6-4af6-844f-9d9a806080a7/a4ab48822362df6e478eb4ed33bf825a07a6faacd6879c1e3d59929cd38b984b/Microsoft.VC.14.50.18.0.CRT.Redist.X64.base.vsix",
|
||||
"sha256": "a4ab48822362df6e478eb4ed33bf825a07a6faacd6879c1e3d59929cd38b984b",
|
||||
"member": "Contents/VC/Redist/MSVC/14.50.35710/x64/Microsoft.VC145.CRT/vcruntime140.dll",
|
||||
"dllSha256": "184146852727a9db4eea06178716bec3cdbb1015c911f6b0f915b184ad7775b2"
|
||||
},
|
||||
"aarch64-pc-windows-msvc": {
|
||||
"url": "https://download.visualstudio.microsoft.com/download/pr/a424e95b-20f6-4af6-844f-9d9a806080a7/3544badcbcf09e77c6ec32ed866aae59471a39d8a84611d9ae016861ff60a42f/Microsoft.VC.14.50.18.0.CRT.Redist.ARM64.base.vsix",
|
||||
"sha256": "3544badcbcf09e77c6ec32ed866aae59471a39d8a84611d9ae016861ff60a42f",
|
||||
"member": "Contents/VC/Redist/MSVC/14.50.35710/arm64/Microsoft.VC145.CRT/vcruntime140.dll",
|
||||
"dllSha256": "6d987d8cb2a47cff9c29c1fcbb853e7ef273c545f7d822728f7d2d448ca18758"
|
||||
}
|
||||
}
|
||||
89
third_party/voice/windows_build_inputs.py
vendored
Normal file
89
third_party/voice/windows_build_inputs.py
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
"""Select already provisioned Windows build tools without unrelated PATH entries.
|
||||
|
||||
This is an input-selection contract, not a sandbox or a hashed tool closure.
|
||||
The selected tools still depend on their installed support files and Windows.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def build_environment(path, target, selected_tools):
|
||||
if path.stat().st_size > 65536:
|
||||
raise ValueError("Windows build input document exceeds limits")
|
||||
inputs = json.loads(path.read_text(encoding="utf-8"))
|
||||
expected = {
|
||||
"cc": "cl.exe",
|
||||
"cxx": "cl.exe",
|
||||
"link": "link.exe",
|
||||
"lib": "lib.exe",
|
||||
"dumpbin": "dumpbin.exe",
|
||||
"assembler": "ml64.exe" if target.startswith("x86_64-") else "armasm64.exe",
|
||||
"rc": "rc.exe",
|
||||
"mt": "mt.exe",
|
||||
"cmake": "cmake.exe",
|
||||
"bootstrap_make": "nmake.exe",
|
||||
"make": "make.exe",
|
||||
"shell": "bash.exe",
|
||||
"cygpath": "cygpath.exe",
|
||||
"automake": "automake-1.18",
|
||||
}
|
||||
if (
|
||||
target not in ("x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc")
|
||||
or inputs.get("schemaVersion") != 1
|
||||
or inputs.get("target") != target
|
||||
or set(inputs.get("tools", {})) != {*expected, "pkg_config", "python"}
|
||||
):
|
||||
raise ValueError("Windows build inputs do not match the target and tool set")
|
||||
tools = {}
|
||||
for name, value in inputs["tools"].items():
|
||||
tool = Path(value)
|
||||
if (
|
||||
not tool.is_absolute()
|
||||
or not tool.is_file()
|
||||
or ";" in str(tool)
|
||||
or (name in expected and tool.name.lower() != expected[name])
|
||||
):
|
||||
raise ValueError(f"Invalid Windows build tool: {name}")
|
||||
tools[name] = tool
|
||||
for name, tool in selected_tools.items():
|
||||
if not tools[name].samefile(tool):
|
||||
raise ValueError(f"Windows build input disagrees with --{name}")
|
||||
# libffi invokes cl/link/lib and its architecture's assembler by name.
|
||||
# Keep MSVC ahead of Cygwin, which also installs a different link.exe.
|
||||
directories = list(dict.fromkeys(tools[name].parent for name in expected))
|
||||
directories += [tools[name].parent for name in ("pkg_config", "python")]
|
||||
directories = list(dict.fromkeys(directories))
|
||||
for name, filename in expected.items():
|
||||
found = next(
|
||||
(p / filename for p in directories if (p / filename).is_file()), None
|
||||
)
|
||||
if found is None or not found.samefile(tools[name]):
|
||||
raise ValueError(f"Windows build tool is shadowed: {name}")
|
||||
system = Path(inputs["systemRoot"])
|
||||
command = system / "System32/cmd.exe"
|
||||
if not system.is_absolute() or not command.is_file() or ";" in str(system):
|
||||
raise ValueError(
|
||||
"Windows build inputs require a valid system command directory"
|
||||
)
|
||||
directories.append(command.parent)
|
||||
environment = {
|
||||
"PATH": os.pathsep.join(map(str, directories)),
|
||||
"SystemRoot": str(system),
|
||||
"SYSTEMROOT": str(system),
|
||||
"WINDIR": str(system),
|
||||
"COMSPEC": str(command),
|
||||
}
|
||||
for name in ("INCLUDE", "LIB"):
|
||||
values = inputs.get(name)
|
||||
if not isinstance(values, list) or not 1 <= len(values) <= 64:
|
||||
raise ValueError(
|
||||
f"Windows build inputs require explicit {name} directories"
|
||||
)
|
||||
for value in values:
|
||||
directory = Path(value)
|
||||
if not directory.is_absolute() or not directory.is_dir() or ";" in value:
|
||||
raise ValueError(f"Invalid Windows {name} directory")
|
||||
environment[name] = os.pathsep.join(values)
|
||||
return environment, inputs
|
||||
83
third_party/voice/windows_crt.py
vendored
Normal file
83
third_party/voice/windows_crt.py
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Add pinned, unmodified Microsoft retail CRT files to Windows release staging."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import urllib.request
|
||||
import zipfile
|
||||
|
||||
from windows_runtime import EXTERNAL_IMPORTS, inspect
|
||||
|
||||
|
||||
def stage(root: Path, target: str, helper: Path):
|
||||
pin = json.loads(Path(__file__).with_name("windows-crt.json").read_text())[target]
|
||||
with urllib.request.urlopen(pin["url"], timeout=90) as response:
|
||||
archive = response.read(6 * 1024 * 1024 + 1)
|
||||
if hashlib.sha256(archive).hexdigest() != pin["sha256"]:
|
||||
raise ValueError("Microsoft CRT archive digest mismatch")
|
||||
with zipfile.ZipFile(io.BytesIO(archive)) as source:
|
||||
member = source.getinfo(pin["member"])
|
||||
if member.file_size > 1024 * 1024:
|
||||
raise ValueError("CRT member exceeds size limit")
|
||||
data = source.read(member)
|
||||
if hashlib.sha256(data).hexdigest() != pin["dllSha256"]:
|
||||
raise ValueError("Microsoft CRT DLL digest mismatch")
|
||||
# Extract exactly one retail member, never debug_nonredist or installer files.
|
||||
with (root / "bin/vcruntime140.dll").open("xb") as output:
|
||||
output.write(data)
|
||||
files = list((root / "bin").glob("*.dll"))
|
||||
bundled = {path.name.lower() for path in files}
|
||||
imports = set()
|
||||
for path in files:
|
||||
if path.name.lower() != "vcruntime140.dll":
|
||||
imports.update(inspect(path, target).imports)
|
||||
# Only Microsoft's hash-pinned CRT may use ARM64X rather than plain ARM64.
|
||||
for path in (helper, root / "bin/vcruntime140.dll"):
|
||||
result = subprocess.run(
|
||||
["dumpbin", "/nologo", "/dependents", str(path)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
timeout=30,
|
||||
)
|
||||
imports.update(
|
||||
re.findall(
|
||||
r"(?mi)^ +([a-z0-9_+.-]+\.dll)\s*$", result.stdout.decode("ascii")
|
||||
)
|
||||
)
|
||||
# Additional Windows OS imports used by the Rust helper, not bundled CRTs.
|
||||
system = (EXTERNAL_IMPORTS - {"vcruntime140.dll"}) | {
|
||||
"api-ms-win-core-synch-l1-2-0.dll",
|
||||
"api-ms-win-core-winrt-error-l1-1-0.dll",
|
||||
"bcrypt.dll",
|
||||
"bcryptprimitives.dll",
|
||||
"combase.dll",
|
||||
"mmdevapi.dll",
|
||||
"oleaut32.dll",
|
||||
"ntdll.dll",
|
||||
"userenv.dll",
|
||||
"dbghelp.dll",
|
||||
}
|
||||
missing = {name.lower() for name in imports} - bundled - system
|
||||
if missing:
|
||||
raise ValueError(f"Unbundled Windows imports: {sorted(missing)}")
|
||||
manifest_path = root / "runtime.json"
|
||||
manifest = json.loads(manifest_path.read_text())
|
||||
if manifest.get("target") != target or manifest.get("developmentOnly") is not True:
|
||||
raise ValueError("expected staged development runtime")
|
||||
manifest["libraries"].append(
|
||||
{"path": "bin/vcruntime140.dll", "sha256": pin["dllSha256"]}
|
||||
)
|
||||
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--root", type=Path, required=True)
|
||||
parser.add_argument("--target", required=True)
|
||||
parser.add_argument("--helper", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
stage(args.root, args.target, args.helper)
|
||||
11
third_party/voice/windows_link_smoke.cc
vendored
Normal file
11
third_party/voice/windows_link_smoke.cc
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// Force a real final link against the prepared GStreamer import library.
|
||||
extern "C" void gst_version(unsigned int*, unsigned int*, unsigned int*, unsigned int*);
|
||||
|
||||
int main() {
|
||||
unsigned int major = 0;
|
||||
unsigned int minor = 0;
|
||||
unsigned int micro = 0;
|
||||
unsigned int nano = 0;
|
||||
gst_version(&major, &minor, µ, &nano);
|
||||
return major == 1 ? 0 : 1;
|
||||
}
|
||||
136
third_party/voice/windows_native.bzl
vendored
Normal file
136
third_party/voice/windows_native.bzl
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
"""Native Windows audio actions with complete, explicitly provisioned tool inputs."""
|
||||
|
||||
load("@bazel_skylib//rules/directory:providers.bzl", "DirectoryInfo")
|
||||
load("@rules_python//python:py_runtime_info.bzl", "PyRuntimeInfo")
|
||||
|
||||
WindowsBuildToolsInfo = provider(
|
||||
doc = "Selected native Windows tools, their support closure and recipe input document.",
|
||||
fields = {
|
||||
"files": "Complete declared executable, support, header and library files.",
|
||||
"inputs": "Existing windows_build_inputs schema, with execroot-relative tool paths.",
|
||||
"manifest": "Imported installed-tree manifest File.",
|
||||
"installed_files": "Files supplied by the explicitly selected installed tool repository.",
|
||||
"python": "Declared PyRuntimeInfo used by the actions.",
|
||||
"environment": "Explicit Windows OS environment; never a developer PATH.",
|
||||
},
|
||||
)
|
||||
|
||||
def _windows_tools_impl(ctx):
|
||||
architectures = {"x86_64-pc-windows-msvc": "ml64.exe", "aarch64-pc-windows-msvc": "armasm64.exe"}
|
||||
if ctx.attr.target not in architectures:
|
||||
fail("Windows native tools require a supported MSVC target")
|
||||
python = ctx.attr._python[PyRuntimeInfo]
|
||||
if not python.interpreter:
|
||||
fail("Windows native tools require a declared native Python interpreter")
|
||||
system_root = ctx.configuration.default_shell_env.get("SystemRoot")
|
||||
if not system_root:
|
||||
fail("Pass --action_env=SystemRoot=<actual Windows directory> as a fixed value")
|
||||
host_architecture = ctx.configuration.default_shell_env.get("PROCESSOR_ARCHITECTURE")
|
||||
if not host_architecture:
|
||||
fail("Pass --action_env=PROCESSOR_ARCHITECTURE=<actual host architecture> as a fixed value")
|
||||
msvc = ctx.attr.msvc[DirectoryInfo]
|
||||
sdk = ctx.attr.sdk[DirectoryInfo]
|
||||
tools = {
|
||||
name: msvc.get_file(filename)
|
||||
for name, filename in {
|
||||
"cc": "cl.exe",
|
||||
"cxx": "cl.exe",
|
||||
"link": "link.exe",
|
||||
"lib": "lib.exe",
|
||||
"dumpbin": "dumpbin.exe",
|
||||
"bootstrap_make": "nmake.exe",
|
||||
"assembler": architectures[ctx.attr.target],
|
||||
}.items()
|
||||
}
|
||||
tools.update({"rc": sdk.get_file("rc.exe"), "mt": sdk.get_file("mt.exe")})
|
||||
tools.update({"cmake": ctx.file.cmake, "python": python.interpreter})
|
||||
installed = ctx.files.installed_tools
|
||||
manifests = [file for file in installed if file.basename == "voice-tools.json"]
|
||||
if len(manifests) != 1:
|
||||
fail("Select a complete installed tool repository with --//third_party/voice:windows_installed_tools=<tools label>")
|
||||
pkgconf_root = manifests[0].dirname + "/pkgconf-image/"
|
||||
pkgconf_files = [file for file in installed if file.path.startswith(pkgconf_root)]
|
||||
pkgconf = [file for file in pkgconf_files if file.basename == "pkgconf.exe"]
|
||||
if len(pkgconf) != 1:
|
||||
fail("Installed tool repository must declare exactly one pkgconf-image pkgconf.exe")
|
||||
tools["pkg_config"] = pkgconf[0]
|
||||
if ctx.file.cmake not in ctx.files.cmake_data:
|
||||
fail("CMake executable must belong to its declared support tree")
|
||||
includes = [target[DirectoryInfo] for target in ctx.attr.includes]
|
||||
libraries = [target[DirectoryInfo] for target in ctx.attr.libraries]
|
||||
files = depset(
|
||||
tools.values() + installed,
|
||||
transitive = [msvc.transitive_files, sdk.transitive_files, python.files, ctx.attr.cmake_data.files] +
|
||||
[directory.transitive_files for directory in includes + libraries],
|
||||
)
|
||||
return [DefaultInfo(
|
||||
files = depset(pkgconf),
|
||||
runfiles = ctx.runfiles(files = pkgconf_files),
|
||||
), WindowsBuildToolsInfo(
|
||||
files = files,
|
||||
python = python,
|
||||
manifest = manifests[0],
|
||||
installed_files = installed,
|
||||
environment = {
|
||||
"SystemRoot": system_root,
|
||||
"SYSTEMROOT": system_root,
|
||||
"PROCESSOR_ARCHITECTURE": host_architecture,
|
||||
},
|
||||
inputs = {
|
||||
"schemaVersion": 1,
|
||||
"target": ctx.attr.target,
|
||||
"systemRoot": system_root,
|
||||
"tools": {name: file.path for name, file in tools.items()},
|
||||
"INCLUDE": [directory.path for directory in includes],
|
||||
"LIB": [directory.path for directory in libraries],
|
||||
},
|
||||
)]
|
||||
|
||||
windows_build_tools = rule(
|
||||
implementation = _windows_tools_impl,
|
||||
attrs = {
|
||||
"target": attr.string(mandatory = True),
|
||||
"msvc": attr.label(mandatory = True, providers = [DirectoryInfo]),
|
||||
"sdk": attr.label(mandatory = True, providers = [DirectoryInfo]),
|
||||
"includes": attr.label_list(mandatory = True, providers = [DirectoryInfo]),
|
||||
"libraries": attr.label_list(mandatory = True, providers = [DirectoryInfo]),
|
||||
"installed_tools": attr.label(mandatory = True),
|
||||
"cmake": attr.label(default = "@cmake-3.31.8-windows-x86_64//:cmake_bin", allow_single_file = True),
|
||||
"cmake_data": attr.label(default = "@cmake-3.31.8-windows-x86_64//:cmake_data"),
|
||||
"_python": attr.label(default = "@python_3_12//:py3_runtime", cfg = "exec"),
|
||||
},
|
||||
)
|
||||
|
||||
def _windows_prefix_impl(ctx):
|
||||
tools = ctx.attr.build_tools[WindowsBuildToolsInfo]
|
||||
prefix = ctx.actions.declare_file(ctx.label.name + "/prefix.tar")
|
||||
receipt = ctx.actions.declare_file(ctx.label.name + "/built.json")
|
||||
config = ctx.actions.declare_file(ctx.label.name + ".json")
|
||||
ctx.actions.write(config, json.encode({
|
||||
"inputs": tools.inputs,
|
||||
"manifest": tools.manifest.path,
|
||||
"installed_files": [file.path for file in tools.installed_files],
|
||||
"archives": [file.path for file in ctx.files.archives],
|
||||
"prefix": prefix.path,
|
||||
"receipt": receipt.path,
|
||||
}))
|
||||
ctx.actions.run(
|
||||
executable = tools.python.interpreter,
|
||||
arguments = [ctx.file._driver.path, "build", config.path],
|
||||
inputs = depset([config, ctx.file._driver] + ctx.files.archives + ctx.files._recipe, transitive = [tools.files]),
|
||||
outputs = [prefix, receipt],
|
||||
env = tools.environment,
|
||||
execution_requirements = {"no-remote-exec": "1"},
|
||||
mnemonic = "VoiceWindowsPrefix",
|
||||
)
|
||||
return [DefaultInfo(files = depset([prefix])), OutputGroupInfo(receipt = depset([receipt]))]
|
||||
|
||||
windows_native_prefix = rule(
|
||||
implementation = _windows_prefix_impl,
|
||||
attrs = {
|
||||
"build_tools": attr.label(mandatory = True, cfg = "exec", providers = [WindowsBuildToolsInfo]),
|
||||
"archives": attr.label_list(mandatory = True, allow_files = True),
|
||||
"_driver": attr.label(default = "//third_party/voice:bazel_windows.py", allow_single_file = True),
|
||||
"_recipe": attr.label(default = "//third_party/voice:native_recipe"),
|
||||
},
|
||||
)
|
||||
148
third_party/voice/windows_runtime.py
vendored
Normal file
148
third_party/voice/windows_runtime.py
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
"""Prepare verified Windows audio DLLs in one private development runtime directory."""
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Import only this script's siblings, including under PYTHONSAFEPATH.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from runtime import Binary, PLUGINS, RuntimeFormat, prepare, required_library_paths
|
||||
|
||||
# VCRUNTIME140 is a development prerequisite, not a guaranteed Windows component.
|
||||
EXTERNAL_IMPORTS = frozenset(
|
||||
{
|
||||
"advapi32.dll",
|
||||
"dnsapi.dll",
|
||||
"iphlpapi.dll",
|
||||
"kernel32.dll",
|
||||
"ole32.dll",
|
||||
"shell32.dll",
|
||||
"shlwapi.dll",
|
||||
"user32.dll",
|
||||
"ws2_32.dll",
|
||||
"vcruntime140.dll",
|
||||
*(
|
||||
f"api-ms-win-crt-{part}-l1-1-0.dll"
|
||||
for part in (
|
||||
"conio",
|
||||
"convert",
|
||||
"environment",
|
||||
"filesystem",
|
||||
"heap",
|
||||
"locale",
|
||||
"math",
|
||||
"process",
|
||||
"runtime",
|
||||
"stdio",
|
||||
"string",
|
||||
"time",
|
||||
"utility",
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def inspect(path, target):
|
||||
machine = {"x86_64-pc-windows-msvc": "8664", "aarch64-pc-windows-msvc": "AA64"}[
|
||||
target
|
||||
]
|
||||
if not 64 <= path.stat().st_size <= 64 * 1024 * 1024:
|
||||
raise ValueError("invalid PE file size")
|
||||
result = subprocess.run(
|
||||
["dumpbin", "/nologo", "/headers", "/dependents", "/exports", str(path)],
|
||||
capture_output=True,
|
||||
timeout=30,
|
||||
)
|
||||
output = result.stdout.decode("ascii", errors="backslashreplace").replace(
|
||||
"\r\n", "\n"
|
||||
)
|
||||
if (
|
||||
result.returncode
|
||||
or result.stderr
|
||||
or re.search(r"(?:fatal error|warning) LNK[0-9]+", output)
|
||||
):
|
||||
raise ValueError("dumpbin rejected the PE library")
|
||||
headers = output.split("SECTION HEADER #", 1)[0]
|
||||
if (
|
||||
"File Type: DLL\n" not in headers
|
||||
or not re.search(r"^ +" + machine + r" machine \(", headers, re.M)
|
||||
or not re.search(r"^ +20B magic # \(PE32\+\)$", headers, re.M)
|
||||
):
|
||||
raise ValueError(f"expected a {target} PE32+ DLL")
|
||||
count = re.search(r"^ +([0-9A-F]+) number of sections$", headers, re.M)
|
||||
if not count or not 1 <= int(count[1], 16) <= 96:
|
||||
raise ValueError("invalid PE section table")
|
||||
directories = {
|
||||
name: (int(address, 16), int(size, 16))
|
||||
for address, size, name in re.findall(
|
||||
r"^ +([0-9A-F]+) \[ *([0-9A-F]+)\] RVA \[size\] of ([^\n]+ Directory)$",
|
||||
headers,
|
||||
re.M,
|
||||
)
|
||||
}
|
||||
if len(directories) != 16:
|
||||
raise ValueError("unsupported PE data directories")
|
||||
if any(
|
||||
directories.get(name) != (0, 0)
|
||||
for name in ("Delay Import Directory", "COM Descriptor Directory")
|
||||
):
|
||||
raise ValueError("delay-load and managed DLL dependencies are unsupported")
|
||||
if "(forwarded to " in output:
|
||||
raise ValueError("forwarded DLL exports are unsupported loader dependencies")
|
||||
groups = re.findall(
|
||||
r"\n Image has the following dependencies:\n\n(.*?)(?:\n\n|\Z)", output, re.S
|
||||
)
|
||||
if len(groups) > 1:
|
||||
raise ValueError("ambiguous dumpbin dependencies")
|
||||
imports = (
|
||||
tuple(line.strip().lower() for line in groups[0].splitlines()) if groups else ()
|
||||
)
|
||||
if any(not re.fullmatch(r"[a-z0-9_+.-]+\.dll", name) for name in imports):
|
||||
raise ValueError("PE dependencies must be plain DLL names")
|
||||
address, size = directories["Import Directory"]
|
||||
# A descriptor per DLL plus its null terminator; reject truncated/injected output.
|
||||
if (address, size) != (0, 0) and (
|
||||
not address or size != 20 * (len(imports) + 1) or len(imports) > 128
|
||||
):
|
||||
raise ValueError("inconsistent PE import directory")
|
||||
return Binary(path.name.lower(), imports, ())
|
||||
|
||||
|
||||
def finalize_copy(destination, metadata, dependency_paths):
|
||||
# DLL import names already resolve among siblings; do not alter signed bytes.
|
||||
return metadata
|
||||
|
||||
|
||||
def project(prefix, receipts, target, output):
|
||||
if sys.platform != "win32" or target not in (
|
||||
"x86_64-pc-windows-msvc",
|
||||
"aarch64-pc-windows-msvc",
|
||||
):
|
||||
raise ValueError(
|
||||
"runtime preparation requires Windows and an explicit MSVC target"
|
||||
)
|
||||
format = RuntimeFormat(
|
||||
tuple(Path(f"lib/gstreamer-1.0/gst{name}.dll") for name in sorted(PLUGINS)),
|
||||
EXTERNAL_IMPORTS,
|
||||
inspect,
|
||||
finalize_copy,
|
||||
library_dir="bin",
|
||||
plugin_dir="bin",
|
||||
required_libraries=tuple(
|
||||
Path(path).name for path in required_library_paths(target)
|
||||
),
|
||||
)
|
||||
prepare(prefix, receipts, target, output, format)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--prefix", type=Path, required=True)
|
||||
parser.add_argument("--receipts", type=Path, required=True)
|
||||
parser.add_argument("--target", required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
project(args.prefix, args.receipts, args.target, args.output)
|
||||
21
third_party/wezterm/LICENSE
vendored
Normal file
21
third_party/wezterm/LICENSE
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018-Present Wez Furlong
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
40
third_party/wine/BUILD.bazel
vendored
Normal file
40
third_party/wine/BUILD.bazel
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
exports_files([
|
||||
"bin/wine",
|
||||
"bin/wineserver",
|
||||
])
|
||||
|
||||
filegroup(
|
||||
name = "wine",
|
||||
srcs = ["bin/wine"],
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "wineserver",
|
||||
srcs = ["bin/wineserver"],
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "runtime_marker",
|
||||
srcs = ["lib/wine/x86_64-unix/ntdll.so"],
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
# Static import libraries are build-time-only, so omit them from test runfiles.
|
||||
filegroup(
|
||||
name = "runtime",
|
||||
srcs = glob(
|
||||
[
|
||||
"lib/wine/**",
|
||||
"share/wine/**",
|
||||
],
|
||||
# This BUILD file is also loaded from the source tree, where the
|
||||
# archive-only paths are intentionally absent.
|
||||
allow_empty = True,
|
||||
exclude = ["**/*.a"],
|
||||
),
|
||||
tags = ["manual"],
|
||||
)
|
||||
Reference in New Issue
Block a user