mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-26 03:23:39 +08:00
reduce libfibre binary size
This commit is contained in:
@@ -43,4 +43,4 @@ windows:
|
||||
-static-libgcc -Wl,-Bstatic -lstdc++ ./third_party/libusb-windows/libusb-1.0.23/MinGW64/static/libusb-1.0.a -Wl,-Bdynamic
|
||||
|
||||
# To check exported symbols run:
|
||||
# nm -D libfibre.so | grep T
|
||||
# nm -D libfibre.so | grep ' T '
|
||||
|
||||
@@ -11,6 +11,9 @@ set -euo pipefail
|
||||
|
||||
# TODO: support C++11
|
||||
|
||||
CROSS_PLATFORM_CFLAGS='-O3 -fPIC -std=c++11 -DFIBRE_COMPILE -DFIBRE_ENABLE_CLIENT'
|
||||
CROSS_PLATFORM_GCC_FLAGS='-flto -Wl,--version-script=libfibre.version -Wl,--gc-sections'
|
||||
|
||||
mkdir -p third_party
|
||||
|
||||
# Usage: download_deb_pkg destination-dir url
|
||||
@@ -68,12 +71,17 @@ FILES=('libfibre.cpp'
|
||||
|
||||
function build_for_linux() {
|
||||
arch_name="$1"
|
||||
"${CXX}" -shared -o libfibre-"$arch_name".so -fPIC -std=c++11 -I./include -DFIBRE_COMPILE -DFIBRE_ENABLE_CLIENT \
|
||||
"${CXX}" -shared -o libfibre-"$arch_name".so -I./include \
|
||||
${CFLAGS} \
|
||||
${CROSS_PLATFORM_CFLAGS} \
|
||||
${CROSS_PLATFORM_GCC_FLAGS} \
|
||||
"${FILES[@]}" \
|
||||
${LIBS} \
|
||||
-lpthread \
|
||||
-Wl,--unresolved-symbols=ignore-in-shared-libs -static-libstdc++
|
||||
|
||||
# Could reduce binary size by 35% by using something like
|
||||
#arm-none-eabi-strip --strip-all --discard-all libfibre-linux-armhf.so
|
||||
}
|
||||
|
||||
|
||||
@@ -117,16 +125,22 @@ CXX="arm-linux-gnueabihf-g++" \
|
||||
### Windows
|
||||
|
||||
echo "building libfibre for Windows (AMD64)..."
|
||||
x86_64-w64-mingw32-g++ -shared -o libfibre-windows-amd64.dll -fPIC -std=c++11 -I./include -DFIBRE_COMPILE -DFIBRE_ENABLE_CLIENT \
|
||||
x86_64-w64-mingw32-g++ -shared -o libfibre-windows-amd64.dll -I./include \
|
||||
-I./third_party/libusb-windows/libusb-1.0.23/include/libusb-1.0 \
|
||||
${CROSS_PLATFORM_CFLAGS} \
|
||||
${CROSS_PLATFORM_GCC_FLAGS} \
|
||||
"${FILES[@]}" \
|
||||
-static-libgcc \
|
||||
-Wl,-Bstatic \
|
||||
-lstdc++ \
|
||||
./third_party/libusb-windows/libusb-1.0.23/MinGW64/static/libusb-1.0.a \
|
||||
-Wl,-Bdynamic
|
||||
-Wl,-Bdynamic
|
||||
cp /usr/x86_64-w64-mingw32/bin/libwinpthread-1.dll .
|
||||
|
||||
# The windows compiler keeps a ton of debug symbols for some reason. Stripping
|
||||
# the DLL reduces its size by a factor of 10.
|
||||
x86_64-w64-mingw32-strip --strip-all --discard-all libfibre-windows-amd64.dll
|
||||
|
||||
### macOS
|
||||
|
||||
# Link are broken:
|
||||
@@ -152,11 +166,12 @@ export MACOSX_DEPLOYMENT_TARGET='10.9'
|
||||
CC='o64-clang' \
|
||||
compile_libusb 'macos-amd64' 'x86_64-apple-darwin17'
|
||||
|
||||
echo "building libfibre for macOS"
|
||||
echo "building libfibre for macOS (x86)"
|
||||
|
||||
o64-clang++ -shared -o libfibre-macos-x86.dylib -fPIC -std=c++11 -I./include -DFIBRE_COMPILE -DFIBRE_ENABLE_CLIENT \
|
||||
o64-clang++ -shared -o libfibre-macos-x86.dylib -I./include \
|
||||
-I./third_party/libusb-windows/libusb-1.0.23/include/libusb-1.0 \
|
||||
-arch x86_64 -arch i386 \
|
||||
${CROSS_PLATFORM_CFLAGS} \
|
||||
"${FILES[@]}" \
|
||||
-static-libstdc++ \
|
||||
./third_party/libusb-1.0.23/build-macos-amd64/libusb/.libs/libusb-1.0.a \
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
LIBFIBREABI_0.1.0 {
|
||||
global: libfibre_*;
|
||||
local: *;
|
||||
};
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user