Commit Graph

16771 Commits

Author SHA1 Message Date
Xiretza
71c2f08e5d printf: implement Printf for &WString 2023-02-18 18:53:50 +01:00
Xiretza
333056a9ec rust: add bindings for signal conversion functions 2023-02-18 18:53:50 +01:00
Xiretza
e6e866e455 Port escape_string() to Rust 2023-02-18 18:53:50 +01:00
Xiretza
15d4310ae9 Port scoped_push to Rust 2023-02-18 18:53:50 +01:00
Neeraj Jaiswal
844174367b wgetopt: fix long option match to always match prefix 2023-02-18 18:53:40 +01:00
Neeraj Jaiswal
1adfce18ee builtins: port return/exit to rust 2023-02-18 18:53:40 +01:00
Mahmoud Al-Qudsi
b5ff175b45 Fix timer.rs cross-platform compilation
* macOS does not have RUSAGE_THREAD
* tv_sec and tv_usec may be i32 instead of i64
2023-02-14 16:36:00 -06:00
Mahmoud Al-Qudsi
a1a8bc3d8d Port timer.cpp to rust 2023-02-14 15:54:18 -06:00
David Adam
340db7f7d3 fish.spec/debian packaging: add initial Rust dependencies 2023-02-12 22:53:14 +08:00
ridiculousfish
15c3698258 Mark Dup2List as a struct, not a class
Fixes clang warnings "class 'Dup2List' was previously declared as a
struct."
2023-02-11 12:13:51 -08:00
Xiretza
5a76c7d3b1 Port emit builtin to rust 2023-02-11 15:04:57 +01:00
Xiretza
3ed86fae1c Port parse_help_only_cmd_opts to Rust
This is duplicated for now, since a `&mut [&wstr]` can't be passed over FFI.
2023-02-11 15:04:57 +01:00
Xiretza
27c8845075 rust: fix typos in documentation, add links
Closes #9556
2023-02-11 08:54:53 +01:00
Johannes Altmanninger
a8c992236e Document some porting bits 2023-02-09 00:39:01 +01:00
Johannes Altmanninger
39f3c894d7 Port tokenizer.cpp to Rust
In hindsight, I should probably have split this into three different commits.
2023-02-09 00:37:22 +01:00
Johannes Altmanninger
7f8d247211 Port parse_constants.h to Rust 2023-02-09 00:37:22 +01:00
Johannes Altmanninger
25816627de Port redirection.cpp to Rust 2023-02-09 00:37:22 +01:00
Johannes Altmanninger
9ca160eac2 Convert parse_error_code_t to a scoped enum
This will make the Rust port's diff smaller.
2023-02-08 21:49:54 +01:00
Johannes Altmanninger
8fd1db06ed Remove unused parse error code 2023-02-08 21:49:54 +01:00
Johannes Altmanninger
4639f7ec40 Follow Rust naming convention for some types
But don't do it for enum variants just yet.
2023-02-08 21:49:54 +01:00
Johannes Altmanninger
958ad3a9e7 ffi.rs: silence warning about get_procs()
We should fix this warning eventually.  Silence it for now to make Clippy
pass without warnings, which makes it much more useful.

       Compiling fish-rust v0.1.0 (/home/johannes/git/fish-riir/fish-rust)
    error: mutable borrow from immutable input(s)
      --> src/ffi.rs:79:32
       |
    79 |     pub fn get_procs(&self) -> &mut [UniquePtr<process_t>] {
       |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: immutable borrow here
      --> src/ffi.rs:79:22
       |
    79 |     pub fn get_procs(&self) -> &mut [UniquePtr<process_t>] {
       |                      ^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref
       = note: `#[deny(clippy::mut_from_ref)]` on by default

    error: could not compile `fish-rust` due to previous error
2023-02-08 21:49:41 +01:00
Johannes Altmanninger
29a2c4b718 gettext.rs: allow translating non-literal strings
A following commit will pass global string constants to the gettext macro.
This is not ideal because we might accidentally use the constants without
gettext (which we should never do). To fix that we might need to define a
macro per constant, or use a proc macro which is maybe not worth it.
2023-02-08 21:49:41 +01:00
Johannes Altmanninger
47cc98fd57 wutil.h: enable implicit conversion from wcharz_t to wcstring
This allows to write

    wcstring result = some_rust_function_that_returns_wcharz_t();
2023-02-08 21:49:41 +01:00
Johannes Altmanninger
bfa94bfa7a Fix rustc warning about auto deref
warning: deref which would be done by auto-deref
      --> src/wchar_ffi.rs:81:5
       |
    81 |     &*EMPTY_WSTRING
       |     ^^^^^^^^^^^^^^^ help: try this: `&EMPTY_WSTRING`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
       = note: `#[warn(clippy::explicit_auto_deref)]` on by default
2023-02-08 21:49:41 +01:00
Xiretza
a16e2ecb1b Port echo builtin to Rust 2023-02-07 22:25:47 +01:00
Xiretza
4b85c2f6db builtin: propagate status from Rust builtins
The return type of `builtin_run_rust()` reflects that of C++ builtins.
2023-02-07 22:25:47 +01:00
Xiretza
cfb5bb2505 builtin: correctly flush streams after running Rust builtin 2023-02-07 22:25:47 +01:00
Mahmoud Al-Qudsi
0b160ebe71 Drop lazy_static from Cargo.toml
This should have been included as part of the previous commit, mea culpa.
2023-02-05 18:20:26 -06:00
Mahmoud Al-Qudsi
d7febd4f3e Use once_cell instead of lazy_static
lazy_static has better ergonomics at the call/access sites (it returns a
reference to the type directly, whereas with once_cell we get a static Lazy<T>
that we must dereference instead) but the once_cell api is slated for
integration into the standard library [0] and has been the "preferred" way to
declare static global variables w/ deferred initialization. It's also less
opaque and easier to comprehend how it works, I guess?

(Both `once_cell` and `lazy_static` are already in our dependency tree, so this
should have no detrimental effect on build times. It actually negligibly
*improves* build times by not using macros, reducing the amount of expansion the
compiler has to do by a miniscule amount.)

[0]: https://github.com/rust-lang/rust/issues/74465
2023-02-05 17:58:33 -06:00
Johannes Altmanninger
39c3faeaf4 gettext.rs: make trailing comma actually optional 2023-02-05 12:24:29 +01:00
Johannes Altmanninger
f167ec9063 clippy: silence manual_is_ascii_check
It's debatable whether is_ascii_digit() is better than (0..=9).contains().
(Probably we want to go with the mainstream Rust choice eventually.)
Let's disable the warning for now since it's not terribly important.
2023-02-05 12:24:29 +01:00
Johannes Altmanninger
c8bf2be408 wchar_ffi.rs: implement from_ffi() for more FFI strings 2023-02-05 12:22:42 +01:00
Johannes Altmanninger
dcca3cfe3c Prefer taking native Rust strings instead of wcharz_t
We should only be dealing with wcharz_t at the language boundary.
Rust callers should prefer the equivalent &wstr.
Since wcsfilecmp() is no longer exposed directly it can take &wstr only.
2023-02-05 12:22:42 +01:00
Johannes Altmanninger
a446a16471 flog.rs: use qualified name in FLOG! macro
Otherwise this macro fails when used in a context that doesn't import
this name.
2023-02-05 12:02:48 +01:00
Johannes Altmanninger
7347c90d1e builtins.rs: correct error message on unknown option 2023-02-05 12:02:48 +01:00
Johannes Altmanninger
476b12e06a util.rs: simplify wcsfilecmp a bit further 2023-02-05 12:02:48 +01:00
Johannes Altmanninger
ba1c5d495f util.rs: fix Yoda condition 2023-02-05 12:02:48 +01:00
Xiretza
8460b37b6a rust: util: use Ordering instead of integers 2023-02-05 11:57:25 +01:00
Xiretza
8b483735b4 rust: fix doc comments 2023-02-05 11:57:25 +01:00
Xiretza
cee13531e3 rust: silence warnings on auto-generated FFI bindings 2023-02-05 11:57:25 +01:00
Xiretza
cba03fc1e8 rust: remove unnecessary newline 2023-02-05 11:57:25 +01:00
Xiretza
35083c72ef rust: silence some clippy warnings 2023-02-05 11:57:25 +01:00
Xiretza
853649f8dc rust: fix issues reported by clippy 2023-02-05 11:57:25 +01:00
ridiculousfish
c2df63f586 Remove an errant printf from fish_tests 2023-02-04 11:24:54 -07:00
Johannes Altmanninger
83fd7ea7c4 Port future_feature_flags.cpp to Rust
This is early work but I guess there's no harm in pushing it?
Some thoughts on the conventions:

Types that live only inside Rust follow Rust naming convention
("FeatureMetadata").

Types that live on both sides of the language boundary follow the existing
naming ("feature_flag_t").
The alternative is to define a type alias ("using feature_flag_t =
rust::FeatureFlag") but that doesn't seem to be supported in "[cxx::bridge]"
blocks. We could put it in a header ("future_feature_flags.h").

"feature_metadata_t" is a variant of "FeatureMetadata" that can cross
the language boundary. This has the advantage that we can avoid tainting
"FeatureMetadata" with "CxxString" and such. This is an experimental approach,
probably not what we should do in general.
2023-02-03 18:55:06 +01:00
Johannes Altmanninger
132d99a27b Call rust_init() in fish_indent too
The initial port of feature flags requires a global initialization. Since
fish_indent accesses feature flags, let's make sure to initialize them here.
In future, we can stop initializing things fish_indent doesn't need (like
the topic monitor) but that's no big deal. Global initialization should
always be a benign addition.
2023-02-03 18:55:06 +01:00
Johannes Altmanninger
517d53dc46 Port util.cpp to Rust
The original implementation without the test took me 3 hours (first time
seriously looking into this)

The functions take "wcharz_t" for smooth integration with existing C++ callers.
This is at the expense of Rust callers, which would prefer "&wstr".  Would be
nice to declare a function parameter that accepts both but I don't think
that really works since "wcharz_t" drops the lifetime annotation.
2023-02-03 18:55:06 +01:00
Johannes Altmanninger
44d75409d0 build.rs: re-run autocxx if any ffi module changed
I'm not 100% sure this is the right thing but it seems to fix a scenario
where a change to a Rust module was not propagated by "make".
2023-02-03 18:55:06 +01:00
Johannes Altmanninger
a502cb16c3 ffi.rs: prevent rustfmt from breaking "use" statements
rustfmt removes the "::" prefix from qualifiers. This breaks the build because
I think a later "pub use ffi::*" results in "std" being an ambiguous reference.
2023-02-03 18:55:05 +01:00
Mahmoud Al-Qudsi
91be7489bc CI: Disable some Cirrus CI jobs during RIIR transition
We can re-enable these once we're nearing a RIIR release (or if someone thinks
it's a good use of their time to fix them before then). Otherwise we're just
going to have GitHub reporting CI failure for all commits instead of just the
ones that actually broke something.

(I'm mainly trying to get the branch in a good state to merge into master.)
2023-02-03 11:52:01 -06:00