Commit Graph

234 Commits

Author SHA1 Message Date
Henrik Hørlück Berg
c23f419af1 Use the workspace from CMake
- Make CMake use the correct target-path
- Make build.rs use the correct target dir

Workspaces place it in the project root by default, the alternative to making
this change is to add a `.cargo/config.toml` file with

```toml
[build]
target-dir = "fish-rust/target"
```

Which I think is unnecessary, as we likely want to use the new location anyways.
2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
4728eaf642 Don't specify a min macOS version when not needed
Corrosion does not forward the `CMAKE_OSX_DEPLOYMENT_TARGET` to cargo.
As a result we end up building the Rust-libraries for the default target,
which is usually current macOS-version. But CMake links using the set
target, so we link for a version older than we built for.

To properly build for older macOS versions, the env variable
`MACOSX_DEPLOYMENT_TARGET` should instead be set, which cargo,
cmake and friends read by default. This can then lead to
warnings if you have libraries (e.g. PCRE2) built for newer
than our minimum version. Therefore we do not set a min-target
by default.
2023-08-02 22:42:52 +08:00
Henrik Hørlück Berg
55b6d7cd74 Revert "Fix built for newer than linked macOS warning"
This reverts commit 69ed2d1ca7. It was never meant
to be merged.
2023-08-02 22:42:52 +08:00
David Adam
861da91bf1 drop unused functions and configure checks
Remove the following C++ functions/methods, which have no callers:

fallback.cpp:
- wcstod_l

proc.cpp:
- job_t::get_processes

wutil.cpp:
- fish_wcstoll
- fish_wcstoull

Also drop unused configure checks/defines:
- HAVE_WCSTOD_L
- HAVE_USELOCALE
2023-07-14 20:48:56 +08:00
Henrik Hørlück Berg
69ed2d1ca7 Fix built for newer than linked macOS warning 2023-07-04 13:27:53 -07:00
Mahmoud Al-Qudsi
b17124d8d2 Add rsconf build system and check for gettext symbols
This is more complicated than it needs to be thanks to the presence of CMake and
the C++ ffi in the picture. rsconf can correctly detect the required libraries
and instruct rustc to link against them, but since we generate a static rust
library and have CMake link it against the C++ binaries, we are still at the
mercy of CMake picking up the symbols we want.

