remove C++ std limitation for linux and android

This commit is contained in:
ekibun
2020-08-26 23:38:16 +08:00
parent e0000ac2d6
commit ba35352b2a
22 changed files with 35 additions and 110 deletions

View File

@@ -23,9 +23,8 @@
"C:/Users/ekibun/AppData/Local/Android/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
"__ANDROID__",
"__LINUX__"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Users/ekibun/AppData/Local/Android/Sdk/cmake/3.10.2.4988404/bin/cmake.exe",
@@ -41,9 +40,7 @@
"/usr/include/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
"__LINUX__"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "/usr/bin/clang++",

View File

@@ -3,8 +3,12 @@
* @Author: ekibun
* @Date: 2020-08-08 08:16:50
* @LastEditors: ekibun
* @LastEditTime: 2020-08-25 18:12:51
* @LastEditTime: 2020-08-26 23:37:16
-->
## 0.0.4
* remove C++ std limitation for linux and android.
## 0.0.3
* fix js memory leak.

View File

@@ -3,7 +3,7 @@
* @Author: ekibun
* @Date: 2020-08-08 08:16:50
* @LastEditors: ekibun
* @LastEditTime: 2020-08-20 13:58:47
* @LastEditTime: 2020-08-26 23:02:05
-->
# flutter_qjs
@@ -76,6 +76,3 @@ try {
```
[This example](example/lib/test.dart) contains a complete demonstration on how to use this plugin.
**notice:**
To use this plugin in Linux desktop application, you must change `cxx_std_14` to `cxx_std_17` in your project's `CMakeLists.txt`.

View File

@@ -33,11 +33,6 @@ android {
}
defaultConfig {
minSdkVersion 16
externalNativeBuild {
cmake {
cppFlags "-std=c++17"
}
}
}
lintOptions {
disable 'InvalidPackage'

View File

@@ -30,6 +30,7 @@ target_sources(${JNI_LIB_NAME} PUBLIC
${QUICK_JS_LIB_DIR}/libunicode.c
${QUICK_JS_LIB_DIR}/quickjs.c
)
target_compile_features(${JNI_LIB_NAME} PUBLIC cxx_std_17)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by

View File

@@ -29,7 +29,6 @@ class FlutterQjsPlugin: FlutterPlugin, MethodCallHandler {
override fun onMethodCall(call: MethodCall, result: Result) {
if (call.method == "createEngine") {
val engine: Long = JniBridge.instance.createEngine(channelwrapper)
println(engine)
result.success(engine)
} else if (call.method == "evaluate") {
val engine: Long = call.argument<Long>("engine")!!
@@ -43,7 +42,6 @@ class FlutterQjsPlugin: FlutterPlugin, MethodCallHandler {
JniBridge.instance.call(engine, function, args, ResultWrapper(handler, result))
} else if (call.method == "close") {
val engine: Long = call.arguments<Long>()
println(engine)
JniBridge.instance.close(engine)
result.success(null)
} else {

View File

@@ -3,7 +3,7 @@
* @Author: ekibun
* @Date: 2020-08-08 10:30:59
* @LastEditors: ekibun
* @LastEditTime: 2020-08-20 11:11:30
* @LastEditTime: 2020-08-26 23:35:20
*/
#pragma once
@@ -53,7 +53,8 @@ namespace qjs
void handleException(qjs::Value exc)
{
std::cout << getStackTrack(exc) << std::endl;
printf("%s", getStackTrack(exc).c_str());
std::cout << std::endl;
}
public:
@@ -125,7 +126,7 @@ namespace qjs
if (err <= 0)
{
if (err < 0)
std::cout << getStackTrack(ctx.getException()) << std::endl;
handleException(ctx.getException());
break;
}
}

View File

@@ -37,12 +37,6 @@
#include <malloc.h>
#endif
#if defined(__ANDROID__)
#include <android/log.h>
#undef printf
#define printf(...) __android_log_print(ANDROID_LOG_INFO, "qjs", __VA_ARGS__)
#endif
#ifdef _MSC_VER
#include <WinSock2.h>
@@ -1704,7 +1698,7 @@ static inline size_t js_def_malloc_usable_size(void *ptr)
return malloc_size(ptr);
#elif defined(_WIN32)
return _msize(ptr);
#elif defined(EMSCRIPTEN)
#elif defined(EMSCRIPTEN) || defined(__ANDROID__)
return 0;
#elif defined(__linux__)
return malloc_usable_size(ptr);
@@ -1778,7 +1772,7 @@ static const JSMallocFunctions def_malloc_funcs = {
malloc_size,
#elif defined(_WIN32)
(size_t (*)(const void *))_msize,
#elif defined(EMSCRIPTEN)
#elif defined(EMSCRIPTEN) || defined(__ANDROID__)
NULL,
#elif defined(__linux__)
(size_t (*)(const void *))malloc_usable_size,

View File

@@ -28,6 +28,11 @@
#include <stdio.h>
#include <stdint.h>
#if defined(__ANDROID__)
#include <android/log.h>
#define printf(...) __android_log_print(ANDROID_LOG_INFO, "qjs", __VA_ARGS__)
#endif
#ifdef __cplusplus
extern "C" {
#endif

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

View File

@@ -1,13 +0,0 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=C\:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2019.3.2/jbr
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

View File

@@ -1,2 +0,0 @@
connection.project.dir=..
eclipse.preferences.version=1

View File

@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
compileSdkVersion 29
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
@@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "soko.ekibun.example"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

View File

@@ -1,6 +0,0 @@
package soko.ekibun.flutter_qjs_example
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}

View File

@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true

View File

@@ -18,7 +18,7 @@ endif()
# Compilation settings that should be applied to most targets.
function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_17)
target_compile_features(${TARGET} PUBLIC cxx_std_14)
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")

View File

@@ -75,7 +75,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.3"
version: "0.0.4"
flutter_test:
dependency: "direct dev"
description: flutter

View File

@@ -3,7 +3,7 @@
* @Author: ekibun
* @Date: 2020-08-08 08:29:09
* @LastEditors: ekibun
* @LastEditTime: 2020-08-20 14:43:40
* @LastEditTime: 2020-08-26 23:11:10
*/
import 'dart:async';
import 'dart:io';
@@ -24,7 +24,6 @@ class FlutterJs {
_ensureEngine() async {
if (_engine == null) {
_engine = await _FlutterJs.instance._channel.invokeMethod("createEngine");
print(_engine);
}
}

View File

@@ -22,6 +22,7 @@ add_library(${PLUGIN_NAME} SHARED
)
apply_standard_settings(${PLUGIN_NAME})
target_compile_features(${PLUGIN_NAME} PUBLIC cxx_std_17)
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)

View File

@@ -1,6 +1,6 @@
name: flutter_qjs
description: This plugin is a simple js engine for flutter using the `quickjs` project. Plugin currently supports Windows, Linux, and Android.
version: 0.0.3
version: 0.0.4
homepage: https://github.com/ekibun/flutter_qjs
environment: