Bug 1917739 - Move Lz4 and mfbt/Compression* to mozglue/static. r=nika,frontend-codestyle-reviewers

As per mozglue/static/README:

> mozglue/static contains parts of the mozglue library that can/should be
> statically linked to e.g. js/Gecko.

The compression part of MFBT is a good candidate for this.

Differential Revision: https://phabricator.services.mozilla.com/D221565
This commit is contained in:
Mike Hommey 2024-09-10 20:35:56 +00:00
parent a4a4236336
commit d46c6229a7
25 changed files with 52 additions and 45 deletions

View File

@ -168,7 +168,6 @@ media/openmax_il/.*
media/webrtc/signaling/src/sdp/sipcc/.*
media/webrtc/trunk/.*
mfbt/double-conversion/double-conversion/.*
mfbt/lz4/.*
mobile/android/geckoview/src/thirdparty/.*
modules/brotli/.*
modules/fdlibm/.*
@ -180,6 +179,7 @@ modules/woff2/src/.*
modules/xz-embedded/.*
modules/zlib/.*
mozglue/misc/decimal/.*
mozglue/static/lz4/.*
mozglue/tests/glibc_printf_tests/.*
netwerk/dns/nsIDNKitInterface.h
netwerk/sctp/src/.*

View File

@ -1389,7 +1389,6 @@ media/mp4parse-rust/
media/openmax_il/
media/webrtc/signaling/gtest/MockCall.h
mfbt/double-conversion/double-conversion/
mfbt/lz4/.*
mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/readability/JSDOMParser-0.4.2.js
mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/readability/readability-0.4.2.js
mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/readability/readability-readerable-0.4.2.js
@ -1401,6 +1400,7 @@ modules/woff2/
modules/xz-embedded/
modules/zlib/
mozglue/misc/decimal/
mozglue/static/lz4/.*
mozglue/tests/glibc_printf_tests/
netwerk/dns/nsIDNKitInterface.h
netwerk/sctp/src/

View File

@ -18,7 +18,7 @@ src:*/media/libvpx/libvpx/vp8/encoder/encodeframe.c
src:*/third_party/aom/av1/common/quant_common.c
# crashtest
src:*/parser/expat/lib/xmlparse.c
src:*/mfbt/lz4/lz4.c
src:*/mozglue/static/lz4/lz4.c
src:*/media/libogg/src/ogg_framing.c
# mochitest gl2c dom/canvas/test/webgl-conf/generated/test_2_conformance2__reading__read-pixels-pack-parameters.html
src:*/dom/canvas/WebGLContextGL.cpp

View File

@ -112,7 +112,7 @@ src:*/modules/zlib/src/*
# Our LZ4 implementation uses overflows. By listing it here we might
# miss some unintended overflows in that implementation, but we can't
# check for it right now.
src:*/mfbt/lz4.c
src:*/mozglue/static/lz4/lz4.c
# Apparently this overflows a lot, because it contains some allocators
# that keep overflowing, not sure why. Disabling by function didn't seem

View File

