8000 feat: export-cef-dir utility to copy extracted CEF out of target by wravery · Pull Request #27 · tauri-apps/cef-rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: export-cef-dir utility to copy extracted CEF out of target #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,49 @@ jobs:

- name: Check fmt
run: cargo fmt --check
- name: Build

- name: Install ninja
run: |
${{ matrix.os == 'macos-latest' && 'brew install ninja'
|| (matrix.os == 'windows-latest' && 'choco install ninja'
|| 'echo "ninja already installed"') }}
cargo build --verbose

- name: Cache CEF
id: cache-cef
uses: actions/cache@v4.2.0
with:
path: ~/.local/share/cef
key: cef-${{ matrix.os }}-${{ hashFiles('Cargo.toml') }}

- name: ${{ steps.cache-cef.outputs.cache-hit && 'Use cache' || 'Export CEF' }}
run: |
${{ steps.cache-cef.outputs.cache-hit && 'echo "Cached CEF"'
|| (matrix.os == 'windows-latest'
&& 'cargo run -p export-cef-dir -- "$env:USERPROFILE/.local/share/cef"'
|| 'cargo run -p export-cef-dir -- "$HOME/.local/share/cef"')
}}
echo "CEF_PATH=${{ matrix.os == 'windows-latest'
&& '$env:USERPROFILE'
|| '$HOME'
}}/.local/share/cef" >> $${{ matrix.os == 'windows-latest'
&& 'env:'
|| ''
}}GITHUB_ENV
echo "${{ matrix.os == 'macos-latest'
&& 'DYLD_FALLBACK_LIBRARY_PATH'
|| (matrix.os == 'windows-latest'
&& 'PATH'
|| 'LD_LIBRARY_PATH') }}=${{ matrix.os == 'macos-latest'
&& '$DYLD_FALLBACK_LIBRARY_PATH:$HOME/.local/share/cef'
|| (matrix.os == 'windows-latest'
&& '$env:PATH;$env:USERPROFILE/.local/share/cef'
|| '$LD_LIBRARY_PATH:$HOME/.local/share/cef') }}" >> $${{ matrix.os == 'windows-latest'
&& 'env:'
|| ''
}}GITHUB_ENV

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ resolver = "2"
members = [
"download-cef",
"update-bindings",
"export-cef-dir",
"sys",
"cef",
]
Expand Down
5 changes: 4 additions & 1 deletion cef/src/library_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ impl LibraryLoader {

fn load_library(name: &std::path::Path) -> bool {
use std::os::unix::ffi::OsStrExt;
unsafe { load_library(Some(&*name.as_os_str().as_bytes().as_ptr().cast())) == 1 }
let Ok(name) = std::ffi::CString::new(name.as_os_str().as_bytes()) else {
return false;
};
unsafe { load_library(Some(&*name.as_ptr().cast())) == 1 }
}
}

Expand Down
17 changes: 17 additions & 0 deletions export-cef-dir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "export-cef-dir"
publish = false

version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
repository.workspace = true

[dependencies]
anyhow.workspace = true
cef-dll-sys.workspace = true
clap.workspace = true

[build-dependencies]
anyhow.workspace = true
10 changes: 10 additions & 0 deletions export-cef-dir/build.rs
EDBE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::{env, fs::File, io::Write, path::PathBuf};

fn main() -> anyhow::Result<()> {
let cef_dir = env::var("DEP_CEF_DLL_WRAPPER_CEF_DIR")?;
eprintln!("DEP_CEF_DLL_WRAPPER_CEF_DIR: {cef_dir}");
let cef_dir_rs = PathBuf::from(env::var("OUT_DIR")?).join("cef_dir.rs");
let mut cef_dir_rs = File::create(cef_dir_rs)?;
writeln!(&mut cef_dir_rs, r#"const CEF_DIR: &str = r"{cef_dir}";"#)?;
Ok(())
}
60 changes: 60 additions & 0 deletions export-cef-dir/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use clap::Parser;
use std::{
fs, io,
path::{Path, PathBuf},
};

include!(concat!(env!("OUT_DIR"), "/cef_dir.rs"));

#[derive(Parser, Debug)]
#[command(about, long_about = None)]
struct Args {
#[arg(short, long, default_value = "false")]
force: bool,
target: String,
}

fn main() -> anyhow::Result<()> {
let args = Args::parse();
let target = PathBuf::from(args.target);

if target.exists() {
if !args.force {
return Err(anyhow::anyhow!(
"target directory already exists: {}",
target.display()
));
}

let parent = target.parent();
let dir = target
.file_name()
.ok_or_else(|| anyhow::anyhow!("invalid target directory: {}", target.display()))?;
let old_target = parent.map(|p| p.join(dir));
let old_target = old_target.as_ref().unwrap_or(&target);
fs::rename(&target, old_target)?;
fs::remove_dir_all(old_target)?
}

copy_directory(PathBuf::from(CEF_DIR), &target)?;

Ok(())
}

fn copy_directory<P, Q>(src: P, dst: Q) -> io::Result<()>
where
P: AsRef<Path>,
Q: AsRef<Path>,
{
fs::create_dir_all(&dst)?;
for entry in fs::read_dir(&src)? {
let entry = entry?;
let dst_path = dst.as_ref().join(entry.file_name());
if entry.file_type()?.is_dir() {
copy_directory(&entry.path(), &dst_path)?;
} else {
fs::copy(&entry.path(), &dst_path)?;
}
}
Ok(())
}
2 changes: 1 addition & 1 deletion sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> anyhow::Result<()> {
Ok(cef_path) => {
1E0A // Allow overriding the CEF path with environment variables.
println!("Using CEF path from environment: {cef_path}");
PathBuf::from(cef_path).canonicalize()?
PathBuf::from(cef_path)
}
Err(_) => {
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
Expand Down
7 changes: 3 additions & 4 deletions sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ mod test {
.join(FRAMEWORK_PATH)
.canonicalize()
.expect("failed to get framework path");
let framework_dir = std::ffi::CString::new(framework_dir.as_os_str().as_bytes())
.expect("invalid path");

assert_eq!(
cef_load_library(framework_dir.as_os_str().as_bytes().as_ptr().cast()),
1
);
assert_eq!(cef_load_library(framework_dir.as_ptr().cast()), 1);
}

assert_eq!(cef_initialize(null(), null(), null_mut(), null_mut()), 0);
Expand Down
Loading
0