MCPcopy Create free account
hub / github.com/astonbitecode/j4rs / copy_j4rs_libs_under

Method copy_j4rs_libs_under

rust/src/api/mod.rs:1465–1506  ·  view source on GitHub ↗

Copies the jassets default directory and the j4rs dynamic library under the specified location. This is useful for cases when `with_base_path` method is used when building a Jvm with the JvmBuilder. Build scripts should use this method.

(path: P)

Source from the content-addressed store, hash-verified

1463 /// the JvmBuilder.
1464 /// Build scripts should use this method.
1465 pub fn copy_j4rs_libs_under<P: AsRef<Path>>(path: P) -> errors::Result<()> {
1466 let mut pb = PathBuf::from(path.as_ref());
1467 pb.push("deps");
1468 fs::create_dir_all(&pb)?;
1469
1470 let default_jassets_path_buf = utils::default_jassets_path()?;
1471 let default_jassets_path_string = default_jassets_path_buf.to_str().unwrap().to_owned();
1472
1473 // Copy the jassets
1474 let options = &mut fs_extra::dir::CopyOptions::new();
1475 options.overwrite = true;
1476 let _ = fs_extra::copy_items(vec![default_jassets_path_string].as_ref(), path, options)?;
1477
1478 // Copy the dynamic libraries
1479 let dynlibs: Vec<String> = {
1480 let mut dynlibs = vec![];
1481 // We try every 1 second for 10 iterations because on most systems, cargo will
1482 // parallelize the build and the dynlib might not be created yet.
1483 for _i in 0..10 {
1484 dynlibs = utils::find_j4rs_dynamic_libraries_paths()?;
1485 if dynlibs.is_empty() {
1486 thread::sleep(time::Duration::from_millis(1000));
1487 } else {
1488 break;
1489 }
1490 }
1491 dynlibs
1492 };
1493 if dynlibs.is_empty() {
1494 let message = format!(
1495 "No j4rs dynamic libraries found for target triple {}. \
1496 The host triple during build is {}.",
1497 env::var("TARGET").unwrap_or("".to_string()),
1498 env::var("HOST").unwrap_or("UNKNOWN".to_string())
1499 );
1500 println!("cargo:warning={}", message);
1501 }
1502
1503 let _ = fs_extra::copy_items(&dynlibs, &pb, options)?;
1504
1505 Ok(())
1506 }
1507
1508 /// Initiates a chain of operations on Instances.
1509 pub fn chain(&self, instance: &Instance) -> errors::Result<ChainableInstance<'_>> {

Callers

nothing calls this directly

Calls 2

default_jassets_pathFunction · 0.85

Tested by

no test coverage detected