-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
251 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
# | ||
# android-mktemplate generates a template json file suitable for use with the | ||
# androiddeployqt tool. | ||
|
||
set -eu | ||
|
||
# QT_PATH is already pre-set in our docker container environment. Includes trailing slash. | ||
QT_PATH=${QT_PATH:-/usr/local/Qt-5.15.13/} | ||
|
||
main() { | ||
|
||
if [[ $# -ne 2 ]] ; then | ||
echo "Usage: android-mktemplate.sh appname output.json" >&2 | ||
exit 1 | ||
fi | ||
local ARG_APPNAME="$1" | ||
local ARG_DESTFILE="$2" | ||
|
||
# Available fields are documented in the template file at | ||
# @ref /usr/local/Qt-5.15.13/mkspecs/features/android/android_deployment_settings.prf | ||
cat > "${ARG_DESTFILE}" <<EOF | ||
{ | ||
"_description": "Generated by miqt/android-mktemplate", | ||
"application-binary": "${ARG_APPNAME}", | ||
"architectures": { | ||
"arm64-v8a" : "aarch64-linux-android" | ||
}, | ||
"android-extra-libs": "/opt/android_openssl/ssl_1.1/arm64-v8a/libssl_1_1.so,/opt/android_openssl/ssl_1.1/arm64-v8a/libcrypto_1_1.so", | ||
"android-min-sdk-version": "23", | ||
"android-target-sdk-version": "30", | ||
"ndk": "/opt/android-sdk/ndk/22.1.7171670", | ||
"ndk-host": "linux-x86_64", | ||
"qt": "${QT_PATH}", | ||
"sdk": "/opt/android-sdk", | ||
"sdkBuildToolsRevision": "30.0.2", | ||
"stdcpp-path": "/opt/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/", | ||
"tool-prefix": "llvm", | ||
"toolchain-prefix": "llvm", | ||
"useLLVM": true | ||
} | ||
EOF | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
# | ||
# android-stub-gen generates a .so that runs an exported function from another | ||
# so file. This is because Qt for Android always tries to run `main`, but Go's | ||
# c-shared build mode cannot export a function named `main`. | ||
|
||
set -eu | ||
|
||
# QT_PATH is already pre-set in our docker container environment. Includes trailing slash. | ||
QT_PATH=${QT_PATH:-/usr/local/Qt-5.15.13/} | ||
|
||
main() { | ||
|
||
if [[ $# -ne 3 ]] ; then | ||
echo "Usage: android-gen-stub.sh src.so function-name dest.so" >&2 | ||
exit 1 | ||
fi | ||
local ARG_SOURCE_SOFILE="$1" | ||
local ARG_FUNCTIONNAME="$2" | ||
local ARG_DEST_SOFILE="$3" | ||
|
||
local tmpdir=$(mktemp -d) | ||
trap "rm -r ${tmpdir}" EXIT | ||
|
||
echo "- Using temporary directory: ${tmpdir}" | ||
echo "- Found Qt path: ${QT_PATH}" | ||
|
||
echo "Generating stub..." | ||
|
||
cat > $tmpdir/miqtstub.cpp <<EOF | ||
#include <android/log.h> | ||
#include <dlfcn.h> | ||
#include <stdlib.h> | ||
typedef void goMainFunc_t(); | ||
int main(int argc, char** argv) { | ||
__android_log_print(ANDROID_LOG_VERBOSE, "miqt_stub", "Starting up"); | ||
void* handle = dlopen("$(basename "$ARG_SOURCE_SOFILE")", RTLD_LAZY); | ||
if (handle == NULL) { | ||
__android_log_print(ANDROID_LOG_VERBOSE, "miqt_stub", "miqt_stub: null handle opening so: %s", dlerror()); | ||
exit(1); | ||
} | ||
void* goMain = dlsym(handle, "${ARG_FUNCTIONNAME}"); | ||
if (goMain == NULL) { | ||
__android_log_print(ANDROID_LOG_VERBOSE, "miqt_stub", "miqt_stub: null handle looking for function: %s", dlerror()); | ||
exit(1); | ||
} | ||
__android_log_print(ANDROID_LOG_VERBOSE, "miqt_stub", "miqt_stub: Found target, calling"); | ||
// Cast to function pointer and call | ||
goMainFunc_t* f = (goMainFunc_t*)goMain; | ||
f(); | ||
__android_log_print(ANDROID_LOG_VERBOSE, "miqt_stub", "miqt_stub: Target function returned"); | ||
return 0; | ||
} | ||
EOF | ||
|
||
# Compile | ||
# Link with Qt libraries so that androiddeployqt detects us as being the | ||
# main shared library | ||
$CXX -shared \ | ||
-ldl \ | ||
-llog \ | ||
${QT_PATH}plugins/platforms/libplugins_platforms_qtforandroid_arm64-v8a.so \ | ||
${QT_PATH}lib/libQt5Widgets_arm64-v8a.so /usr/local/Qt-5.15.13/lib/libQt5Gui_arm64-v8a.so \ | ||
${QT_PATH}lib/libQt5Core_arm64-v8a.so \ | ||
${QT_PATH}lib/libQt5Svg_arm64-v8a.so \ | ||
${QT_PATH}lib/libQt5AndroidExtras_arm64-v8a.so \ | ||
-fPIC -DQT_WIDGETS_LIB -I${QT_PATH}include/QtWidgets -I${QT_PATH}include/ -I${QT_PATH}include/QtCore -DQT_GUI_LIB -I${QT_PATH}include/QtGui -DQT_CORE_LIB \ | ||
$tmpdir/miqtstub.cpp \ | ||
"-Wl,-soname,$(basename "$ARG_DEST_SOFILE")" \ | ||
-o "$ARG_DEST_SOFILE" | ||
|
||
|
||
echo "Done." | ||
} | ||
|
||
main "$@" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM raymii/qt:5.15-android-source | ||
|
||
RUN wget 'https://go.dev/dl/go1.23.1.linux-amd64.tar.gz' && \ | ||
tar x -C /usr/local/ -f go1.23.1.linux-amd64.tar.gz && \ | ||
rm go1.23.1.linux-amd64.tar.gz | ||
|
||
COPY ../cmd/android-stub-gen/android-stub-gen.sh /usr/local/bin/android-stub-gen.sh | ||
COPY ../cmd/android-stub-gen/android-mktemplate.sh /usr/local/bin/android-mktemplate.sh | ||
|
||
ENV PATH=/usr/local/go/bin:/opt/cmake/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/Qt-5.15.13/bin:/opt/android-sdk/cmdline-tools/tools/bin:/opt/android-sdk/tools:/opt/android-sdk/tools/bin:/opt/android-sdk/platform-tools | ||
|
||
ENV CC=/opt/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang | ||
ENV CXX=/opt/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang++ | ||
ENV CGO_ENABLED=1 | ||
ENV GOOS=android | ||
ENV GOARCH=arm64 | ||
ENV GOFLAGS=-buildvcs=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/mappu/miqt/qt" | ||
) | ||
|
||
func myRealMainFunc() { | ||
|
||
qt.NewQApplication(os.Args) | ||
|
||
btn := qt.NewQPushButton2("Hello world!") | ||
btn.SetFixedWidth(320) | ||
|
||
var counter int = 0 | ||
|
||
btn.OnPressed(func() { | ||
counter++ | ||
btn.SetText(fmt.Sprintf("You have clicked the button %d time(s)", counter)) | ||
}) | ||
|
||
btn.Show() | ||
|
||
qt.QApplication_Exec() | ||
|
||
fmt.Println("OK!") | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// +build android | ||
|
||
package main | ||
|
||
import "C" // Required for export support | ||
|
||
//export AndroidMain | ||
func AndroidMain() { | ||
myRealMainFunc() | ||
} | ||
|
||
func main() { | ||
// Must be empty | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build !android | ||
|
||
package main | ||
|
||
func main() { | ||
myRealMainFunc() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package qt | ||
|
||
/* | ||
#cgo CXXFLAGS: -fPIC -DQT_WIDGETS_LIB -I/usr/local/Qt-5.15.13/include/QtWidgets -I/usr/local/Qt-5.15.13/include/ -I/usr/local/Qt-5.15.13/include/QtCore -DQT_GUI_LIB -I/usr/local/Qt-5.15.13/include/QtGui -DQT_CORE_LIB | ||
#cgo LDFLAGS: /usr/local/Qt-5.15.13/lib/libQt5Widgets_arm64-v8a.so /usr/local/Qt-5.15.13/lib/libQt5Gui_arm64-v8a.so /usr/local/Qt-5.15.13/lib/libQt5Core_arm64-v8a.so /usr/local/Qt-5.15.13/lib/libQt5Svg_arm64-v8a.so /usr/local/Qt-5.15.13/lib/libQt5AndroidExtras_arm64-v8a.so | ||
*/ | ||
import "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build linux,!android | ||
|
||
package qt | ||
|
||
/* | ||
|