mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2025-02-18 15:41:39 +00:00
Always write cxxbridge.h into a predictable place from build script
This commit is contained in:
parent
0c88e03a4a
commit
c43627aee6
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../include/cxxbridge.h"
|
||||
#include "cxxbridge/cxxbridge.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
@ -463,5 +463,10 @@ fn try_generate_bridge(rust_source_file: &Path) -> Result<cc::Build> {
|
||||
let mut build = paths::cc_build();
|
||||
build.file(&bridge_path);
|
||||
|
||||
let ref cxxbridge_h = paths::include_dir()?.join("cxxbridge/cxxbridge.h");
|
||||
let _ = fs::create_dir_all(cxxbridge_h.parent().unwrap());
|
||||
let _ = fs::remove_file(cxxbridge_h);
|
||||
let _ = fs::write(cxxbridge_h, gen::include::HEADER);
|
||||
|
||||
Ok(build)
|
||||
}
|
||||
|
13
src/paths.rs
13
src/paths.rs
@ -15,11 +15,9 @@ pub(crate) fn cc_build() -> cc::Build {
|
||||
}
|
||||
|
||||
fn try_cc_build() -> Result<cc::Build> {
|
||||
let target_dir = target_dir()?;
|
||||
|
||||
let mut build = cc::Build::new();
|
||||
build.include(target_dir.join("cxxbridge"));
|
||||
build.include(target_dir.parent().unwrap());
|
||||
build.include(include_dir()?);
|
||||
build.include(target_dir()?.parent().unwrap());
|
||||
Ok(build)
|
||||
}
|
||||
|
||||
@ -31,7 +29,7 @@ pub(crate) fn symlink_header(path: &Path, original: &Path) {
|
||||
|
||||
fn try_symlink_header(path: &Path, original: &Path) -> Result<()> {
|
||||
let suffix = relative_to_parent_of_target_dir(original)?;
|
||||
let ref dst = target_dir()?.join("cxxbridge").join(suffix);
|
||||
let ref dst = include_dir()?.join(suffix);
|
||||
|
||||
fs::create_dir_all(dst.parent().unwrap())?;
|
||||
let _ = fs::remove_file(dst);
|
||||
@ -67,6 +65,11 @@ pub(crate) fn out_with_extension(path: &Path, ext: &str) -> Result<PathBuf> {
|
||||
Ok(out_dir.join(rel).with_file_name(file_name))
|
||||
}
|
||||
|
||||
pub(crate) fn include_dir() -> Result<PathBuf> {
|
||||
let target_dir = target_dir()?;
|
||||
Ok(target_dir.join("cxxbridge"))
|
||||
}
|
||||
|
||||
fn target_dir() -> Result<PathBuf> {
|
||||
let mut dir = out_dir()?.canonicalize()?;
|
||||
loop {
|
||||
|
Loading…
x
Reference in New Issue
Block a user