Unfortunately, we could detect the gettext symbols but discover at runtime that
they weren't linked in because CMake was compiled with `-DWITH_GETTEXT=0` or
similar (as the macOS CI runner does). This means we also need to pass state
between CMake and our build script to communicate which CMake options were
enabled.
2023-05-25 16:54:03 -05:00
Thomas Klausner
67d1d80f94
When using curses, look for libterminfo as well. (#9794)
Supports NetBSD, where libtinfo isn't available but libterminfo is.
2023-05-16 15:02:11 -05:00
Mahmoud Al-Qudsi
3651e0e9d8 Actually report ASAN memory leaks
The new asan exit handlers are called to get proper ASAN leak reports (as
calling _exit(0) skips the LSAN reporting stage and exits with success every
time).

They are no-ops when not compiled for ASAN.
2023-05-02 11:52:41 -05:00
Johannes Altmanninger
ec176dc07e Port path.h 2023-04-21 13:57:29 +02:00
Johannes Altmanninger
454009d13e Rust.cmake: break up long line 2023-04-21 13:57:29 +02:00
David Adam
1c978f7ec5 cmake: add support for vendored cmake
Use a "cmake-vendored" directory if it exists, to avoid accessing the
network if it's available, and a target to create an appropriate tarball
to create that directory.
2023-03-30 12:01:25 +08:00
Mahmoud Al-Qudsi
1bdb7dffaf Use cargo build -Z build-std for ASAN
This is recommended and increases coverage.
2023-03-08 11:27:15 -06:00
Mahmoud Al-Qudsi
91cf526d23
Enable rust address sanitizer for asan ci job (#9643)
Rust has multiple sanitizers available (with llvm integration).
-Zsanitizer=address catches the most likely culprits but we may want to set up a
separate job w/ -Zsanitizer=memory to catch uninitialized reads.

It might be necessary to execute `cargo build` as `cargo build -Zbuild-std` to
get full coverage.

When we're linking against the hybrid C++ codebase, the sanitizer library is
injected into the binary by also include `-fsanitize=address` in CXXFLAGS - we
do *not* want to manually opt-into `-lasan`. We also need to manually specify
the desired target triple as a CMake variable and then explicitly pass it to all
`cargo` invocations if building with ASAN.

Corrosion has been patched to make sure it follows these rules.

The `cargo-test` target is failing to link under ASAN. For some reason it has
autocxx/ffi dependencies even though only rust-native, ffi-free code should be
tested (and one would think the situation wouldn't change depending on the
presence of the sanitizer flag). It's been disabled under ASAN for now.
2023-03-06 18:15:36 -06:00
Akatsuki Rui
5a5cf267b7
cmake/Tests.cmake: Fix failure in cargo test (#9603)
The FISH_RUST_TARGET_DIR is not set for Tests.cmake, the target_dir will set to
$CARGO_MANIFEST_DIR/target. But if build.target-dir or CARGO_TARGET_DIR is set,
the real target_dir doesn't at the $CARGO_MANIFEST_DIR/target. It causes failure
in cargo test. Then, set --target-dir for cargo test.

Closes #9600
2023-02-21 11:44:59 -06:00
ridiculousfish
681a165721 Add an FFI test facility
This allow testing Rust functions (from fish_tests.cpp) which need to
cross the FFI. See the example in smoke.rs.
2023-02-02 19:34:48 -07:00
ridiculousfish
d843b67d2d Initial Rust commit 2023-02-02 19:34:47 -07:00
Aaron Gyes
550857ef65 Remove obsolete lynx bug mitigation
a lynx-internal hash of div.contents collided with em>a which caused
built-in styling to render much of entire pages as emphasized links.

Since switching from doxygen, we haven't had a <div class="contents">
so this workaround is no longer needed.
2023-01-01 19:41:41 -08:00
Mahmoud Al-Qudsi
2c0bbb0f82 Revert "cmake: Use pcre2 tag directly"
This reverts commit 2cc4437567.

As pointed out to me, it is safer to use the SHA directly to ~guarantee
the remote resource hasn't changed.
2022-10-28 17:59:08 -05:00
Mahmoud Al-Qudsi
c45fac84ee cmake: Use shallow clone for pcre2
This should speed up the clones and reduce unnecessary usage of both
bandwidth and disk space.
2022-10-28 14:04:14 -05:00
Mahmoud Al-Qudsi
2cc4437567 cmake: Use pcre2 tag directly 2022-10-28 14:04:14 -05:00
Mahmoud Al-Qudsi
11f954e7ec Correctly query termios.h and ioctl.h for struct winsize
The previous check was including these as relative includes, meaning the actual
system header files weren't actually being explicitly included and the check
could spuriously fail.

CMAKE_EXTRA_INCLUDE_FILES doesn't seem to have a way to specify that the
includes should be treated as system/global includes and CHECK_TYPE_SIZE() isn't
documented as being affected by any other variables that do, so switch to
another method altogether.

This requires that `struct winsize` have a member `ws_row`, but as best as I can
tell that is always the case.

Closes #9279.
2022-10-14 22:07:03 -05:00
Mahmoud Al-Qudsi
8b5cc0883a Use the official organization URL for PCRE2
PhilipHazel/pcre2.git redirects here *for now* but we shouldn't be using
anything other than the official GitHub repo.
2022-10-14 21:39:16 -05:00
ridiculousfish
379ad245e4 cmake: defeat bogus missing-field-initializers warning on g++ 4.8
g++ 4.8 emits a bogus warning on code like foo{}. Add a compiler flag
-Wno-missing-field-initializers if that warning is detected, because it
is annoying.
2022-09-20 14:41:22 -07:00
Fabian Boehm
5e0f5eff37 Remove wcsdup fallback
2a0e0d6721 removed the last use of it,
and in most cases we'd probably prefer to use a wcstring instead
2022-08-27 11:36:15 +02:00
ridiculousfish
deec78cdd3 cmake: Unset GIT_WORK_TREE and GIT_DIR before FetchContent_Populate
GIT_WORK_TREE is an environment variable which tells git where the
worktree is. It may be set by the user or by git itself, e.g. when
running `git rebase -i --exec ...`. If it is set, it overrides the
working directory, causing the `git checkout` from FetchContent_Populate
to fail. Clear this variable.

Do the same for GIT_DIR for the same reason.

A way to reproduce the failure that this commit fixes is:

    git rebase -i HEAD^^^ --exec 'ninja -C /path/to/build/dir fish'

prior to this commit, using the fetched PCRE2, this would fail in CMake.
2022-08-06 13:07:22 -07:00
Fabian Boehm
e04785604a Make static_assert C++11 compatible
static_assert without a message is C++17. Which we can't use 5 years later.
2022-07-24 16:53:53 +02:00
Fabian Boehm
bcd84c6908 Check for waitstatus orientation via cmake
Yeah we need the long way around because old glibc versions have weird WEXITSTATUS.
2022-07-24 16:40:33 +02:00
Aaron Gyes
dbb4e05254 Revert "PCRE2.cmake: update minimum system PCRE2 version, use GIT_SHALLOW"
This was in response to a feature we were using that required a
very new PCRE2: that was backed out.

So this reverts commit e63af7d006.
2022-07-10 12:44:35 -07:00
Aaron Gyes
e63af7d006 PCRE2.cmake: update minimum system PCRE2 version, use GIT_SHALLOW
GIT_SHALLOW 1 here improves generation speed and _deps in the build
dir like is 6 or 7 MB less according to `du`.

Bump the minimum PCRE2 to 10.35 on account of we use
PCRE2_SUBSTITUTE_LITERAL.
2022-07-09 20:00:53 -07:00
ridiculousfish
5b1e106d87 cmake: Download and fetch PCRE2 rather than using vendored sources
This switches to using the CMake FetchContent path to dynamically download
and build PCRE2, allowing us to drop the vendored sources.

The FISH_USE_SYSTEM_PCRE2 CMake option is kept, but if false it now means
fetch-and-build PCRE2 rather than building vendored sources.

Note FetchContent was introduced in CMake 3.11. That is now a prerequisite
for building fish with FISH_USE_SYSTEM_PCRE2 disabled.
2022-07-02 18:46:58 -07:00
ridiculousfish
5beb3a1141 Mark FISH_FORCE_COLOR in individual test targets
This allows running individual tests to produce colorized output.
No need to relnote this.
2022-04-10 13:41:21 -07:00
Raymond Wong
9f98d2ec5d cmake: check for 8-bit atomic operation
Fix building on RISC-V.
Closes #8850.

Signed-off-by: Raymond Wong <infiwang@pm.me>
2022-04-03 10:20:51 -07:00
Raymond Wong
1f393c627b cmake: alter check for 64-bit atomic operation
Signed-off-by: Raymond Wong <infiwang@pm.me>
2022-04-03 10:20:51 -07:00
ridiculousfish
793aff3891 Use -fno-c++-static-destructors
Static destructors cause the destructor for a global object to run when
the program exits. They are bad because:

1. Registering them takes time and memory at startup

2. Running them takes time at shutdown and also they may have weird
   interactions.

This shaves about 12k off of the binary size.

Unfortunately gcc does not support this flag.
2022-04-02 13:45:01 -07:00
David Adam
970a963896 cmake: disable frameworks when searching for libintl
This is a less-intrusive version of 95845b1, and only disables the
search for frameworks for libintil (sometimes shipped with Mono, but not
usable for compilation).

Closes #5244.
2022-03-26 22:00:44 +08:00
David Adam
73cade558a Revert "cmake: disable use of frameworks on macOS"
This reverts commit 95845b16c9.
2022-03-26 21:49:44 +08:00
David Adam
95845b16c9 cmake: disable use of frameworks on macOS
Prevents an issue where libintl from Mono gets picked up.

Closes #5244.
2022-03-26 21:38:12 +08:00
Fabian Homborg
d751b00504 Remove getifaddrs check
Not used anymore
2022-03-17 18:15:11 +01:00
Fabian Homborg
03c188086c Remove wcsndup and wcslcpy
We no longer use these anywhere.
2022-03-17 18:15:11 +01:00
Mahmoud Al-Qudsi
372f03ba20 Fix sys/sysctl.h depreciation error under glibc 2.30+
glibc 2.30 and up emit an ugly depreciation warning on
`#include <sys/sysctl.h>` - this patch makes the build system fail the
include test for `sys/sysctl.h` by forcibly setting `-Werror` before the
call to `check_include_files` (which internally uses `try_compile`) to
get `HAVE_SYS_SYSCTL` to not be defined (even if it's there) if it would
cause such a depreciation message to be emitted.

Ideally, we would not have to manually massage `CMAKE_C_FLAGS` before
calling `check_include_files` and could just tweak that to either always
or conditionally try compilation with `-Werror`, but try_compile doesn't
actually use any overridden `CMAKE_C_FLAGS` values [0] (dating back to
2006).

[0]: https://cmake.org/pipermail/cmake/2006-October/011649.html
2022-01-20 11:04:40 -06:00
Aaron Gyes
401d302179 :Revert "Remove CheckIncludeFiles.cmake"
This reverts commit 398f3213d2.
2022-01-19 11:41:16 -08:00
Aaron Gyes
398f3213d2 Remove CheckIncludeFiles.cmake
We apparently vendored it for the sake of attempting to support
old cmake versions:
7aefaff298.
"This file can be dropped once the minimum version of CMake for fish is 3.11.0"

So, drop it like it's hot.
2022-01-19 11:38:41 -08:00
Johannes Altmanninger
c0d1e41313 docs synopsis: add HTML highlighing and automate manpage markup
Recent synopsis changes move from literal code blocks to
[RST line blocks].  This does not translate well to HTML: it's not
rendered in monospace, so aligment is lost.  Additionally, we don't
get syntax highlighting in HTML, which adds differences to our code
samples which are highlighted.

We hard-wrap synopsis lines (like code blocks). To align continuation
lines in manpages we need [backslashes in weird places]. Combined with
the **, *, and `` markup, it's a bit hard to get the alignment right.

Fix these by moving synopsis sources back to code blocks and compute
HTML syntax highlighting and manpage markup with a custom Sphinx
extension.

The new Pygments lexer can tokenize a synopsis and assign the various
highlighting roles, which closely matches fish's syntax highlighing:
- command/keyword (dark blue)
- parameter (light blue)
- operator like and/or/not/&&/|| (cyan)
- grammar metacharacter (black)

For manpage output, we don't project the fish syntax highlighting
but follow the markup convention in GNU's man(1):

	bold text          type exactly as shown.
	italic text        replace with appropriate argument.

To make it easy to separate these two automatically, formalize that
(italic) placeholders must be uppercase; while all lowercase text is
interpreted literally (so rendered bold).
This makes manpages more consistent, see string-join(1) and and(1).

Implementation notes:
Since we want manpage formatting but Sphinx's Pygments highlighing
plugin does not support manpage output, add our custom "synopsis"
directive.  This directive parses differently when manpage output is
specified. This means that the HTML and manpage build processes must
not share a cache, because the parsed doctrees are cached.  Work around
this by using separate cache locations for build targets "sphinx-docs"
(which creates HTML) and "sphinx-manpages".  A better solution would
be to only override Sphinx's ManualPageBuilder but that would take a
bit more code (ideally we could override ManualPageWriter but Sphinx
4.3.2 doesn't really support that).

---

Alternative solution: stick with line blocks but use roles like
:command: or :option: (or custom ones). While this would make it
possible to produce HTML that is consistent with code blocks (by adding
a bit of CSS), the source would look uglier and is harder to maintain.
(Let's say we want to add custom formatting to the [|] metacharacters
in HTML.  This is much easier with the proposed patch.)

---

[RST line blocks]: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#line-blocks
[backslashes in weird places]: https://github.com/fish-shell/fish-shell/pull/8626#discussion_r782837750
2022-01-19 22:56:41 +08:00
Aaron Gyes
1552c526ba Revert "Update Mac.cmake"
This reverts commit 01919f1785.
2022-01-03 08:08:41 -08:00
ridiculousfish
fecc022030 Rename the top-level test target to fish_run_tests
This keeps 'test' as an alias target. The reason is for compatibility
with CMake 3.10  and earlier, where one cannot make a target named
'test'.
2021-11-26 13:13:42 -08:00
Aaron Gyes
eb990c07c8 Let's make src/ easier to grok, move builins to src/builtins
+ No functional change here, just renames and #include changes.
+ CMake can't have slashes in the target names. I'm suspciious of
  that weird machinery for test, but I made it work.
+ A couple of builtins did not include their own headers, that
  is no longer the case.
2021-11-09 17:39:10 -08:00
Aaron Gyes
901dbd71b0 fix build when path has spaces in it.
Now it works.
2021-10-22 02:27:19 -07:00
Fabian Homborg
eba5352576 Also remove the languages from cmake
I'm not sure why this list is hardcoded?
2021-10-18 18:39:07 +02:00
Fabian Homborg
5e3c40207d cmake: Pass the source directory to the tests
Our tests typically run in their own environment, which is great for
normal tests.

However for the coming translation test, we don't want to copy the .po
files into the test environment, so it's nice to have a way out.
2021-10-18 17:02:17 +02:00
Aaron Gyes
87b2c2fdec install the fish.png file itself 2021-10-17 09:20:06 -07:00