Skip to content

Commit

Permalink
Merge pull request #296 from cunarist/orgainze-codebase
Browse files Browse the repository at this point in the history
Orgainze codebase
  • Loading branch information
temeddix authored Feb 17, 2024
2 parents cc8b7ec + 1872afb commit 1e4fe41
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 18 deletions.
4 changes: 2 additions & 2 deletions documentation/docs/running-and-building.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ flutter build web

When deploying your web app, ensure that your web server is configured to include cross-origin-related HTTP headers in its responses. These headers enable web browsers using your website to gain access to `SharedArrayBuffer` web API, which is something similar to shared memory on the web.

- [`cross-origin-opener-policy`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy): `same-origin`
- [`cross-origin-embedder-policy`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy): `require-corp`.
- [`Cross-Origin-Opener-Policy`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy): `same-origin`
- [`Cross-Origin-Embedder-Policy`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy): `require-corp`.

Additionally, don't forget to specify the MIME type `application/wasm` for `.wasm` files within the server configuration to ensure optimal performance.
1 change: 1 addition & 0 deletions flutter_ffi_plugin/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lints/core.yaml
2 changes: 1 addition & 1 deletion flutter_ffi_plugin/bin/rinf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'src/helpers.dart';
import 'src/message.dart';

Future<void> main(List<String> args) async {
if (args.length == 0) {
if (args.isEmpty) {
print("No operation is provided.");
print("Use `rinf --help` to see all available operations.");
return;
Expand Down
12 changes: 10 additions & 2 deletions flutter_ffi_plugin/bin/src/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,16 @@ Future<void> buildWebassembly({bool isReleaseMode = false}) async {
await Process.run("cargo", ["install", "wasm-bindgen-cli"]);

// Verify Flutter SDK web server's response headers.
print("Patching Flutter SDK's web server with CORS HTTP headers.");
await patchServerHeaders();
try {
await patchServerHeaders();
print("Patched Flutter SDK's web server with CORS HTTP headers.");
} catch (error) {
print("Failed patching Flutter's web server with CORS HTTP headers.");
print("Try using the command below.");
print('flutter run' +
' --web-header=Cross-Origin-Opener-Policy=same-origin' +
' --web-header=Cross-Origin-Embedder-Policy=require-corp');
}

// Prepare the webassembly output path.
final flutterProjectPath = Directory.current;
Expand Down
12 changes: 6 additions & 6 deletions flutter_ffi_plugin/bin/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Future<void> generateMessageCode({
final subPath = entry.key;
final resourceNames = entry.value;
await Directory('$rustOutputPath$subPath').create(recursive: true);
if (resourceNames.length == 0) {
if (resourceNames.isEmpty) {
continue;
}
final protoPaths = <String>[];
Expand Down Expand Up @@ -148,7 +148,7 @@ Future<void> generateMessageCode({
final subPath = entry.key;
final resourceNames = entry.value;
await Directory('$dartOutputPath$subPath').create(recursive: true);
if (resourceNames.length == 0) {
if (resourceNames.isEmpty) {
continue;
}
final protoPaths = <String>[];
Expand Down Expand Up @@ -180,7 +180,7 @@ Future<void> generateMessageCode({
final subPath = entry.key;
final filesAndMarks = entry.value;
for (final entry in filesAndMarks.entries) {
if (entry.value.length == 0) {
if (entry.value.isEmpty) {
continue;
}
final filename = entry.key;
Expand Down Expand Up @@ -464,7 +464,7 @@ Future<void> patchServerHeaders() async {
var serverFileContent = await serverFile.readAsString();

// Check if the server already includes cross-origin HTTP headers.
if (serverFileContent.contains('cross-origin-opener-policy')) {
if (serverFileContent.contains('Cross-Origin-Opener-Policy')) {
return;
}

Expand All @@ -475,11 +475,11 @@ Future<void> patchServerHeaders() async {
);
lines.insert(serverDeclaredIndex + 1, """
httpServer.defaultResponseHeaders.add(
'cross-origin-opener-policy',
'Cross-Origin-Opener-Policy',
'same-origin',
);
httpServer.defaultResponseHeaders.add(
'cross-origin-embedder-policy',
'Cross-Origin-Embedder-Policy',
'require-corp',
);""");
serverFileContent = lines.join("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class AndroidEnvironment {

final cxxKey = 'CXX_${target.rust}';
final cxxValue = path.join(toolchainPath, 'clang++$exe');
final cxxfFlagsKey = 'CXXFLAGS_${target.rust}';
final cxxFlagsKey = 'CXXFLAGS_${target.rust}';
final cxxFlagsValue = targetArg;

final linkerKey =
Expand Down Expand Up @@ -152,7 +152,7 @@ class AndroidEnvironment {
ccKey: ccValue,
cfFlagsKey: cFlagsValue,
cxxKey: cxxValue,
cxxfFlagsKey: cxxFlagsValue,
cxxFlagsKey: cxxFlagsValue,
ranlibKey: ranlibValue,
rustFlagsKey: rustFlagsValue,
linkerKey: selfPath,
Expand Down
2 changes: 1 addition & 1 deletion flutter_ffi_plugin/cargokit/gradle/plugin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CargoKitPlugin implements Plugin<Project> {
}

def task = project.tasks.create(taskName, CargoKitBuildTask.class) {
buildMode = variant.name
buildMode = variant.buildType.name
buildDir = cargoBuildDir
outputDir = cargoOutputDir
ndkVersion = plugin.project.android.ndkVersion
Expand Down
8 changes: 7 additions & 1 deletion flutter_ffi_plugin/cargokit/run_build_tool.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down Expand Up @@ -42,6 +42,12 @@ void main(List<String> args) {
}
EOF

# Create alias for `shasum` if it does not exist and `sha1sum` exists
if ! [ -x "$(command -v shasum)" ] && [ -x "$(command -v sha1sum)" ]; then
shopt -s expand_aliases
alias shasum="sha1sum"
fi

# Dart run will not cache any package that has a path dependency, which
# is the case for our build_tool_runner. So instead we precompile the package
# ourselves.
Expand Down
4 changes: 2 additions & 2 deletions flutter_ffi_plugin/example/native/hub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ crate-type = ["lib", "cdylib", "staticlib"]
[dependencies]
rinf = "6.6.0"
prost = "0.12.3"
wasm-bindgen = "0.2.90"
tokio_with_wasm = "0.4.0"
wasm-bindgen = "0.2.91"
tokio_with_wasm = "0.4.1"
sample_crate = { path = "../sample_crate" }
1 change: 1 addition & 0 deletions flutter_ffi_plugin/lib/rinf.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// This module supports communication with Rust.
library;

import 'dart:typed_data';
import 'src/exports.dart';
Expand Down
3 changes: 3 additions & 0 deletions flutter_ffi_plugin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dependencies:
ffi: ^2.1.0
yaml: ^3.1.2

dev_dependencies:
lints: ^3.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
2 changes: 1 addition & 1 deletion rust_crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ allo-isolate = "0.1.24"

[target.'cfg(target_family = "wasm")'.dependencies]
js-sys = "0.3.67"
wasm-bindgen = "0.2.90"
wasm-bindgen = "0.2.91"

0 comments on commit 1e4fe41

Please sign in to comment.