Skip to content

Commit

Permalink
Review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
noituri committed Jan 5, 2024
1 parent 11b0108 commit c651562
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:

- name: shellcheck
run: |
shellcheck ./scripts/release.sh ./scripts/compositor_runtime_wrapper.sh
shellcheck ./scripts/release.sh ./src/bin/package_for_release/linux_runtime_wrapper.sh
11 changes: 6 additions & 5 deletions examples/web_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ fn main() {
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
);
ffmpeg_next::format::network::init();
let target_path = &std::env::current_exe()
.unwrap()
.parent()
.unwrap()
.join("..");

#[cfg(feature = "web_renderer")]
{
use compositor_chromium::cef::bundle_for_development;

let target_path = &std::env::current_exe()
.unwrap()
.parent()
.unwrap()
.join("..");
if let Err(err) = bundle_for_development(target_path) {
panic!(
"Build process helper first. For release profile use: cargo build -r --bin process_helper. {:?}",
Expand Down
7 changes: 7 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ cd "$ROOT_DIR/release_tmp"
gh run download "$WORKFLOW_RUN_ID" -n video_compositor_linux_x86_64.tar.gz
gh run download "$WORKFLOW_RUN_ID" -n video_compositor_darwin_x86_64.tar.gz
gh run download "$WORKFLOW_RUN_ID" -n video_compositor_darwin_aarch64.tar.gz
gh run download "$WORKFLOW_RUN_ID" -n video_compositor_with_web_rendering_linux_x86_64.tar.gz
gh run download "$WORKFLOW_RUN_ID" -n video_compositor_with_web_rendering_darwin_x86_64.tar.gz
gh run download "$WORKFLOW_RUN_ID" -n video_compositor_with_web_rendering_darwin_aarch64.tar.gz

gh release create "$RELEASE_TAG"
gh release upload "$RELEASE_TAG" video_compositor_linux_x86_64.tar.gz
gh release upload "$RELEASE_TAG" video_compositor_darwin_x86_64.tar.gz
gh release upload "$RELEASE_TAG" video_compositor_darwin_aarch64.tar.gz
gh release upload "$RELEASE_TAG" video_compositor_with_web_rendering_linux_x86_64.tar.gz
gh release upload "$RELEASE_TAG" video_compositor_with_web_rendering_darwin_x86_64.tar.gz
gh release upload "$RELEASE_TAG" video_compositor_with_web_rendering_darwin_aarch64.tar.gz

rm -rf "$ROOT_DIR/release_tmp"
30 changes: 22 additions & 8 deletions src/bin/package_for_release/bundle_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,30 @@ use std::process::Command;
use crate::utils;

const X86_TARGET: &str = "x86_64-unknown-linux-gnu";
const X86_OUTPUT_FILE: &str = "video_compositor_linux_x86_64.tar.gz";
const X86_WITH_WEB_RENDERING_OUTPUT_FILE: &str =
"video_compositor_with_web_rendering_linux_x86_64.tar.gz";

pub fn bundle_linux_app(enable_web_rendering: bool) -> Result<()> {
pub fn bundle_linux_app() -> Result<()> {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
);

info!("Bundling compositor without web rendering");
bundle_app(false)?;

info!("Bundling compositor with web rendering");
bundle_app(true)?;

Ok(())
}

fn bundle_app(enable_web_rendering: bool) -> Result<()> {
let root_dir_str = env!("CARGO_MANIFEST_DIR");
let root_dir: PathBuf = root_dir_str.into();
let release_dir = root_dir.join("target/x86_64-unknown-linux-gnu/release");
let tmp_dir = root_dir.join("video_compositor");

info!("Setting up tmp directory");
let _ = fs::remove_dir_all(&tmp_dir);
fs::create_dir_all(&tmp_dir)?;
utils::setup_bundle_dir(&tmp_dir);

info!("Build main_process binary.");
utils::cargo_build("main_process", X86_TARGET, !enable_web_rendering)?;
Expand All @@ -43,7 +57,7 @@ pub fn bundle_linux_app(enable_web_rendering: bool) -> Result<()> {

info!("Copy wrapper script.");
fs::copy(
root_dir.join("scripts/compositor_runtime_wrapper.sh"),
root_dir.join("src/bin/package_for_release/linux_runtime_wrapper.sh"),
tmp_dir.join("video_compositor"),
)?;

Expand All @@ -64,8 +78,8 @@ pub fn bundle_linux_app(enable_web_rendering: bool) -> Result<()> {

info!("Create tar.gz archive.");
let archive_name = match enable_web_rendering {
true => "video_compositor_with_web_rendering_linux_x86_64.tar.gz",
false => "video_compositor_linux_x86_64.tar.gz",
true => X86_WITH_WEB_RENDERING_OUTPUT_FILE,
false => X86_OUTPUT_FILE,
};
let exit_code = Command::new("tar")
.args([
Expand Down
40 changes: 22 additions & 18 deletions src/bin/package_for_release/bundle_macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,44 @@ use log::info;
use crate::utils;

const ARM_MAC_TARGET: &str = "aarch64-apple-darwin";
const ARM_OUTPUT_FILE: &str = "video_compositor_darwin_aarch64.tar.gz";
const ARM_WITH_WEB_RENDERING_OUTPUT_FILE: &str =
"video_compositor_with_web_rendering_darwin_aarch64.tar.gz";

const INTEL_MAC_TARGET: &str = "x86_64-apple-darwin";
const INTEL_OUTPUT_FILE: &str = "video_compositor_darwin_x86_64.tar.gz";
const INTEL_WITH_WEB_RENDERING_OUTPUT_FILE: &str =
"video_compositor_with_web_rendering_darwin_x86_64.tar.gz";

pub fn bundle_macos_app(enable_web_rendering: bool) -> Result<()> {
let output_name = match enable_web_rendering {
true => "video_compositor_with_web_rendering",
false => "video_compositor",
};
pub fn bundle_macos_app() -> Result<()> {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
);

if cfg!(target_arch = "x86_64") {
bundle_app(
INTEL_MAC_TARGET,
&format!("{output_name}_darwin_x86_64.tar.gz"),
enable_web_rendering,
)?;
bundle_app(INTEL_MAC_TARGET, INTEL_OUTPUT_FILE, false)?;
bundle_app(INTEL_MAC_TARGET, INTEL_WITH_WEB_RENDERING_OUTPUT_FILE, true)?;
} else if cfg!(target_arch = "aarch64") {
bundle_app(
ARM_MAC_TARGET,
&format!("{output_name}_darwin_aarch64.tar.gz"),
enable_web_rendering,
)?;
bundle_app(ARM_MAC_TARGET, ARM_OUTPUT_FILE, false)?;
bundle_app(ARM_MAC_TARGET, ARM_WITH_WEB_RENDERING_OUTPUT_FILE, true)?;
} else {
panic!("Unknown architecture")
}
Ok(())
}

fn bundle_app(target: &'static str, output_name: &str, enable_web_rendering: bool) -> Result<()> {
if enable_web_rendering {
info!("Bundling compositor with web rendering");
} else {
info!("Bundling compositor without web rendering");
}

let root_dir_str = env!("CARGO_MANIFEST_DIR");
let root_dir: PathBuf = root_dir_str.into();
let build_dir = root_dir.join(format!("target/{target}/release"));
let tmp_dir = root_dir.join("video_compositor");
utils::setup_bundle_dir(&tmp_dir)?;

info!("Build main_process binary.");
utils::cargo_build("main_process", target, !enable_web_rendering)?;
Expand All @@ -51,9 +58,6 @@ fn bundle_app(target: &'static str, output_name: &str, enable_web_rendering: boo
info!("Build process_helper binary.");
utils::cargo_build("process_helper", target, false)?;
cef::bundle_app(&build_dir, &tmp_dir.join("video_compositor.app"))?;
} else {
let _ = fs::remove_dir_all(&tmp_dir);
fs::create_dir_all(&tmp_dir)?;
}

fs::copy(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

#
# Runtime wrapper which provides paths to native libs used by the web renderer
#

set -eo pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Expand Down
22 changes: 2 additions & 20 deletions src/bin/package_for_release/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use log::info;

#[cfg(target_os = "linux")]
mod bundle_linux;
#[cfg(target_os = "macos")]
Expand All @@ -8,26 +6,10 @@ mod utils;

#[cfg(target_os = "linux")]
fn main() {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
);

info!("Bundling compositor with web rendering");
bundle_linux::bundle_linux_app(true).unwrap();

info!("Bundling compositor without web rendering");
bundle_linux::bundle_linux_app(false).unwrap();
bundle_linux::bundle_linux_app().unwrap();
}

#[cfg(target_os = "macos")]
fn main() {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
);

info!("Bundling compositor with web rendering");
bundle_macos::bundle_macos_app(true).unwrap();

info!("Bundling compositor without web rendering");
bundle_macos::bundle_macos_app(false).unwrap();
bundle_macos::bundle_macos_app().unwrap();
}
18 changes: 17 additions & 1 deletion src/bin/package_for_release/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};
use log::{info, warn};
use std::{process::Command, str::from_utf8};
use std::{fs, path::PathBuf, process::Command, str::from_utf8};

pub fn cargo_build(
bin: &'static str,
Expand Down Expand Up @@ -32,3 +32,19 @@ pub fn cargo_build(
}
Ok(())
}

pub fn setup_bundle_dir(dir: &PathBuf) -> Result<()> {
if dir.exists() {
if !dir.is_dir() {
return Err(anyhow!("Expected directory path"));
}

info!("Bundle directory already exists. Removing...");
fs::remove_dir_all(dir)?;
}

info!("Creating new bundle directory");
fs::create_dir_all(dir)?;

Ok(())
}

0 comments on commit c651562

Please sign in to comment.