Merge pull request #21 from pdckxd/main

#19 - [FR] Successfully to build workable version for windows (Rust t…
This commit is contained in:
AppFlowy.IO 2021-11-17 22:07:42 +08:00 committed by GitHub
commit 6536098b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 212 additions and 13 deletions

56
doc/BUILD_ON_WNIDOWS.md Normal file
View File

@ -0,0 +1,56 @@
## How to build on Windows 10, please follow these simple steps.
**Step 1:**
```shell
git clone https://github.com/AppFlowy-IO/appflowy.git
```
**Step 2:**
Note: Please run the commands in windows cmd rather than powershell
1. Install Visual Studio 2019 community. See: https://visualstudio.microsoft.com/downloads/
- Note: Didn't test Visual Studio 2022. It should also work.
2. Install choco according to https://chocolatey.org/install
3. Install vcpkg according to https://github.com/microsoft/vcpkg#quick-start-windows. Make sure to add vcpkg installation folder to PATH env var.
4. Install flutter according to https://docs.flutter.dev/get-started/install/windows
```shell
flutter channel dev
```
5. Install rust
```shell
choco install rustup.install
rustup toolchain install nightly
```
6. Install cargo make
```shell
cd appflowy
cargo install --force cargo-make
```
7. Install duckscript
```shell
cargo install --force duckscript_cli
```
8. Check pre-request
```shell
cargo make flowy_dev
```
9. Generate protobuf for dart
```shell
cargo make -p development-windows pb
```
10. Build flowy-sdk-dev (dart-ffi)
```shell
cargo make --profile development-windows flowy-sdk-dev
```
11. Build app_flowy
```shell
cargo make -p development-windows appflowy-windows
```
**Step 3:** Server side application
Note: You can launch postgresql server by using docker container
TBD

View File

@ -12,7 +12,7 @@ syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "fu
tera = { version = "1.5.0" } tera = { version = "1.5.0" }
log = "0.4.11" log = "0.4.11"
env_logger = "0.8.2" env_logger = "0.8.2"
shell = { git="https://github.com/google/rust-shell.git"} #shell = { git="https://github.com/google/rust-shell.git"}
cmd_lib = "1.1" cmd_lib = "1.1"
flowy-ast = { path = "../../rust-lib/flowy-ast" } flowy-ast = { path = "../../rust-lib/flowy-ast" }
console = "0.14.0" console = "0.14.0"

View File

