checkpoint
This commit is contained in:
parent
a39b38cc16
commit
5298fc3fcf
@ -55,14 +55,13 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# install android targets
|
# install targets
|
||||||
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
|
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
|
||||||
|
|
||||||
# install cargo ndk
|
# install cargo packages
|
||||||
cargo install cargo-ndk
|
cargo install wasm-bindgen-cli
|
||||||
cargo install cargo-apk
|
|
||||||
|
|
||||||
# Ensure packages are installed
|
# Ensure packages are installed
|
||||||
sudo apt-get install libc6-dev-i386 libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 openjdk-11-jdk llvm
|
sudo apt-get install libc6-dev-i386 libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 openjdk-11-jdk llvm wabt
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,15 +6,19 @@ if [ ! "$(uname)" == "Darwin" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# install android targets
|
# install targets
|
||||||
rustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-darwin x86_64-apple-ios
|
rustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-darwin x86_64-apple-ios
|
||||||
|
|
||||||
|
# install cargo packages
|
||||||
|
cargo install wasm-bindgen-cli
|
||||||
|
|
||||||
|
# install bitcode compatible ios toolchain
|
||||||
echo Manual Step:
|
echo Manual Step:
|
||||||
echo install +ios-arm64-1.57.0 toolchain for bitcode from https://github.com/getditto/rust-bitcode/releases/latest and unzip
|
echo install +ios-arm64-1.57.0 toolchain for bitcode from https://github.com/getditto/rust-bitcode/releases/latest and unzip
|
||||||
echo xattr -d -r com.apple.quarantine .
|
echo xattr -d -r com.apple.quarantine .
|
||||||
echo ./install.sh
|
echo ./install.sh
|
||||||
|
|
||||||
# Ensure brew is installed
|
# ensure brew is installed
|
||||||
if command -v brew &> /dev/null; then
|
if command -v brew &> /dev/null; then
|
||||||
echo '[X] brew is available in the path'
|
echo '[X] brew is available in the path'
|
||||||
else
|
else
|
||||||
@ -22,7 +26,7 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure xcode is installed
|
# ensure xcode is installed
|
||||||
if command -v xcode-select &> /dev/null; then
|
if command -v xcode-select &> /dev/null; then
|
||||||
echo '[X] XCode is available in the path'
|
echo '[X] XCode is available in the path'
|
||||||
else
|
else
|
||||||
@ -30,10 +34,10 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure we have command line tools
|
# ensure we have command line tools
|
||||||
xcode-select --install
|
xcode-select --install
|
||||||
|
|
||||||
# Ensure packages are installed
|
# ensure packages are installed
|
||||||
if [ "$BREW_USER" == "" ]; then
|
if [ "$BREW_USER" == "" ]; then
|
||||||
BREW_USER=`ls -lad /opt/homebrew/. | cut -d\ -f4`
|
BREW_USER=`ls -lad /opt/homebrew/. | cut -d\ -f4`
|
||||||
echo "Must sudo to homebrew user \"$BREW_USER\" to install capnp package:"
|
echo "Must sudo to homebrew user \"$BREW_USER\" to install capnp package:"
|
||||||
|
@ -1484,9 +1484,6 @@ impl RPCProcessor {
|
|||||||
let own_peer_info = self
|
let own_peer_info = self
|
||||||
.routing_table()
|
.routing_table()
|
||||||
.get_own_peer_info(self.default_peer_scope);
|
.get_own_peer_info(self.default_peer_scope);
|
||||||
if own_peer_info.dial_infos.is_empty() {
|
|
||||||
return Err(rpc_error_internal("No valid public dial info for own node"));
|
|
||||||
}
|
|
||||||
|
|
||||||
encode_peer_info(&own_peer_info, &mut peer_info_builder)?;
|
encode_peer_info(&own_peer_info, &mut peer_info_builder)?;
|
||||||
|
|
||||||
|
@ -89,10 +89,11 @@ class _MyAppState extends State<MyApp> with UiLoggy {
|
|||||||
// Platform messages may fail, so we use a try/catch PlatformException.
|
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||||
// We also handle the message potentially returning null.
|
// We also handle the message potentially returning null.
|
||||||
try {
|
try {
|
||||||
veilidVersion = await Veilid.instance.veilidVersionString();
|
veilidVersion = Veilid.instance.veilidVersionString();
|
||||||
} on Exception {
|
} on Exception {
|
||||||
veilidVersion = 'Failed to get veilid version.';
|
veilidVersion = 'Failed to get veilid version.';
|
||||||
}
|
}
|
||||||
|
print("veilidVersionString $veilidVersion");
|
||||||
|
|
||||||
// In case of hot restart shut down first
|
// In case of hot restart shut down first
|
||||||
try {
|
try {
|
||||||
|
@ -149,13 +149,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.7.0"
|
version: "1.7.0"
|
||||||
mutex:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: mutex
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "3.0.0"
|
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -308,13 +301,6 @@ packages:
|
|||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
wasm_interop:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: wasm_interop
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.1"
|
|
||||||
win32:
|
win32:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -31,8 +31,27 @@
|
|||||||
|
|
||||||
<title>veilid_example</title>
|
<title>veilid_example</title>
|
||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="manifest.json">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<!-- Load WASM modules -->
|
||||||
|
|
||||||
|
xxx figure out how to switch to debug, maybe do this from dart land
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
async function run() {
|
||||||
|
import * as veilid_wasm_module from './wasm/veilid_wasm.js';
|
||||||
|
// save the wasm exports
|
||||||
|
window.veilid_wasm = veilid_wasm_module;
|
||||||
|
// init the js module
|
||||||
|
await veilid_wasm_module.default();
|
||||||
|
// init the wasm library
|
||||||
|
await veilid_wasm_module.initialize_veilid_wasm();
|
||||||
|
}
|
||||||
|
run();
|
||||||
|
</script>
|
||||||
|
|
||||||
<!-- This script installs service_worker.js to provide PWA functionality to
|
<!-- This script installs service_worker.js to provide PWA functionality to
|
||||||
application. For more information, see:
|
application. For more information, see:
|
||||||
https://developers.google.com/web/fundamentals/primers/service-workers -->
|
https://developers.google.com/web/fundamentals/primers/service-workers -->
|
||||||
|
1
veilid-flutter/example/web/wasm
Symbolic link
1
veilid-flutter/example/web/wasm
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../target/wasm32-unknown-unknown/release/pkg
|
@ -996,6 +996,6 @@ abstract class Veilid {
|
|||||||
Future<void> changeLogLevel(VeilidConfigLogLevel logLevel);
|
Future<void> changeLogLevel(VeilidConfigLogLevel logLevel);
|
||||||
Future<void> shutdownVeilidCore();
|
Future<void> shutdownVeilidCore();
|
||||||
Future<String> debug(String command);
|
Future<String> debug(String command);
|
||||||
Future<String> veilidVersionString();
|
String veilidVersionString();
|
||||||
Future<VeilidVersion> veilidVersion();
|
VeilidVersion veilidVersion();
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ class VeilidFFI implements Veilid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String> veilidVersionString() async {
|
String veilidVersionString() {
|
||||||
final versionString = _veilidVersionString();
|
final versionString = _veilidVersionString();
|
||||||
String ret = versionString.toDartString();
|
String ret = versionString.toDartString();
|
||||||
_freeString(versionString);
|
_freeString(versionString);
|
||||||
@ -334,7 +334,7 @@ class VeilidFFI implements Veilid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<VeilidVersion> veilidVersion() async {
|
VeilidVersion veilidVersion() {
|
||||||
final version = _veilidVersion();
|
final version = _veilidVersion();
|
||||||
return VeilidVersion(
|
return VeilidVersion(
|
||||||
version.major,
|
version.major,
|
||||||
|
@ -1,81 +1,76 @@
|
|||||||
import 'veilid.dart';
|
import 'veilid.dart';
|
||||||
|
|
||||||
import 'dart:js';
|
import 'dart:html' as html;
|
||||||
import 'dart:js_util';
|
import 'dart:js' as js;
|
||||||
|
import 'dart:js_util' as js_util;
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:flutter/services.dart' show NetworkAssetBundle;
|
|
||||||
import 'package:wasm_interop/wasm_interop.dart';
|
|
||||||
import 'package:mutex/mutex.dart';
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Veilid getVeilid() => VeilidJS();
|
Veilid getVeilid() => VeilidJS();
|
||||||
|
|
||||||
Instance? _wasmInstance;
|
Object wasm = js_util.getProperty(html.window, "veilid_wasm");
|
||||||
final _wasmInstanceMutex = Mutex();
|
|
||||||
|
|
||||||
Future<Instance> getWasmInstance() async {
|
Future<T> _wrapApiPromise<T>(Object p) {
|
||||||
await _wasmInstanceMutex.acquire();
|
return js_util.promiseToFuture(p).then((value) => value as T).catchError(
|
||||||
var _wi = _wasmInstance;
|
(error) => Future<T>.error(
|
||||||
if (_wi == null) {
|
VeilidAPIException.fromJson(jsonDecode(error as String))));
|
||||||
final bytes = await http???.get(Uri.parse("/wasm/veilid_wasm.wasm"));
|
|
||||||
_wi = await Instance.fromBufferAsync(bytes.buffer);
|
|
||||||
_wasmInstance = _wi;
|
|
||||||
}
|
|
||||||
_wasmInstanceMutex.release();
|
|
||||||
return _wi;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class VeilidJS implements Veilid {
|
class VeilidJS implements Veilid {
|
||||||
@override
|
@override
|
||||||
Stream<VeilidUpdate> startupVeilidCore(VeilidConfig config) async* {
|
Stream<VeilidUpdate> startupVeilidCore(VeilidConfig config) async* {
|
||||||
var wasm = (await getWasmInstance());
|
|
||||||
var streamController = StreamController<VeilidUpdate>();
|
var streamController = StreamController<VeilidUpdate>();
|
||||||
await promiseToFuture(
|
updateCallback(String update) {
|
||||||
wasm.functions["startup_veilid_core"]!.call((String update) {
|
var updateJson = jsonDecode(update);
|
||||||
streamController.add(VeilidUpdate.fromJson(jsonDecode(update)));
|
if (updateJson["kind"] == "Shutdown") {
|
||||||
}, jsonEncode(config.json, toEncodable: veilidApiToEncodable)));
|
streamController.close();
|
||||||
|
} else {
|
||||||
|
var update = VeilidUpdate.fromJson(updateJson);
|
||||||
|
streamController.add(update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _wrapApiPromise(js_util.callMethod(wasm, "startup_veilid_core", [
|
||||||
|
js.allowInterop(updateCallback),
|
||||||
|
jsonEncode(config.json, toEncodable: veilidApiToEncodable)
|
||||||
|
]));
|
||||||
yield* streamController.stream;
|
yield* streamController.stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<VeilidState> getVeilidState() async {
|
Future<VeilidState> getVeilidState() async {
|
||||||
var wasm = (await getWasmInstance());
|
return VeilidState.fromJson(jsonDecode(await _wrapApiPromise(
|
||||||
return VeilidState.fromJson(jsonDecode(
|
js_util.callMethod(wasm, "get_veilid_state", []))));
|
||||||
await promiseToFuture(wasm.functions["get_veilid_state"]!.call())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> changeLogLevel(VeilidConfigLogLevel logLevel) async {
|
Future<void> changeLogLevel(VeilidConfigLogLevel logLevel) {
|
||||||
var wasm = (await getWasmInstance());
|
return _wrapApiPromise(js_util.callMethod(wasm, "change_log_level",
|
||||||
await promiseToFuture(wasm.functions["change_log_level"]!
|
[jsonEncode(logLevel.json, toEncodable: veilidApiToEncodable)]));
|
||||||
.call(jsonEncode(logLevel.json, toEncodable: veilidApiToEncodable)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> shutdownVeilidCore() async {
|
Future<void> shutdownVeilidCore() {
|
||||||
var wasm = (await getWasmInstance());
|
return _wrapApiPromise(
|
||||||
await promiseToFuture(wasm.functions["shutdown_veilid_core"]!.call());
|
js_util.callMethod(wasm, "shutdown_veilid_core", []));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String> debug(String command) async {
|
Future<String> debug(String command) {
|
||||||
var wasm = (await getWasmInstance());
|
return _wrapApiPromise(js_util.callMethod(wasm, "debug", [command]));
|
||||||
return await promiseToFuture(wasm.functions["debug"]!.call(command));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String> veilidVersionString() async {
|
String veilidVersionString() {
|
||||||
var wasm = (await getWasmInstance());
|
return js_util.callMethod(wasm, "veilid_version_string", []);
|
||||||
return await promiseToFuture(wasm.functions["debug"]!.call());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<VeilidVersion> veilidVersion() async {
|
VeilidVersion veilidVersion() {
|
||||||
var wasm = (await getWasmInstance());
|
var jsonVersion =
|
||||||
var jsonVersion = jsonDecode(
|
jsonDecode(js_util.callMethod(wasm, "veilid_version", []));
|
||||||
await promiseToFuture(wasm.functions["get_veilid_state"]!.call()));
|
|
||||||
return VeilidVersion(
|
return VeilidVersion(
|
||||||
jsonVersion["major"], jsonVersion["minor"], jsonVersion["patch"]);
|
jsonVersion["major"], jsonVersion["minor"], jsonVersion["patch"]);
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@ dependencies:
|
|||||||
change_case: ^1.0.1
|
change_case: ^1.0.1
|
||||||
path_provider: ^2.0.9
|
path_provider: ^2.0.9
|
||||||
path: ^1.8.0
|
path: ^1.8.0
|
||||||
wasm_interop: ^2.0.1
|
|
||||||
mutex: ^3.0.0
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
@ -138,7 +138,7 @@ pub fn get_veilid_state() -> Promise {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_namespace = veilid)]
|
#[wasm_bindgen()]
|
||||||
pub fn change_log_level(log_level: String) -> Promise {
|
pub fn change_log_level(log_level: String) -> Promise {
|
||||||
wrap_api_future(async move {
|
wrap_api_future(async move {
|
||||||
let veilid_api = get_veilid_api()?;
|
let veilid_api = get_veilid_api()?;
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
|
||||||
|
pushd $SCRIPTDIR &> /dev/null
|
||||||
|
|
||||||
if [[ "$1" == "release" ]]; then
|
if [[ "$1" == "release" ]]; then
|
||||||
RELEASE=-r
|
OUTPUTDIR=../target/wasm32-unknown-unknown/release/pkg
|
||||||
GENERATE_SOURCE_MAP=
|
INPUTDIR=../target/wasm32-unknown-unknown/release
|
||||||
|
|
||||||
|
cargo build --target wasm32-unknown-unknown --release
|
||||||
|
mkdir -p $OUTPUTDIR
|
||||||
|
wasm-bindgen --out-dir $OUTPUTDIR --target web --no-typescript $INPUTDIR/veilid_wasm.wasm
|
||||||
|
wasm-strip $OUTPUTDIR/veilid_wasm_bg.wasm
|
||||||
else
|
else
|
||||||
RELEASE=
|
OUTPUTDIR=../target/wasm32-unknown-unknown/debug/pkg
|
||||||
RUSTFLAGS="-O -g"
|
INPUTDIR=../target/wasm32-unknown-unknown/debug
|
||||||
GENERATE_SOURCE_MAP="./wasm-sourcemap.py ../target/wasm32-unknown-unknown/debug/veilid_wasm.wasm -o ../target/wasm32-unknown-unknown/debug/veilid_wasm.wasm.map --dwarfdump `which llvm-dwarfdump`"
|
|
||||||
|
RUSTFLAGS="-O -g" cargo build --target wasm32-unknown-unknown
|
||||||
|
mkdir -p $OUTPUTDIR
|
||||||
|
wasm-bindgen --out-dir $OUTPUTDIR --target web --no-typescript --keep-debug --debug $INPUTDIR/veilid_wasm.wasm
|
||||||
|
./wasm-sourcemap.py $OUTPUTDIR/veilid_wasm_bg.wasm -o $OUTPUTDIR/veilid_wasm_bg.wasm.map --dwarfdump `which llvm-dwarfdump`
|
||||||
|
wasm-strip $OUTPUTDIR/veilid_wasm_bg.wasm
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pushd $SCRIPTDIR 2> /dev/null
|
popd &> /dev/null
|
||||||
cargo build --target wasm32-unknown-unknown $RELEASE
|
|
||||||
$GENERATE_SOURCE_MAP
|
|
||||||
popd 2> /dev/null
|
|
||||||
|
Loading…
Reference in New Issue
Block a user