feat: set up build for android
Signed-off-by: Sphericalkat <me@kat.bio>
This commit is contained in:
parent
ae18a6ebaa
commit
308bb37564
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
target
|
3
Makefile
Normal file
3
Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
build:
|
||||||
|
go build -o target/linux-x86-64/libreadability.so -buildmode=c-shared main.go
|
||||||
|
strip target/linux-x86-64/libreadability.so
|
15
android.sh
Executable file
15
android.sh
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/sh
|
||||||
|
export NDK_PATH=/home/sphericalkat/Android/Sdk/ndk/27.0.11902837
|
||||||
|
export TARGET=aarch64-linux-android
|
||||||
|
export API=21
|
||||||
|
|
||||||
|
export CC=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/$TARGET$API-clang
|
||||||
|
export STRIP=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
|
||||||
|
export CXX=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/$TARGET$API-clang++
|
||||||
|
export CGO_CFLAGS="-I$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include"
|
||||||
|
export CGO_CPPFLAGS="-I$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include"
|
||||||
|
export CGO_CXXFLAGS="-I$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include"
|
||||||
|
export CGO_LDFLAGS="-L$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib"
|
||||||
|
|
||||||
|
CGO_ENABLED=1 GOOS=android GOARCH=arm64 go build -o target/android-arm64/libreadability.so -buildmode=c-shared main.go
|
||||||
|
$STRIP target/android-arm64/libreadability.so
|
40
main.go
40
main.go
@ -15,6 +15,8 @@ typedef struct {
|
|||||||
char* text_content; // text content
|
char* text_content; // text content
|
||||||
char* language;
|
char* language;
|
||||||
char* published_time;
|
char* published_time;
|
||||||
|
char* err;
|
||||||
|
int success;
|
||||||
} CArticle;
|
} CArticle;
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
@ -26,10 +28,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//export Parse
|
//export Parse
|
||||||
func Parse(url string) (result C.CArticle, errorMsg *C.char) {
|
func Parse(url *C.char) (result C.CArticle) {
|
||||||
article, err := readability.FromURL(url, 30*time.Second)
|
goURL := C.GoString(url)
|
||||||
|
article, err := readability.FromURL(goURL, 30*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return C.CArticle{}, C.CString(err.Error())
|
return C.CArticle{
|
||||||
|
err: C.CString(err.Error()),
|
||||||
|
success: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return C.CArticle{
|
return C.CArticle{
|
||||||
@ -42,20 +48,44 @@ func Parse(url string) (result C.CArticle, errorMsg *C.char) {
|
|||||||
favicon_url: C.CString(article.Favicon),
|
favicon_url: C.CString(article.Favicon),
|
||||||
content: C.CString(article.Content),
|
content: C.CString(article.Content),
|
||||||
text_content: C.CString(article.TextContent),
|
text_content: C.CString(article.TextContent),
|
||||||
}, nil
|
err: nil,
|
||||||
|
success: 1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export FreeArticle
|
//export FreeArticle
|
||||||
func FreeArticle(article C.CArticle) {
|
func FreeArticle(article C.CArticle) {
|
||||||
|
if article.title != nil {
|
||||||
C.free(unsafe.Pointer(article.title))
|
C.free(unsafe.Pointer(article.title))
|
||||||
|
}
|
||||||
|
if article.author != nil {
|
||||||
C.free(unsafe.Pointer(article.author))
|
C.free(unsafe.Pointer(article.author))
|
||||||
|
}
|
||||||
|
if article.excerpt != nil {
|
||||||
C.free(unsafe.Pointer(article.excerpt))
|
C.free(unsafe.Pointer(article.excerpt))
|
||||||
|
}
|
||||||
|
if article.site_name != nil {
|
||||||
C.free(unsafe.Pointer(article.site_name))
|
C.free(unsafe.Pointer(article.site_name))
|
||||||
|
}
|
||||||
|
if article.image_url != nil {
|
||||||
C.free(unsafe.Pointer(article.image_url))
|
C.free(unsafe.Pointer(article.image_url))
|
||||||
|
}
|
||||||
|
if article.favicon_url != nil {
|
||||||
C.free(unsafe.Pointer(article.favicon_url))
|
C.free(unsafe.Pointer(article.favicon_url))
|
||||||
|
}
|
||||||
|
if article.content != nil {
|
||||||
C.free(unsafe.Pointer(article.content))
|
C.free(unsafe.Pointer(article.content))
|
||||||
|
}
|
||||||
|
if article.text_content != nil {
|
||||||
C.free(unsafe.Pointer(article.text_content))
|
C.free(unsafe.Pointer(article.text_content))
|
||||||
|
}
|
||||||
|
if article.language != nil {
|
||||||
|
C.free(unsafe.Pointer(article.language))
|
||||||
|
}
|
||||||
|
if article.published_time != nil {
|
||||||
|
C.free(unsafe.Pointer(article.published_time))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user