@ -159,10 +159,7 @@ fn run_flutter_protoc(crate_infos: &Vec<CrateProtoInfo>, package_info: &FlutterP
fn remove_everything_in_dir(dir: &str) { fn remove_everything_in_dir(dir: &str) {
if Path::new(dir).exists() { if Path::new(dir).exists() {
if cmd_lib::run_cmd! { if std::fs::remove_dir_all(dir).is_err()
rm -rf ${dir}
}
.is_err()
{ {
panic!("Reset protobuf directory failed") panic!("Reset protobuf directory failed")
}; };

View File

@ -97,8 +97,13 @@ pub fn get_tera(directory: &str) -> Tera {
.as_path() .as_path()
.display() .display()
.to_string(); .to_string();
let mut template_path = format!("{}/**/*.tera", root_absolute_path);
if cfg!(windows)
{
// remove "\\?\" prefix on windows
template_path = format!("{}/**/*.tera", &root_absolute_path[4..]);
}
let template_path = format!("{}/**/*.tera", root_absolute_path);
match Tera::new(template_path.as_ref()) { match Tera::new(template_path.as_ref()) {
Ok(t) => t, Ok(t) => t,
Err(e) => { Err(e) => {

View File

@ -1,19 +1,79 @@
[tasks.flowy_dev] [tasks.flowy_dev]
run_task = { name = ["install_targets","install_diesel", "install_protobuf"] } run_task = { name = ["install_prerequests","install_diesel", "install_protobuf"] }
[tasks.install_windows_deps.windows]
dependencies=["check_duckscript_installation", "check_visual_studio_installation", "check_vcpkg", "install_rust_vcpkg_cli"]
[tasks.check_visual_studio_installation.windows]
script = """
output = exec powershell -Command "Get-CimInstance MSFT_VSInstance | select -ExpandProperty Version"
stdout = set ${output.stdout}
pos = last_indexof ${stdout} .
new_str = substring ${stdout} 0 ${pos}
newer = semver_is_newer ${new_str} 16.11.0
assert ${newer} "Visual studio 2019 is not installed or version is lower than 16.11.0"
"""
script_runner = "@duckscript"
[tasks.check_duckscript_installation.windows]
script = """
@echo off
@duck -h > nul
if %errorlevel% GTR 0 (
echo Please install duckscript at first: cargo install --force duckscript_cli
exit -1
)
"""
[tasks.check_vcpkg.windows]
script = """
ret = which vcpkg
if is_empty ${ret}
echo "Please install vcpkg on windows at first. Make sure to put it into PATH env var"
echo "See: https://github.com/microsoft/vcpkg#quick-start-windows"
exit -1
end
"""
script_runner = "@duckscript"
[tasks.install_rust_vcpkg_cli.windows]
script = """
exec cargo install vcpkg_cli
output = exec vcpkg_cli probe sqlite3
stdout = set ${output.stdout}
stderr = set ${output.stderr}
ret = indexof ${stdout} "Failed:"
assert_eq ${ret} "" ${stdout}
"""
script_runner = "@duckscript"
[tasks.install_diesel] [tasks.install_diesel]
script = """ script = """
cargo install diesel_cli --no-default-features --features sqlite cargo install diesel_cli --no-default-features --features sqlite
""" """
[tasks.install_diesel.windows]
script = """
vcpkg install sqlite3:x64-windows-static-md
cargo install diesel_cli --no-default-features --features sqlite
"""
dependencies = ["check_vcpkg"]
[tasks.install_targets] [tasks.install_targets]
script = """ script = """
rustup target add x86_64-apple-ios rustup target add x86_64-apple-ios
rustup target add x86_64-apple-darwin rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-ios rustup target add aarch64-apple-ios
rustup target add aarch64-apple-darwin rustup target add aarch64-apple-darwin
rustup target add x86_64-pc-windows-msvc
""" """
[tasks.install_prerequests]
dependencies=["install_targets"]
[tasks.install_prerequests.windows]
dependencies=["install_targets", "install_windows_deps"]
[tasks.install_protobuf] [tasks.install_protobuf]
script = """ script = """
# Custom dart: # Custom dart:
@ -27,6 +87,24 @@ dart pub global activate protoc_plugin
cargo install --version 2.20.0 protobuf-codegen cargo install --version 2.20.0 protobuf-codegen
""" """
[tasks.install_protobuf.windows]
script = """
ret = which dart
if is_empty ${ret}
echo Please make sure flutter/dart is properly installed and in PATH env var
exit -1
end
ret = which protoc-gen-dart
if is_empty ${ret}
dart pub global activate protoc_plugin
home_dir = get_home_dir
echo Please add '${home_dir}\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\bin' into PATH env var
exit -1
end
exec cargo install --version 2.22.1 protobuf-codegen
"""
script_runner = "@duckscript"
[tasks.install_tools] [tasks.install_tools]
script = """ script = """
rustup component add rustfmt rustup component add rustfmt
@ -64,9 +142,12 @@ brew install fish
[tasks.install_flutter] [tasks.install_flutter]
script = """ script = """
echo "[❤️] Follow the https://flutter.dev/docs/get-started/install instructions to install the flutter, skip if you already installed." ret = which flutter
echo "Switch to dev channel with command: flutter channel dev" if is_empty ${ret}
echo "[❤️] Follow the https://flutter.dev/docs/get-started/install instructions to install the flutter, skip if you already installed."
echo "Switch to dev channel with command: flutter channel dev"
exit -1
end
""" """
script_runner = "@duckscript"

View File

@ -9,7 +9,7 @@ script_runner = "@shell"
[tasks.appflowy-windows] [tasks.appflowy-windows]
dependencies = ["flowy-sdk-release"] dependencies = ["flowy-sdk-release"]
run_task = { name = ["flutter-build", "copy-to-product"] } run_task = { name = ["flutter-build", "copy-dll-to-build-folder", "copy-to-product"] }
[tasks.copy-to-product] [tasks.copy-to-product]
mac_alias = "copy-to-product-macos" mac_alias = "copy-to-product-macos"
@ -32,12 +32,23 @@ script = [
] ]
script_runner = "@shell" script_runner = "@shell"
[tasks.copy-dll-to-build-folder]
script = [
"""
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} \
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/build/${TARGET_OS}/runner/${BUILD_FLAG}/${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT}
""",
]
script_runner = "@duckscript"
[tasks.copy-to-product-windows] [tasks.copy-to-product-windows]
script = [ script = [
""" """
# TODO:
echo TBD...
""", """,
] ]
script_runner = "@powershell" script_runner = "@duckscript"
[tasks.flutter-build] [tasks.flutter-build]
@ -51,6 +62,17 @@ script = [
] ]
script_runner = "@shell" script_runner = "@shell"
[tasks.flutter-build.windows]
script = [
"""
cd app_flowy
exec cmd.exe /c flutter clean
exec cmd.exe /c flutter pub get
exec cmd.exe /c flutter build ${TARGET_OS} --${BUILD_FLAG}
""",
]
script_runner = "@duckscript"
[tasks.freeze_setup] [tasks.freeze_setup]
script = [ script = [
""" """

View File

@ -23,6 +23,27 @@ script = [
script_runner = "@shell" script_runner = "@shell"
[tasks.gen_pb_file.windows]
script = [
"""
flowy_tool=set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/scripts/flowy-tool/Cargo.toml
rust_source=set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/
rust_lib=set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib
flutter_lib=set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages
derive_meta=set ${rust_lib}/flowy-derive/src/derive_cache/derive_cache.rs
flutter_package_lib=set ${flutter_lib}/flowy_sdk/lib
exec cmd /c cargo run \
--manifest-path ${flowy_tool} pb-gen \
--rust_source=${rust_source} \
--derive_meta=${derive_meta} \
--flutter_package_lib=${flutter_package_lib}
""",
]
script_runner = "@duckscript"
[tasks.gen_dart_event] [tasks.gen_dart_event]
script = [ script = [
""" """
@ -39,3 +60,20 @@ script = [
""", """,
] ]
script_runner = "@shell" script_runner = "@shell"
[tasks.gen_dart_event.windows]
script = [
"""
flowy_tool=set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/scripts/flowy-tool/Cargo.toml
flutter_lib=set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages
rust_source=set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/
output=set ${flutter_lib}/flowy_sdk/lib/dispatch/code_gen.dart
exec cmd.exe /c cargo run \
--manifest-path ${flowy_tool} dart-event \
--rust_source=${rust_source} \
--output=${output}
""",
]
script_runner = "@duckscript"