Skip to content

Commit

Permalink
Update bindings + test code
Browse files Browse the repository at this point in the history
  • Loading branch information
SwadicalRag committed Jun 9, 2019
1 parent a1a4c57 commit c50df21
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions bindings.idl
Original file line number Diff line number Diff line change
@@ -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);
};
28 changes: 18 additions & 10 deletions test.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion wasi-toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c50df21

Please sign in to comment.