diff --git a/Cargo.toml b/Cargo.toml index 8b1375868..1718f07ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,8 @@ [workspace] resolver = "2" members = [ - "fish-rust", "fish-rust/widestring-suffix", ] -default-members = ["fish-rust"] [workspace.package] rust-version = "1.67" @@ -29,3 +27,57 @@ cc = { git = "https://github.com/mqudsi/cc-rs", branch = "fish" } [profile.release] overflow-checks = true + +[package] +name = "fish-rust" +version = "0.1.0" +edition.workspace = true +rust-version.workspace = true +build = "fish-rust/build.rs" + +[dependencies] +widestring-suffix = { path = "fish-rust/widestring-suffix/" } +pcre2 = { git = "https://github.com/fish-shell/rust-pcre2", branch = "master", default-features = false, features = ["utf32"] } +fast-float = { git = "https://github.com/fish-shell/fast-float-rust", branch="fish" } +hexponent = { git = "https://github.com/fish-shell/hexponent", branch="fish" } +printf-compat = { git = "https://github.com/fish-shell/printf-compat.git", branch="fish" } + +autocxx = "0.23.1" +bitflags = "1.3.2" +cxx = "1.0" +errno = "0.2.8" +inventory = { version = "0.3.3", optional = true} +lazy_static = "1.4.0" +libc = "0.2.137" +lru = "0.10.0" +moveit = "0.5.1" +nix = { version = "0.25.0", default-features = false, features = [] } +num-traits = "0.2.15" +# to make integer->enum conversion easier +num-derive = "0.3.3" +once_cell = "1.17.0" +rand = { version = "0.8.5", features = ["small_rng"] } +unixstring = "0.2.7" +widestring = "1.0.2" +rand_pcg = "0.3.1" + +[build-dependencies] +autocxx-build = "0.23.1" +cc = { git = "https://github.com/mqudsi/cc-rs", branch = "fish" } +cxx-build = { git = "https://github.com/fish-shell/cxx", branch = "fish" } +cxx-gen = { git = "https://github.com/fish-shell/cxx", branch = "fish" } +rsconf = { git = "https://github.com/mqudsi/rsconf", branch = "master" } + +[lib] +crate-type = ["staticlib"] +path = "fish-rust/src/lib.rs" + +[features] +# The fish-ffi-tests feature causes tests to be built which need to use the FFI. +# These tests are run by fish_tests(). +default = ["fish-ffi-tests"] +fish-ffi-tests = ["inventory"] + +# The following features are auto-detected by the build-script and should not be enabled manually. +asan = [] +bsd = [] \ No newline at end of file diff --git a/cmake/Rust.cmake b/cmake/Rust.cmake index 99ceb6b6c..ae9e7362b 100644 --- a/cmake/Rust.cmake +++ b/cmake/Rust.cmake @@ -69,8 +69,9 @@ corrosion_set_env_vars(${fish_rust_target} "CMAKE_WITH_GETTEXT=${CMAKE_WITH_GETTEXT}" ) +# this needs an extra fish-rust due to the poor source placement target_include_directories(${fish_rust_target} INTERFACE - "${rust_target_dir}/cxxbridge/${fish_rust_target}/src/" + "${rust_target_dir}/cxxbridge/${fish_rust_target}/fish-rust/src/" "${fish_autocxx_gen_dir}/include/" ) diff --git a/fish-rust/Cargo.toml b/fish-rust/Cargo.toml deleted file mode 100644 index 966adc57c..000000000 --- a/fish-rust/Cargo.toml +++ /dev/null @@ -1,57 +0,0 @@ -[package] -name = "fish-rust" -version = "0.1.0" -edition.workspace = true -rust-version.workspace = true - -[dependencies] -widestring-suffix = { path = "./widestring-suffix/" } -pcre2 = { git = "https://github.com/fish-shell/rust-pcre2", branch = "master", default-features = false, features = ["utf32"] } -fast-float = { git = "https://github.com/fish-shell/fast-float-rust", branch="fish" } -hexponent = { git = "https://github.com/fish-shell/hexponent", branch="fish" } -printf-compat = { git = "https://github.com/fish-shell/printf-compat.git", branch="fish" } - -autocxx = "0.23.1" -bitflags = "1.3.2" -cxx = "1.0" -errno = "0.2.8" -inventory = { version = "0.3.3", optional = true} -lazy_static = "1.4.0" -libc = "0.2.137" -lru = "0.10.0" -moveit = "0.5.1" -nix = { version = "0.25.0", default-features = false, features = [] } -num-traits = "0.2.15" -# to make integer->enum conversion easier -num-derive = "0.3.3" -once_cell = "1.17.0" -rand = { version = "0.8.5", features = ["small_rng"] } -unixstring = "0.2.7" -widestring = "1.0.2" -rand_pcg = "0.3.1" - -[build-dependencies] -autocxx-build = "0.23.1" -cc = { git = "https://github.com/mqudsi/cc-rs", branch = "fish" } -cxx-build = { git = "https://github.com/fish-shell/cxx", branch = "fish" } -cxx-gen = { git = "https://github.com/fish-shell/cxx", branch = "fish" } -rsconf = { git = "https://github.com/mqudsi/rsconf", branch = "master" } - -[lib] -crate-type = ["staticlib"] - -[features] -# The fish-ffi-tests feature causes tests to be built which need to use the FFI. -# These tests are run by fish_tests(). -default = ["fish-ffi-tests"] -fish-ffi-tests = ["inventory"] - -# The following features are auto-detected by the build-script and should not be enabled manually. -asan = [] -bsd = [] - -#cxx = { path = "../../cxx" } -#cxx-gen = { path="../../cxx/gen/lib" } -#autocxx = { path = "../../autocxx" } -#autocxx-build = { path = "../../autocxx/gen/build" } -#autocxx-bindgen = { path = "../../autocxx-bindgen" } diff --git a/fish-rust/build.rs b/fish-rust/build.rs index 06335c826..0e2b77fc4 100644 --- a/fish-rust/build.rs +++ b/fish-rust/build.rs @@ -2,19 +2,21 @@ use rsconf::{LinkType, Target}; use std::error::Error; fn main() { - cc::Build::new().file("src/compat.c").compile("libcompat.a"); + cc::Build::new() + .file("fish-rust/src/compat.c") + .compile("libcompat.a"); let rust_dir = std::env::var("CARGO_MANIFEST_DIR").expect("Env var CARGO_MANIFEST_DIR missing"); let target_dir = - std::env::var("FISH_RUST_TARGET_DIR").unwrap_or(format!("{}/../{}", rust_dir, "target/")); - let fish_src_dir = format!("{}/{}", rust_dir, "../src/"); + std::env::var("FISH_RUST_TARGET_DIR").unwrap_or(format!("{}/{}", rust_dir, "target/")); + let cpp_fish_src_dir = format!("{}/{}", rust_dir, "src/"); // Where cxx emits its header. let cxx_include_dir = format!("{}/{}", target_dir, "cxxbridge/rust/"); - // If FISH_BUILD_DIR is given by CMake, then use it; otherwise assume it's at ../build. + // If FISH_BUILD_DIR is given by CMake, then use it; otherwise assume it's at build. let fish_build_dir = - std::env::var("FISH_BUILD_DIR").unwrap_or(format!("{}/{}", rust_dir, "../build/")); + std::env::var("FISH_BUILD_DIR").unwrap_or(format!("{}/{}", rust_dir, "build/")); // Where autocxx should put its stuff. let autocxx_gen_dir = std::env::var("FISH_AUTOCXX_GEN_DIR") @@ -38,47 +40,47 @@ fn main() { // This allows "Rust to be used from C++" // This must come before autocxx so that cxx can emit its cxx.h header. let source_files = vec![ - "src/abbrs.rs", - "src/ast.rs", - "src/builtins/shared.rs", - "src/builtins/function.rs", - "src/common.rs", - "src/env/env_ffi.rs", - "src/env_dispatch.rs", - "src/event.rs", - "src/fd_monitor.rs", - "src/fd_readable_set.rs", - "src/fds.rs", - "src/ffi_init.rs", - "src/ffi_tests.rs", - "src/fish_indent.rs", - "src/function.rs", - "src/future_feature_flags.rs", - "src/highlight.rs", - "src/job_group.rs", - "src/kill.rs", - "src/null_terminated_array.rs", - "src/output.rs", - "src/parse_constants.rs", - "src/parse_tree.rs", - "src/parse_util.rs", - "src/print_help.rs", - "src/redirection.rs", - "src/signal.rs", - "src/smoke.rs", - "src/spawn.rs", - "src/termsize.rs", - "src/threads.rs", - "src/timer.rs", - "src/tokenizer.rs", - "src/topic_monitor.rs", - "src/trace.rs", - "src/util.rs", - "src/wait_handle.rs", + "fish-rust/src/abbrs.rs", + "fish-rust/src/ast.rs", + "fish-rust/src/builtins/shared.rs", + "fish-rust/src/builtins/function.rs", + "fish-rust/src/common.rs", + "fish-rust/src/env/env_ffi.rs", + "fish-rust/src/env_dispatch.rs", + "fish-rust/src/event.rs", + "fish-rust/src/fd_monitor.rs", + "fish-rust/src/fd_readable_set.rs", + "fish-rust/src/fds.rs", + "fish-rust/src/ffi_init.rs", + "fish-rust/src/ffi_tests.rs", + "fish-rust/src/fish_indent.rs", + "fish-rust/src/function.rs", + "fish-rust/src/future_feature_flags.rs", + "fish-rust/src/highlight.rs", + "fish-rust/src/job_group.rs", + "fish-rust/src/kill.rs", + "fish-rust/src/null_terminated_array.rs", + "fish-rust/src/output.rs", + "fish-rust/src/parse_constants.rs", + "fish-rust/src/parse_tree.rs", + "fish-rust/src/parse_util.rs", + "fish-rust/src/print_help.rs", + "fish-rust/src/redirection.rs", + "fish-rust/src/signal.rs", + "fish-rust/src/smoke.rs", + "fish-rust/src/spawn.rs", + "fish-rust/src/termsize.rs", + "fish-rust/src/threads.rs", + "fish-rust/src/timer.rs", + "fish-rust/src/tokenizer.rs", + "fish-rust/src/topic_monitor.rs", + "fish-rust/src/trace.rs", + "fish-rust/src/util.rs", + "fish-rust/src/wait_handle.rs", ]; cxx_build::bridges(&source_files) .flag_if_supported("-std=c++11") - .include(&fish_src_dir) + .include(&cpp_fish_src_dir) .include(&fish_build_dir) // For config.h .include(&cxx_include_dir) // For cxx.h .flag("-Wno-comment") @@ -86,8 +88,8 @@ fn main() { // Emit autocxx junk. // This allows "C++ to be used from Rust." - let include_paths = [&fish_src_dir, &fish_build_dir, &cxx_include_dir]; - let mut builder = autocxx_build::Builder::new("src/ffi.rs", include_paths); + let include_paths = [&cpp_fish_src_dir, &fish_build_dir, &cxx_include_dir]; + let mut builder = autocxx_build::Builder::new("fish-rust/src/ffi.rs", include_paths); // Use autocxx's custom output directory unless we're being called by `rust-analyzer` and co., // in which case stick to the default target directory so code intelligence continues to work. if std::env::var("RUSTC_WRAPPER").map_or(true, |wrapper| {