Draft: Use libgoshim as external library
After the qt6 update, the building process takes much longer (>2 minutes) on my computer. This is not great for a developing environment. This is a partial fix: the go code results in libgoshim.so instead of libgoshim.a. Previously libgoshim.a was built into the desktop application (c++ code). Now it is linked against an external library.
I'm not familiar with c++/Makefiles. So this is just a workaround. To use it
git clone https://0xacab.org/leap/bitmask-vpn.git
cd bitmask-vpn
PROVIDER=riseup make vendor
PROVIDER=riseup QMAKE=qmake6 make build -j $(nproc)
# Now we have lib/libgoshim.h
wget https://0xacab.org/leap/bitmask-vpn/-/merge_requests/179.diff
git apply 179.diff
# build libgoshim.so
go build -buildmode=c-shared -o lib/libgoshim.so ./gui/backend.go
# build desktop client that uses libgoshim as external library
PROVIDER=riseup QMAKE=qmake6 make build -j $(nproc)
ldd build/qt/release/riseup-vpn | grep libgoshim
LD_LIBRARY_PATH=lib/ build/qt/release/riseup-vpn
Now after changing something in Go, just
go build -buildmode=c-shared -o lib/libgoshim.so ./gui/backend.go
LD_LIBRARY_PATH=lib/ build/qt/release/riseup-vpn
If the Go code changed, you just have to rebuild the library
go build -buildmode=c-shared -o lib/libgoshim.so ./gui/backend.go
which takes <5 seconds. Now, the Makefile does not build libgoshim.so
With the current changes, the Makefile does not build the go code. I changed the buildmode from c-archive
to c-shared
, but that gave me errors:
g++ -Wl,-rpath-link,/usr/lib -o release/bitmask release/.obj/main.o release/.obj/qjsonmodel.o release/.obj/handlers.o release/.obj/gui_main_qml.o release/.obj/gui_themes_Riseup_qml.o release/.obj/gui_themes_theme-calyx_js.o release/.obj/g
ui_themes_Bitmask_qml.o release/.obj/gui_themes_Calyx_qml.o release/.obj/gui_themes_ThemeObject_qml.o release/.obj/gui_themes_themes_js.o release/.obj/gui_themes_theme-riseup_js.o release/.obj/gui_components_Systray_qml.o release/.obj/gui_
components_MainView_qml.o release/.obj/gui_components_MaterialRadioButton_qml.o release/.obj/gui_components_Locations_qml.o release/.obj/gui_components_VPNMouseArea_qml.o release/.obj/gui_components_NavigationDrawer_qml.o release/.obj/gui_
components_ThemedPage_qml.o release/.obj/gui_components_Help_qml.o release/.obj/gui_components_WrappedRadioButton_qml.o release/.obj/gui_components_MotdBox_qml.o release/.obj/gui_components_MaterialButton_qml.o release/.obj/gui_components_
VPNButtonBase_qml.o release/.obj/gui_components_BoldLabel_qml.o release/.obj/gui_components_VerticalSpacer_qml.o release/.obj/gui_components_MaterialRadioIndicator_qml.o release/.obj/gui_components_FadeBehavior_qml.o release/.obj/gui_compo
nents_Home_qml.o release/.obj/gui_components_ErrorBox_qml.o release/.obj/gui_components_MaterialCheckBox_qml.o release/.obj/gui_components_LightLabel_qml.o release/.obj/gui_components_SignalIcon_qml.o release/.obj/gui_components_Icon_qml.o
release/.obj/gui_components_Footer_qml.o release/.obj/gui_components_VPNState_qml.o release/.obj/gui_components_StatusBox_qml.o release/.obj/gui_components_Splash_qml.o release/.obj/gui_components_Preferences_qml.o release/.obj/gui_compon
ents_Header_qml.o release/.obj/gui_components_InitErrors_qml.o release/.obj/gui_components_About_qml.o release/.obj/qmlcache_loader.o release/.obj/qrc_gui_gui_qmlcache.o release/.obj/qrc_vendor.o release/.obj/qrc_qmake_qmake_qm_files.o rel
ease/.obj/qrc_qmake_qmake_immediate.o release/.obj/moc_handlers.o release/.obj/moc_qjsonmodel.o -L../../lib -lgoshim /usr/lib/libQt6QuickControls2.so /usr/lib/libQt6Quick.so /usr/lib/libQt6OpenGL.so /usr/lib/libQt6Svg.so /usr/lib/libQt6W
idgets.so /usr/lib/libQt6Gui.so /usr/lib/libGLX.so /usr/lib/libOpenGL.so /usr/lib/libQt6QmlModels.so /usr/lib/libQt6Qml.so /usr/lib/libQt6Network.so /usr/lib/libQt6Core.so -lpthread -lGLX -lOpenGL
/usr/bin/ld: ../../lib/libgoshim.so: in function `_fini':
(.fini+0x0): multiple definition of `_fini'; /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/crti.o:(.fini+0x0): first defined here
/usr/bin/ld: ../../lib/libgoshim.so: in function `data_start':
(.data+0x0): multiple definition of `__data_start'; /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/Scrt1.o:(.data+0x0): first defined here
/usr/bin/ld: ../../lib/libgoshim.so: in function `data_start':
(.data+0x8): multiple definition of `__dso_handle'; /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/crtbeginS.o:(.data.rel.local+0x0): first defined here
/usr/bin/ld: ../../lib/libgoshim.so:(.rodata+0x0): multiple definition of `_IO_stdin_used'; /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/Scrt1.o:(.rodata.cst4+0x0): first defined here
/usr/bin/ld: ../../lib/libgoshim.so: in function `_start':
(.text+0x10): multiple definition of `_start'; /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/Scrt1.o:(.text+0x0): first defined here
/usr/bin/ld: ../../lib/libgoshim.so: in function `main':
/usr/lib/go/src/runtime/asm_amd64.s:24: multiple definition of `main'; release/.obj/main.o:/home/peanut/projects/leap/bitmask-vpn-build/build/qt/../../gui/main.cpp:102: first defined here
/usr/bin/ld: ../../lib/libgoshim.so: in function `_init':
(.init+0x0): multiple definition of `_init'; /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/crti.o:(.init+0x0): first defined here
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/crtendS.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'; ../../lib/libgoshim.so:(.go.buildinfo+0x0): first defined here
/usr/bin/ld: cannot use executable file '../../lib/libgoshim.so' as input to a link
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile.Release:363: release/bitmask] Error 1
make[2]: Leaving directory '/home/peanut/projects/leap/bitmask-vpn-build/build/qt'
make[1]: *** [Makefile:46: release-all] Error 2
make[1]: Leaving directory '/home/peanut/projects/leap/bitmask-vpn-build/build/qt'
make: *** [Makefile:148: build_gui] Error 2
We need to think about if we want to persist this in the Makefile. For now, this ist just a hint
cc @jkito