8000 Add scripts to build asm/wasm and portable linux + add github action to draft release on tag by sz3 · Pull Request #60 · sz3/libcimbar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add scripts to build asm/wasm and portable linux + add github action to draft release on tag #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
os: ubuntu-18.04
env: CXX="g++-7" CC="gcc-7"

- name: "linux gcc9"
os: ubuntu-latest
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also adding ubuntu-latest, which (at the moment) seems to be gcc9.


- name: "linux clang"
os: ubuntu-18.04
env: CXX="clang++" CC="clang"
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: release
10000
on:
push:
tags:
- '*'

jobs:
package-cimbar:
runs-on: ubuntu-latest
steps:
- name: Get the code
uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Get openCV
run: |
wget https://github.com/opencv/opencv/archive/refs/tags/4.5.5.zip
unzip 4.5.5.zip
mv opencv-4.5.5 opencv4

- name: Run the build process with Docker
uses: addnab/docker-run-action@v3
with:
image: emscripten/emsdk:latest
options: -v ${{ github.workspace }}:/usr/src/app
shell: bash
run: |
bash /usr/src/app/package-wasm.sh

- name: Show results
run: ls -l web/

- name: Create release
uses: softprops/action-gh-release@v1
with:
draft: true
files: |
web/cimbar.asmjs.zip
web/cimbar.wasm.tar.gz

11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ else() # if not wasm, go find opencv. 3 or 4 should both work
include_directories(${OpenCV_INCLUDE_DIRS})
endif()

if(DEFINED BUILD_PORTABLE_LINUX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(OPENCV4 REQUIRED opencv4)
link_directories(${OPENCV4_STATIC_LIBRARY_DIRS})

# statically link c++/gcc (not libc!!)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -static-libstdc++ -static-libgcc")
endif()

if(NOT DEFINED OPENCV_LIBS)
set(OPENCV_LIBS "opencv_calib3d" "opencv_imgcodecs" "opencv_imgproc" "opencv_photo" "opencv_core")
set(OPENCV_LIBS "opencv_calib3d" "opencv_imgcodecs" "opencv_imgproc" "opencv_photo" "opencv_core" ${OPENCV4_STATIC_LIBRARIES})
endif()

if(NOT DEFINED CPPFILESYSTEM)
Expand Down
31 changes: 31 additions & 0 deletions package-portable-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
## targeting old glibc
# docker run --mount type=bind,source="$(pwd)",target="/usr/src/app" -it ubuntu:16.04
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't fully automated yet, but the objdump -T <binfile> | grep GLIBC_ | awk '{print $(NF-1)}' | sort -V output suggests cimbar/cimbar_send built this way will work on glibc 2.14(!) and up. 16.04 is 2.23, so that's probably the more trustworthy number -- but who knows.

That said, I did test on centos7 a bit, and it works. So that's cool.


cd /usr/src/app

# https://gist.github.com/jlblancoc/99521194aba975286c80f93e47966dc5
apt update
apt install -y software-properties-common
add-apt-repository -y ppa:ubuntu-toolchain-r/test
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For g++7


apt update
apt install -y pkgconf g++-7 python-pip
apt install -y libgles2-mesa-dev libglfw3-dev

# cmake (via pip)
python -m pip install cmake

# use gcc7
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-7 100
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-7 100

cd opencv4/
mkdir build-portable/ && cd build-portable/
/usr/local/bin/cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF -DOPENCV_GENERATE_PKGCONFIG=YES -DOPENCV_FORCE_3RDPARTY_BUILD=YES
make -j5 install

cd /usr/src/app
mkdir build-portable/ && cd build-portable/
/usr/local/bin/cmake .. -DBUILD_PORTABLE_LINUX=1
make -j5 install
23 changes: 23 additions & 0 deletions package-wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
#docker run --mount type=bind,source="$(pwd)",target="/usr/src/app" -it emscripten/emsdk:latest
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly nervous about using :latest here. We'll see.


cd /usr/src/app

apt update
apt install python -y

cd opencv4/
mkdir opencv-build-wasm && cd opencv-build-wasm
python ../platforms/js/build_js.py build_wasm --build_wasm --emscripten_dir=/emsdk/upstream/emscripten

cd /usr/src/app
mkdir build-wasm && cd build-wasm
emcmake cmake .. -DUSE_WASM=1 -DOPENCV_DIR=/usr/src/app/opencv4
make -j5 install
(cd ../web/ && tar -czvf cimbar.wasm.tar.gz cimbar_js.* index.html main.js)

cd /usr/src/app
mkdir build-asmjs && cd build-asmjs
emcmake cmake .. -DUSE_WASM=2 -DOPENCV_DIR=/usr/src/app/opencv4
make -j5 install
(cd ../web/ && zip cimbar.asmjs.zip cimbar_js.js index.html main.js)
2 changes: 1 addition & 1 deletion src/lib/cimb_translator/test/CimbDecoderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST_CASE( "CimbDecoderTest/testPrethresholdDecode", "[unit]" )
for (unsigned i = 0; i < 16; ++i)
{
cv::Mat tile = cimbar::getTile(4, i, true);
cv::Mat tenxten(10, 10, tile.type());
cv::Mat tenxten(10, 10, tile.type(), cv::Scalar(0, 0, 0));
tile.copyTo(tenxten(cv::Rect(cv::Point(1, 1), tile.size())));

// grayscale and threshold, since that's what average_hash needs
Expand Down
4 changes: 4 additions & 0 deletions src/lib/image_hash/average_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace image_hash
uint64_t mval = (*hax) & 0x101010101ULL;
const uint8_t* cv = reinterpret_cast<const uint8_t*>(&mval);
uint8_t val = cv[0] << 4 | cv[1] << 3 | cv[2] << 2 | cv[3] << 1 | cv[4];
// TODO:
/*if (bigEndian)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything I'm targeting right now is littleendian, but this little optimization/hack will need some extra care for other platforms...

val = cv[7] << 4 | cv[6] << 3 | cv[5] << 2 | cv[4] << 1 | cv[3];*/ // ?

res |= intx::uint128(val) << bitpos;
}
}
Expand Down
2902
0