@ -119,7 +119,7 @@ src:*/modules/zlib/src/*
# Our LZ4 implementation uses overflows. By listing it here we might
# miss some unintended overflows in that implementation, but we can't
# check for it right now.
src:*/mfbt/lz4/*
src:*/mozglue/static/lz4/*
# Apparently this overflows a lot, because it contains some allocators
# that keep overflowing, not sure why. Disabling by function didn't seem

View File

@ -35,7 +35,6 @@ EXPORTS.mozilla = [
"CheckedInt.h",
"CompactPair.h",
"Compiler.h",
"Compression.h",
"DbgMacro.h",
"DebugOnly.h",
"DefineEnum.h",
@ -163,7 +162,6 @@ if CONFIG["MOZ_TSAN"]:
UNIFIED_SOURCES += [
"Assertions.cpp",
"ChaosMode.cpp",
"Compression.cpp",
"double-conversion/double-conversion/bignum-dtoa.cc",
"double-conversion/double-conversion/bignum.cc",
"double-conversion/double-conversion/cached-powers.cc",
@ -194,22 +192,10 @@ if CONFIG["MOZ_BUILD_APP"] not in (
DEFINES["IMPL_MFBT"] = True
SOURCES += [
"lz4/lz4.c",
"lz4/lz4file.c",
"lz4/lz4frame.c",
"lz4/lz4hc.c",
"lz4/xxhash.c",
]
SOURCES["lz4/xxhash.c"].flags += ["-Wno-unused-function"]
DisableStlWrapping()
OS_LIBS += CONFIG["LIBATOMIC_LIBS"]
DEFINES["LZ4LIB_VISIBILITY"] = ""
# For RefCounted.cpp
DEFINES["MOZ_SUPPORT_LEAKCHECKING"] = True

View File

@ -20,6 +20,7 @@ DIRS += [
"baseprofiler",
"build",
"misc",
"static",
]
if CONFIG["MOZ_WIDGET_TOOLKIT"]:

View File

@ -42,8 +42,7 @@ class LZ4 {
* @param aInputSize is the input size. Max supported value is ~1.9GB
* @return the number of bytes written in buffer |aDest|
*/
static MFBT_API size_t compress(const char* aSource, size_t aInputSize,
char* aDest);
static size_t compress(const char* aSource, size_t aInputSize, char* aDest);
/**
* Compress |aInputSize| bytes from |aSource| into an output buffer
@ -60,9 +59,8 @@ class LZ4 {
* @return the number of bytes written in buffer |aDest| or 0 if the
* compression fails
*/
static MFBT_API size_t compressLimitedOutput(const char* aSource,
size_t aInputSize, char* aDest,
size_t aMaxOutputSize);
static size_t compressLimitedOutput(const char* aSource, size_t aInputSize,
char* aDest, size_t aMaxOutputSize);
/**
* If the source stream is malformed, the function will stop decoding
@ -81,10 +79,9 @@ class LZ4 {
* buffer (necessarily <= aMaxOutputSize)
* @return true on success, false on failure
*/
[[nodiscard]] static MFBT_API bool decompress(const char* aSource,
size_t aInputSize, char* aDest,
size_t aMaxOutputSize,
size_t* aOutputSize);
[[nodiscard]] static bool decompress(const char* aSource, size_t aInputSize,
char* aDest, size_t aMaxOutputSize,
size_t* aOutputSize);
/**
* If the source stream is malformed, the function will stop decoding
@ -105,11 +102,10 @@ class LZ4 {
* buffer (necessarily <= aMaxOutputSize)
* @return true on success, false on failure
*/
[[nodiscard]] static MFBT_API bool decompressPartial(const char* aSource,
size_t aInputSize,
char* aDest,
size_t aMaxOutputSize,
size_t* aOutputSize);
[[nodiscard]] static bool decompressPartial(const char* aSource,
size_t aInputSize, char* aDest,
size_t aMaxOutputSize,
size_t* aOutputSize);
/*
* Provides the maximum size that LZ4 may output in a "worst case"
@ -134,10 +130,10 @@ class LZ4 {
*/
class LZ4FrameCompressionContext final {
public:
MFBT_API LZ4FrameCompressionContext(int aCompressionLevel, size_t aMaxSrcSize,
bool aChecksum, bool aStableSrc = false);
LZ4FrameCompressionContext(int aCompressionLevel, size_t aMaxSrcSize,
bool aChecksum, bool aStableSrc = false);
MFBT_API ~LZ4FrameCompressionContext();
~LZ4FrameCompressionContext();
size_t GetRequiredWriteBufferLength() { return mWriteBufLen; }
@ -147,8 +143,7 @@ class LZ4FrameCompressionContext final {
* @return a Result with a Span containing the frame header, or an lz4 error
* code (size_t).
*/
MFBT_API Result<Span<const char>, size_t> BeginCompressing(
Span<char> aWriteBuffer);
Result<Span<const char>, size_t> BeginCompressing(Span<char> aWriteBuffer);
/**
* Continue streaming frame-based compression with the provided input.
@ -157,8 +152,7 @@ class LZ4FrameCompressionContext final {
* @return a Result with a Span containing compressed output, or an lz4 error
* code (size_t).
*/
MFBT_API Result<Span<const char>, size_t> ContinueCompressing(
Span<const char> aInput);
Result<Span<const char>, size_t> ContinueCompressing(Span<const char> aInput);
/**
* Finalize streaming frame-based compression with the provided input.
@ -166,7 +160,7 @@ class LZ4FrameCompressionContext final {
* @return a Result with a Span containing compressed output and the frame
* footer, or an lz4 error code (size_t).
*/
MFBT_API Result<Span<const char>, size_t> EndCompressing();
Result<Span<const char>, size_t> EndCompressing();
private:
LZ4F_cctx_s* mContext;
@ -191,8 +185,8 @@ struct LZ4FrameDecompressionResult {
*/
class LZ4FrameDecompressionContext final {
public:
explicit MFBT_API LZ4FrameDecompressionContext(bool aStableDest = false);
MFBT_API ~LZ4FrameDecompressionContext();
explicit LZ4FrameDecompressionContext(bool aStableDest = false);
~LZ4FrameDecompressionContext();
/**
* Decompress a buffer/part of a buffer compressed with
@ -204,7 +198,7 @@ class LZ4FrameDecompressionContext final {
* completely decompressed the input into the output, or an lz4 error code
* (size_t).
*/
MFBT_API Result<LZ4FrameDecompressionResult, size_t> Decompress(
Result<LZ4FrameDecompressionResult, size_t> Decompress(
Span<char> aOutput, Span<const char> aInput);
private:

26
mozglue/static/moz.build Normal file
View File

@ -0,0 +1,26 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla = ["Compression.h"]
UNIFIED_SOURCES += [
"Compression.cpp",
]
SOURCES += [
"lz4/lz4.c",
"lz4/lz4file.c",
"lz4/lz4frame.c",
"lz4/lz4hc.c",
"lz4/xxhash.c",
]
SOURCES["lz4/xxhash.c"].flags += ["-Wno-unused-function"]
DEFINES["LZ4LIB_VISIBILITY"] = ""
# By putting it in js, it ends up in libxul too.
FINAL_LIBRARY = "js"

View File

@ -133,7 +133,6 @@ media/openmax_dl/
media/openmax_il/
media/webrtc/signaling/gtest/MockCall.h
mfbt/double-conversion/double-conversion/
mfbt/lz4/.*
mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/readability/JSDOMParser-0.4.2.js
mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/readability/readability-0.4.2.js
mobile/android/android-components/components/feature/readerview/src/main/assets/extensions/readerview/readability/readability-readerable-0.4.2.js
@ -145,6 +144,7 @@ modules/woff2/
modules/xz-embedded/
modules/zlib/
mozglue/misc/decimal/
mozglue/static/lz4/.*
mozglue/tests/glibc_printf_tests/
netwerk/dns/nsIDNKitInterface.h
netwerk/sctp/src/