liftinstall/build.rs

122 lines
3.2 KiB
Rust
Raw Normal View History

#[cfg(windows)]
extern crate winres;
2018-08-06 10:51:59 +00:00
#[cfg(windows)]
extern crate cc;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate toml;
Update config files for v7 (#12) * platform: fix build on Linux and update web-view * deps: replace xz-decom with xz2 and update deps * platform: fix regression... ... that prevents the build on Windows * linux: implement platform-dependent functions * travis: add macos and windows CI * travis: use official Rust Docker image * Update Cargo.lock for new version * Break apart REST into separate services This cleans up locking, ensures consistent futures for all endpoints and enhances code re-use. * Clean up codebase, fixing minor errors * Update packages, use async client for downloading config While this has a hell of a lot more boilerplate, this is quite a bit cleaner. * Add explicit 'dyn's as per Rust nightly requirements * Migrate self updating functions to own module * Migrate assets to server module * Use patched web-view to fix dialogs, remove nfd * Implement basic dark mode * Revert window.close usage * ui: split files and use Webpack * frontend: ui: include prebuilt assets... ... and update rust side stuff * build: integrate webpack building into build.rs * Polish Vue UI split * Add instructions for node + yarn * native: fix uninstall self-destruction behavior...... by not showing the command prompt window and fork-spawning the cmd * native: deal with Unicode issues in native APIs * native: further improve Unicode support on Windows * travis: add cache and fix issues * ui: use Buefy components to... ... beautify the UI * ui: makes error message selectable * Make launcher mode behaviour more robust * Fix error display on launcher pages * Correctly handle exit on error * Bump installer version
2019-07-05 01:23:16 +00:00
extern crate which;
2018-08-07 10:17:01 +00:00
use std::env;
use std::path::PathBuf;
use std::fs::copy;
use std::fs::File;
use std::io::Read;
Update config files for v7 (#12) * platform: fix build on Linux and update web-view * deps: replace xz-decom with xz2 and update deps * platform: fix regression... ... that prevents the build on Windows * linux: implement platform-dependent functions * travis: add macos and windows CI * travis: use official Rust Docker image * Update Cargo.lock for new version * Break apart REST into separate services This cleans up locking, ensures consistent futures for all endpoints and enhances code re-use. * Clean up codebase, fixing minor errors * Update packages, use async client for downloading config While this has a hell of a lot more boilerplate, this is quite a bit cleaner. * Add explicit 'dyn's as per Rust nightly requirements * Migrate self updating functions to own module * Migrate assets to server module * Use patched web-view to fix dialogs, remove nfd * Implement basic dark mode * Revert window.close usage * ui: split files and use Webpack * frontend: ui: include prebuilt assets... ... and update rust side stuff * build: integrate webpack building into build.rs * Polish Vue UI split * Add instructions for node + yarn * native: fix uninstall self-destruction behavior...... by not showing the command prompt window and fork-spawning the cmd * native: deal with Unicode issues in native APIs * native: further improve Unicode support on Windows * travis: add cache and fix issues * ui: use Buefy components to... ... beautify the UI * ui: makes error message selectable * Make launcher mode behaviour more robust * Fix error display on launcher pages * Correctly handle exit on error * Bump installer version
2019-07-05 01:23:16 +00:00
use std::process::Command;
2018-08-07 10:17:01 +00:00
2018-08-08 02:47:32 +00:00
use std::env::consts::OS;
/// Describes the application itself.
#[derive(Debug, Deserialize)]
pub struct BaseAttributes {
pub name: String,
pub target_url: String,
}
#[cfg(windows)]
fn handle_binary(config: &BaseAttributes) {
let mut res = winres::WindowsResource::new();
Update config files for v7 (#12) * platform: fix build on Linux and update web-view * deps: replace xz-decom with xz2 and update deps * platform: fix regression... ... that prevents the build on Windows * linux: implement platform-dependent functions * travis: add macos and windows CI * travis: use official Rust Docker image * Update Cargo.lock for new version * Break apart REST into separate services This cleans up locking, ensures consistent futures for all endpoints and enhances code re-use. * Clean up codebase, fixing minor errors * Update packages, use async client for downloading config While this has a hell of a lot more boilerplate, this is quite a bit cleaner. * Add explicit 'dyn's as per Rust nightly requirements * Migrate self updating functions to own module * Migrate assets to server module * Use patched web-view to fix dialogs, remove nfd * Implement basic dark mode * Revert window.close usage * ui: split files and use Webpack * frontend: ui: include prebuilt assets... ... and update rust side stuff * build: integrate webpack building into build.rs * Polish Vue UI split * Add instructions for node + yarn * native: fix uninstall self-destruction behavior...... by not showing the command prompt window and fork-spawning the cmd * native: deal with Unicode issues in native APIs * native: further improve Unicode support on Windows * travis: add cache and fix issues * ui: use Buefy components to... ... beautify the UI * ui: makes error message selectable * Make launcher mode behaviour more robust * Fix error display on launcher pages * Correctly handle exit on error * Bump installer version
2019-07-05 01:23:16 +00:00
res.set_icon("ui/public/favicon.ico");
res.set(
"FileDescription",
&format!("Interactive installer for {}", config.name),
);
res.set("ProductName", &format!("{} installer", config.name));
res.set(
"OriginalFilename",
&format!("{}_installer.exe", config.name),
);
res.compile().expect("Failed to generate metadata");
2018-08-06 10:51:59 +00:00
cc::Build::new()
.cpp(true)
.file("src/native/interop.cpp")
.compile("interop");
}
#[cfg(not(windows))]
fn handle_binary(_config: &BaseAttributes) {}
2018-08-07 10:17:01 +00:00
fn main() {
let output_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
Update config files for v7 (#12) * platform: fix build on Linux and update web-view * deps: replace xz-decom with xz2 and update deps * platform: fix regression... ... that prevents the build on Windows * linux: implement platform-dependent functions * travis: add macos and windows CI * travis: use official Rust Docker image * Update Cargo.lock for new version * Break apart REST into separate services This cleans up locking, ensures consistent futures for all endpoints and enhances code re-use. * Clean up codebase, fixing minor errors * Update packages, use async client for downloading config While this has a hell of a lot more boilerplate, this is quite a bit cleaner. * Add explicit 'dyn's as per Rust nightly requirements * Migrate self updating functions to own module * Migrate assets to server module * Use patched web-view to fix dialogs, remove nfd * Implement basic dark mode * Revert window.close usage * ui: split files and use Webpack * frontend: ui: include prebuilt assets... ... and update rust side stuff * build: integrate webpack building into build.rs * Polish Vue UI split * Add instructions for node + yarn * native: fix uninstall self-destruction behavior...... by not showing the command prompt window and fork-spawning the cmd * native: deal with Unicode issues in native APIs * native: further improve Unicode support on Windows * travis: add cache and fix issues * ui: use Buefy components to... ... beautify the UI * ui: makes error message selectable * Make launcher mode behaviour more robust * Fix error display on launcher pages * Correctly handle exit on error * Bump installer version
2019-07-05 01:23:16 +00:00
let current_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let ui_dir = current_dir.join("ui");
2018-08-07 10:17:01 +00:00
2018-08-08 02:47:32 +00:00
let os = OS.to_lowercase();
// Find target config
let target_config = PathBuf::from(format!("bootstrap.{}.toml", os));
2018-08-08 02:47:32 +00:00
if !target_config.exists() {
panic!(
"There is no config file specified for the platform: {:?}. \
Create a file named \"bootstrap.{}.toml\" in the root directory.",
2018-08-08 02:47:32 +00:00
os, os
);
}
// Read in the config for our own purposes
let file_contents = {
let mut file = File::open(&target_config).expect("Unable to open config file");
let mut buf = Vec::new();
file.read_to_end(&mut buf)
.expect("Unable to read config file contents");
buf
};
let config: BaseAttributes =
toml::from_slice(&file_contents).expect("Unable to parse config file");
handle_binary(&config);
// Copy for the main build
copy(&target_config, output_dir.join("bootstrap.toml")).expect("Unable to copy config file");
2018-08-08 02:47:32 +00:00
let yarn_binary =
which::which("yarn").expect("Failed to find yarn - please go ahead and install it!");
Update config files for v7 (#12) * platform: fix build on Linux and update web-view * deps: replace xz-decom with xz2 and update deps * platform: fix regression... ... that prevents the build on Windows * linux: implement platform-dependent functions * travis: add macos and windows CI * travis: use official Rust Docker image * Update Cargo.lock for new version * Break apart REST into separate services This cleans up locking, ensures consistent futures for all endpoints and enhances code re-use. * Clean up codebase, fixing minor errors * Update packages, use async client for downloading config While this has a hell of a lot more boilerplate, this is quite a bit cleaner. * Add explicit 'dyn's as per Rust nightly requirements * Migrate self updating functions to own module * Migrate assets to server module * Use patched web-view to fix dialogs, remove nfd * Implement basic dark mode * Revert window.close usage * ui: split files and use Webpack * frontend: ui: include prebuilt assets... ... and update rust side stuff * build: integrate webpack building into build.rs * Polish Vue UI split * Add instructions for node + yarn * native: fix uninstall self-destruction behavior...... by not showing the command prompt window and fork-spawning the cmd * native: deal with Unicode issues in native APIs * native: further improve Unicode support on Windows * travis: add cache and fix issues * ui: use Buefy components to... ... beautify the UI * ui: makes error message selectable * Make launcher mode behaviour more robust * Fix error display on launcher pages * Correctly handle exit on error * Bump installer version
2019-07-05 01:23:16 +00:00
// Build and deploy frontend files
Command::new(&yarn_binary)
.arg("--version")
.spawn()
.expect("Yarn could not be launched");
Command::new(&yarn_binary)
.arg("--cwd")
.arg(ui_dir.to_str().expect("Unable to covert path"))
.spawn()
.unwrap()
.wait()
.expect("Unable to install Node.JS dependencies using Yarn");
Update config files for v7 (#12) * platform: fix build on Linux and update web-view * deps: replace xz-decom with xz2 and update deps * platform: fix regression... ... that prevents the build on Windows * linux: implement platform-dependent functions * travis: add macos and windows CI * travis: use official Rust Docker image * Update Cargo.lock for new version * Break apart REST into separate services This cleans up locking, ensures consistent futures for all endpoints and enhances code re-use. * Clean up codebase, fixing minor errors * Update packages, use async client for downloading config While this has a hell of a lot more boilerplate, this is quite a bit cleaner. * Add explicit 'dyn's as per Rust nightly requirements * Migrate self updating functions to own module * Migrate assets to server module * Use patched web-view to fix dialogs, remove nfd * Implement basic dark mode * Revert window.close usage * ui: split files and use Webpack * frontend: ui: include prebuilt assets... ... and update rust side stuff * build: integrate webpack building into build.rs * Polish Vue UI split * Add instructions for node + yarn * native: fix uninstall self-destruction behavior...... by not showing the command prompt window and fork-spawning the cmd * native: deal with Unicode issues in native APIs * native: further improve Unicode support on Windows * travis: add cache and fix issues * ui: use Buefy components to... ... beautify the UI * ui: makes error message selectable * Make launcher mode behaviour more robust * Fix error display on launcher pages * Correctly handle exit on error * Bump installer version
2019-07-05 01:23:16 +00:00
Command::new(&yarn_binary)
.args(&[
"--cwd",
ui_dir.to_str().expect("Unable to covert path"),
"run",
"build",
"--dest",
output_dir
.join("static")
2018-08-07 10:17:01 +00:00
.to_str()
Update config files for v7 (#12) * platform: fix build on Linux and update web-view * deps: replace xz-decom with xz2 and update deps * platform: fix regression... ... that prevents the build on Windows * linux: implement platform-dependent functions * travis: add macos and windows CI * travis: use official Rust Docker image * Update Cargo.lock for new version * Break apart REST into separate services This cleans up locking, ensures consistent futures for all endpoints and enhances code re-use. * Clean up codebase, fixing minor errors * Update packages, use async client for downloading config While this has a hell of a lot more boilerplate, this is quite a bit cleaner. * Add explicit 'dyn's as per Rust nightly requirements * Migrate self updating functions to own module * Migrate assets to server module * Use patched web-view to fix dialogs, remove nfd * Implement basic dark mode * Revert window.close usage * ui: split files and use Webpack * frontend: ui: include prebuilt assets... ... and update rust side stuff * build: integrate webpack building into build.rs * Polish Vue UI split * Add instructions for node + yarn * native: fix uninstall self-destruction behavior...... by not showing the command prompt window and fork-spawning the cmd * native: deal with Unicode issues in native APIs * native: further improve Unicode support on Windows * travis: add cache and fix issues * ui: use Buefy components to... ... beautify the UI * ui: makes error message selectable * Make launcher mode behaviour more robust * Fix error display on launcher pages * Correctly handle exit on error * Bump installer version
2019-07-05 01:23:16 +00:00
.expect("Unable to convert path"),
])
.spawn()
.unwrap()
.wait()
.expect("Unable to build frontend assets using Webpack");
2018-08-07 10:17:01 +00:00
}