From c50df210c2f68cb09bc718c097228b1ed3e09b05 Mon Sep 17 00:00:00 2001 From: swadical Date: Sun, 9 Jun 2019 15:14:32 +0930 Subject: [PATCH] Update bindings + test code --- CMakeLists.txt | 14 ++++++++++++++ bindings.idl | 12 ++++++++---- test.lua | 28 ++++++++++++++++++---------- wasi-toolchain.cmake | 2 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9492370..9f87e9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,20 @@ cmake_minimum_required(VERSION 2.8.6) project(brotli) + +IF (NOT CMAKE_BUILD_TYPE) +# SET(CMAKE_BUILD_TYPE "Debug") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF (NOT CMAKE_BUILD_TYPE) + +macro(remove_cxx_flag flag) + string(REPLACE "${flag}" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") +endmacro() + +remove_cxx_flag("-O3") +SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast") + + # If Brotli is being bundled in another project, we don't want to # install anything. However, we want to let people override this, so # we'll use the BROTLI_BUNDLED_MODE variable to let them do that; just diff --git a/bindings.idl b/bindings.idl index 53e7e19..a26ea23 100644 --- a/bindings.idl +++ b/bindings.idl @@ -1,8 +1,12 @@ -interface BrotliDecoderResult { - +namespace BrotliEncoderMode { + readonly attribute int BROTLI_MODE_GENERIC; + /** Compression mode for UTF-8 formatted text input. */ + readonly attribute int BROTLI_MODE_TEXT; + /** Compression mode used in WOFF 2.0. */ + readonly attribute int BROTLI_MODE_FONT; }; namespace global { - int BrotliDecoderDecompress ([ArrayLength="encoded_buffer"] any encoded_size, [Const,Array] octet encoded_buffer, [Array,Size,ConvertInputArray] any decoded_size, [Array,ConvertInputArray] octet decoded_buffer); - boolean BrotliEncoderCompress (int quality, int lgwin, BrotliEncoderMode mode, [ArrayLength="input_buffer"] any input_size, [Const,Array] octet input_buffer, [Array,Size,ConvertInputArray] any encoded_size, [Array,ConvertInputArray] octet encoded_buffer); + int BrotliDecoderDecompress ([ArrayLength="encoded_buffer"] any encoded_size, [Const,Array] octet encoded_buffer, [ArrayLengthRef="decoded_buffer"] any decoded_size, [Array,ConvertInputArray] octet decoded_buffer); + boolean BrotliEncoderCompress (int quality, int lgwin, [Enum="BrotliEncoderMode"] any mode, [ArrayLength="input_buffer"] any input_size, [Const,Array] octet input_buffer, [ArrayLengthRef="encoded_buffer"] any encoded_size, [Array,ConvertInputArray] octet encoded_buffer); }; diff --git a/test.lua b/test.lua index de04c00..38a2d45 100644 --- a/test.lua +++ b/test.lua @@ -1,19 +1,27 @@ -local module = dofile("bin/brotli.lua") +local module = dofile("bin/brotli.pure.lua") module.init() local function strToArr(str) - return {str:byte(1,-1)} + local out = {} for i=1,#str do out[i] = str:byte(i,i) end return out end -local compLen,compBuf = {2000},{} -for i=1,2000 do compBuf[i] = 0 end -assert(module.bindings.global.BrotliEncoderCompress(1,22,0,strToArr("Hello World"),compLen,compBuf) == 1) +local inputStr = ("Hello World"):rep(10000) -local fixed = {} -for i=1,compLen[1] do fixed[i] = compBuf[i] end +local compBuf = {__wasmMaxLen = #inputStr * 2} +local t = os.clock() +assert(module.bindings.global.BrotliEncoderCompress( + 5, + 22, + module.bindings.BrotliEncoderMode.BROTLI_MODE_GENERIC, + strToArr(inputStr), + compBuf +),"Compression failed") +print("Compression took "..(os.clock() - t).."s") -local outLen,outBuf = {2000},{} -assert(module.bindings.global.BrotliDecoderDecompress(fixed,outLen,outBuf) == 1) +t = os.clock() +local outBuf = {__wasmMaxLen = #inputStr} +assert(module.bindings.global.BrotliDecoderDecompress(compBuf,outBuf,"Decompression failed")) +print("Decompression took "..(os.clock() - t).."s") -for i=1,outLen[1] do io.write(string.char(outBuf[i])) end +-- for i=1,outBuf.len() do io.write(string.char(outBuf[i])) end diff --git a/wasi-toolchain.cmake b/wasi-toolchain.cmake index 43abea2..f89f488 100644 --- a/wasi-toolchain.cmake +++ b/wasi-toolchain.cmake @@ -17,7 +17,7 @@ set(CMAKE_C_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") set(CMAKE_CXX_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") set(CMAKE_C_FLAGS "-v -fvisibility=hidden" CACHE STRING "wasi-sdk build") set(CMAKE_CXX_FLAGS "-v -std=c++11 -fvisibility=hidden" CACHE STRING "wasi-sdk build") -set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,stack-size=10000000,--no-threads,--allow-undefined,--export-dynamic" CACHE STRING "wasi-sdk build") +set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,stack-size=15728640,--no-threads,--allow-undefined,--export-dynamic" CACHE STRING "wasi-sdk build") set(CMAKE_SYSROOT ${WASI_SDK_PREFIX}/share/sysroot CACHE STRING "wasi-sdk build") set(CMAKE_STAGING_PREFIX ${WASI_SDK_PREFIX}/share/sysroot CACHE STRING "wasi-sdk build")