Closed correabuscar closed 4 months ago
I don't really know what to do about these 2 warnings, which were there before this PR, so I'm gonna delegate them to the next person :)
Compiling ncurses v6.0.0 (/home/user/1tmp/ncurses-rs)
warning: attribute should be applied to a foreign function or static
--> /home/user/1tmp/ncurses-rs/src/lib.rs:161:1
|
161 | #[link_name="box"] pub fn box_(w: WINDOW, v: chtype, h: chtype) -> i32
| _^^^^^^^^^^^^^^^^^^_-
162 | | { wborder(w, v, v, h, h, 0, 0, 0, 0) }
| |______________________________________- not a foreign function or static
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: `#[warn(unused_attributes)]` on by default
warning: use of deprecated function `printw`: printw format support is disabled. Use addstr instead
--> /home/user/1tmp/ncurses-rs/src/lib.rs:822:3
|
822 | printw(s)
| ^^^^^^
|
= note: `#[warn(deprecated)]` on by default
warning: `ncurses` (lib) generated 2 warnings
Finished dev [unoptimized + debuginfo] target(s) in 1.97s
Arguably the latter could just get a #[allow(deprecated)]
on top of that printw(s)
call.
EDIT: Regarding the other warning, here's what ChatGPT 3.5 says (better than I could):
The warning message indicates that there's an attribute
#[link_name="box"]
applied to a function namedbox_
, which is likely intended to alias the functionbox_
to a symbol named "box
" in the resulting binary.However, the warning suggests that this attribute is being applied to a function (
box_
) that is not a foreign function or static, which means it's being used incorrectly according to the Rust compiler. This warning is letting the developer know that while this usage was previously allowed by the compiler, it's being phased out and will eventually become a hard error in future releases of Rust.To resolve this warning, the developer might need to review the purpose of the
#[link_name]
attribute and ensure it's being applied correctly, possibly to a foreign function or static item as intended. If the intention is to rename the functionbox_
to "box
" in the resulting binary, they might need to adjust the usage of the attribute or find an alternative approach that aligns with Rust's conventions.
It's unclear to me whether this actually worked at all before, and is it still working now while it's a warning, but won't when it becomes an error.
Here's the doc for link_name
I don't really know what to do about these 2 warnings, which were there before this PR, so I'm gonna delegate them to the next person :)
Compiling ncurses v6.0.0 (/home/user/1tmp/ncurses-rs) warning: attribute should be applied to a foreign function or static --> /home/user/1tmp/ncurses-rs/src/lib.rs:161:1 | 161 | #[link_name="box"] pub fn box_(w: WINDOW, v: chtype, h: chtype) -> i32 | _^^^^^^^^^^^^^^^^^^_- 162 | | { wborder(w, v, v, h, h, 0, 0, 0, 0) } | |______________________________________- not a foreign function or static | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: `#[warn(unused_attributes)]` on by default warning: use of deprecated function `printw`: printw format support is disabled. Use addstr instead --> /home/user/1tmp/ncurses-rs/src/lib.rs:822:3 | 822 | printw(s) | ^^^^^^ | = note: `#[warn(deprecated)]` on by default warning: `ncurses` (lib) generated 2 warnings Finished dev [unoptimized + debuginfo] target(s) in 1.97s
Arguably the latter could just get a
#[allow(deprecated)]
on top of thatprintw(s)
call.
These appear unrelated to the PR to me.
printw()
and addstr()
do similar things. I looked through recent release notes for ncurses upstream and couldn't find a reference for printw()
being deprecated, just vwprintw
(without the underscore vw_).
https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/printw.html https://invisible-island.net/ncurses/NEWS.html
Indeed, the warnings were there before this PR, however I felt I should've addressed them in this PR since it's about making v6 usable by v5 users of it like cursive
and pancurses
.
ncurses::printw
(the rust version of it) was deprecated before(but for a different reason), however now ll::printw
(the c version, what your link points to) can do formatted strings via ncurses-rs
(previously it couldn't)
I was wondering whether ncurses::printw
should still be deprecated because now that it got fixed, and it still only accepts one argument, thus can't accept formatted strings(ie. you'd need extra args), it's practically working as before (but now it doesn't crash anymore due to stray say %s
), however maybe users of it expect it to act like the c version and accept formatted strings(but this is what ll::printw
is for instead). But maybe I'm missing something and that's why keeping it deprecated makes sense. Either way, users of ncurses::printw
would pass rust's format!() strings to it, if formatting was desired.
I'm gonna say the PR is as ready as it can be, otherwise there's always gonna be something to change/improve on it each day :)
You're already at 50 commits and over 1700 LOC. It feels like a lot of scope creep happened here. My concern with that is getting the CVE patch rolled out in the other libraries now depends on @jeaye reviewing and merging this massive PR. I very much appreciate your work here, but perhaps splitting this off into separate PRs for some of the other quality of life fixes might help make these changes easier to grok and review.
You're already at 50 commits and over 1700 LOC. It feels like a lot of scope creep happened here. My concern with that is getting the CVE patch rolled out in the other libraries now depends on @jeaye reviewing and merging this massive PR. I very much appreciate your work here, but perhaps splitting this off into separate PRs for some of the other quality of life fixes might help make these changes easier to grok and review.
I guess the last 3 commits from April 11th can be cherry picked to make v6 work with cursive/pancurses(but they still need their own patches), the rest of the PR can be reviewed later(if ever).
EDIT: I could squash all the (50) commits into one or two, so to avoid the need to review every[^1] commit. But otherwise each commit is made so that the build doesn't fail to compile, especially during a git bisect. That being said, some builds will fail to compile because their fixes happened in some subsequent commit(s).
I could also just remove the useless feature test_build_rs_of_ncurses_rs
, as it's not gonna be used by anything, it's just a cargo test
equivalent for some of build.rs
QOL code. That would remove 250+ LOC.
Lots of lines are just comments, but comments can be ignored, and I think it's better to have them than not at all, even if they may even be wrong or outdated.
laterEDIT: @vwbusguy regarding your stated concern, if you wish to accelerate that, please by all means feel free to submit a new PR with only the relevant changes needed (you can either use my commits(those 3 I mentioned) or even submit new ones as your own even if it ends up being the same content, I honestly don't mind about credit, you've all my blessings) if you hope it would be accepted sooner... I'll then adapt my PR after yours gets accepted to include the changes(eg. rebase on master). Ie. if you want to do that do it, don't let the existence of this PR stop you from doing it, I honestly won't mind at all. I don't do it myself because perfectionism(sux) :) otherwise I would've just left this PR alone as it was initially, and no scope creep would've happened.
[^1]: which ensures no evil code sneaks in and gets run by builds during a git bisect.
Wow. This is a lot of work. Thank you for doing it! I missed your comment about being done, since there were so many commit emails coming in that I stopped looking at them for a while. :facepalm:
I could also just remove the useless feature test_build_rs_of_ncurses_rs, as it's not gonna be used by anything, it's just a cargo test equivalent for some of build.rs QOL code. That would remove 250+ LOC.
I'm tempted to say we should do this, but what I'd really love is to get someone who knows the current state of Rust better than I do. I haven't been keeping up much with Rust in the last several years (working on my own lang instead). Back when I was used to Rust, cargo did all of the building magically, rather than needing a 1700 line build.rs
. So I'm not sure if this sort of thing is commonplace these days.
With that said, I have gone through the PR and I don't have any overall concerns beyond getting more eyes on this before it gets merged. As @vwbusguy said, if we want to unblock other projects from upgrading to fix that CVE sooner, we can separate that work. But if I could get one or two other folks to go through this, that'd increase my confidence in it.
@vwbusguy, @Ella-0, or @ThomasHabets: Anyone up to give this a look as well?
As a reminder, worst case, you could just consider(ie. cherry pick) only the last 3 commits from the day of April 11th, seen here at the top: https://github.com/jeaye/ncurses-rs/pull/218/commits (EDIT: these[^1]) and ignore the rest(ie. from april 18th and onwards) or even forget about the whole rest of PR, because those 3 commits are the only ones needed to get the other projects (cursive, pancurses) to work (and PRs for them are already prepared). Meanwhile, I could just take another look to see if indeed those 3 commits are indeed enough. EDIT: I've done the checking: they compile/test
on wsl(archlinux), ubuntu 22.04.4, fedora 39. Fail
s to build(or link examples) on nixos,Gentoo,OpenBSD 7.5, FreeBSD 14.0 though, it would need some later changes(related to build) to not fail, no doubt.
I could also just remove the useless feature test_build_rs_of_ncurses_rs
I'm tempted to say we should do this[...] [...] So I'm not sure if this sort of thing is commonplace these days.
that testing of build.rs
code, is definitely not common place at all, I haven't seen it used personally, I've just made that up for this just to make sure the code I changed/added didn't break(which it did several times), but it's not testing enough of the build.rs
anyway (I wanted to add more tests, but procrastinated as I felt it would be removed anyway), and there doesn't seem to be an idiomatic way(or any?) of testing build.rs
, but I may be wrong. I'm a rust beginner actually and while I've had no intention of using anything with ncurses, I can still monitor this repo to address any possible fallout from these changes.
I can just make a commit to remove that testing build.rs
functionality shortly... EDIT: done (341 less lines).
Back when I was used to Rust, cargo did all of the building magically, rather than needing a 1700 line build.rs
the code could probably be minimized more I guess, but it's mainly this much because it's meant to handle many build cases with better reporting in case of build failures, otherwise whoever's building it might be spending more time trying to figure out what went wrong which is something I was trying to spare/avoid. This is arguably not commonplace...
[^1]: those 3 commits are: https://github.com/jeaye/ncurses-rs/pull/218/commits/34310c5546a27b822552ee9b37f6727405ffaac2 https://github.com/jeaye/ncurses-rs/pull/218/commits/ab8fd269fd37ce8e8970406bbc7d803b5be2e8bc https://github.com/jeaye/ncurses-rs/pull/218/commits/e4a1b4fffe14f88bb91181638273003c00d59ac3 they're the last 3 seen for day Apr. 11 in this view.
I'm out of my depth, here.
I'm out of my depth, here.
Ditto. :-)
I (somehow lol)realize now that I've been too stubborn about it and that @vwbusguy was right about this PR needing to be split into two others. So I'll attempt to do this next, so this PR will remain the build improvement one and a new PR will do ONLY the needed stuff for cursive
and pancurses
to use ncurses-rs
v6 without compile errors.
Closing this to allow someone else in the future to come along and do things better, less verbose and more maintainable(!), and so they won't feel deterred by the existence of this PR to make it their own way :) But more importantly, I may or may not be here in the future to provide support for these changes, as I had originally intended, which would be unpleasant for someone else to have to maintain, I can imagine, so I'd recommend not merging this because of that.
UPDATE: Part of this PR is now duplicated into https://github.com/jeaye/ncurses-rs/pull/220 (for the case when the backwards-compatible(iirc) improvements here aren't wanted, or seem too much to review) but in this PR I've kept the commits that #220 has, for now, so merging either one or both should be possible.
This PR preserves the changes that were already done in v6 here(or, well, until this point) and attempts to "fix" some of the missing things... while also making sure compilation doesn't fail on a bunch of target environments and if it does fail, that the user trying to build it has plenty of helpful information about it. Before this PR it would build on Fedora and Ubuntu (and OpenBSD/FreeBSD but fail to link
ex_5
with--features=menu
) and fail to build on NixOS or Gentoo.This PR was initially spawned from: https://github.com/jeaye/ncurses-rs/pull/201#issuecomment-2045636905
The following were used successfully:
cargo build
cargo test
(though there are 0 tests)cargo build --all-features
cargo test --all-features
cargo build --all-targets
cargo test --all-targets
cargo build --all-targets --all-features
cargo test --all-targets --all-features
... on each of these target environments:
nix-shell
which uses ./shell.nix
file)ncurses
&pkgconf
ncurses
&pkgconf
(ie. do# pkg install ncurses pkgconf
)pkg-config
(which it doesn't findncurses
) and no explicit ncurses installed(butbase75
andcomp75
has the libs respectively the headers) - it builds and passes all tests(even ofcursive
andpancurses
) but the examples look broken/unusable incursive
(TERM=vt220
) - inncurses-rs
doesn't detectF1
to exit fromex_4
andex_5
- this depends onTERM
env.var, for example if it'sTERM=alacritty
they work.LC_CTYPE=en_US.UTF-8
orLANG=en_US.UTF-8
to be set otherwise it looks as if it doesn't have wide chars support socursive
andpancuses
examples look pretty broken.libncurses-dev
)pkg-config
andpkgconf
installed.pkg-config
installed.ex_5
(ld: symbol(s) not found for architecture x86_64
) unless you brew ncurses and set PKG_CONFIG_PATH like said here)... and on the following repos that use
ncurses-rs
(if they applied their own patches for which they've PR already waiting in draft mode, to transition from usingncurses-rs
v5 to v6 after this PR is in):cursive
) - needs acargo update
first and its depcursive_table_view
to be updated with this PR first.Ideal TODO(s):
(left to be done by the maintainer of the repo, unless told otherwise)build.rs
build.rs
build.rs
x86_64-pc-windows-gnu
) (compile,test, maybe also run examples)LC_MESSAGES
were removed (it's in two places) - no idea what about them but it's probably no good to do this.actually this isn't entirely true,(eh,pancurses
is supposed to work on Windows and it usesncurses-rs
,pancurses
usespdcurses-sys
on Windows) howeverbuild.rs
has somecfg!(windows)
in code.pancurses
compiles with this PR, on Windows. (it's unaffected)ex_5
linking which fails on NixOS whencargo test --all-features
is used (is fine on Fedora and Gentoo though) - unclear why it can't find themenu
lib unless specified like:RUSTFLAGS='-l menu' cargo test --features=menu
// fixed by ensuringpkgs.pkg-config
existed in thenix-shell
rustfmt
onbuild.rs
?cargo:rerun-if-env-changed
-L
and the path as separate.arg()
s not merged into one..display()
, we definitely don't want\0
to be part of the path i believe.PATH
and having the same name as compiler executable there, because otherwise doesn't seem to use an env var to set the executable for compiler to use EDIT: it does actually useCC
env.var.) to use a script thus paths would be passed to a script acting as the compiler. Defaulting to using.display()
on Path/PathBuf just like previous code did. But this would be bad if compiler is a script, but it's not something we can control or pre-escape from here really.git bisect
; this means, squashing the commits before merge wouldn't be necessary. For this reason decided not to break that bigbuild.rs
commit into smaller commits anymore, but also because it's doing lots of refactoring.warning: use of deprecated function printw: printw format support is disabled. Use addstr instead
printw
is a rust function accepting only 1 arg, thereforeformat!()
would be used for formatting before calling it.warning: attribute should be applied to a foreign function or static
#[link_name="box"] pub fn box_(w: WINDOW, v: chtype, h: chtype) -> i3
not a foreign function or static
UNCLEARlink_name
doc - ok i think i understand the intention now: we wanted to usencurses::box_
in rust but thencurses::ll:box_
one must map to one namedbox
from the ncurses lib. But I'm not sure why this was done instead of just usingbox
from the start, ah I seeexpected identifier, found reserved keyword
but nowr#box
could be used, except thatbox_
would also have to be used for compatibility.r#box
too for both rust andll
.warning: creating a shared reference to mutable static is discouraged
&wrapped::acs_map as *const chtype
shared reference to mutable static
- apparently nothing now uses this anymore, in this crate, but was added by this commit.cargo clippy
and fix:error: this public function might dereference a raw pointer but is not marked unsafe
str::from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()).to_owned()
ll::copywin(src_win, dest_win, src_min_row, src_min_col,
warning: ncurses@6.0.0: 414 | # warning _FORTIFY_SOURCE requires compiling with optimization (-O)
wouldn't compilethis was due toncurses-rs
for other reasons eg.ERR
OK
TERM=linux
instead ofTERM=xterm
now compiles but ex_7 won't link; and I couldn't get NetBSD to see its own packages, sees 0)NCURSES_RS_RUSTC_LINK_LIB=curses
should work, I estimate.cargo test
though) - even though they happen due to feature not being active.cargo build --features wide
nix-shell
in repo dir (I didn't noticeshell.nix
existed until late) than havingpkgs.ncurses
installed system-wide and then settingPKG_CONFIG_PATH
before runningcargo build
in repo dir. Both work.Build
's.flag_if_supported()
(or just.flag()
) to add compiler flags instead of (the old way)directly via the compiler that was gotten via.try_get_compiler()
, I just kept the old way there so far (maybe there's a good reason for it, unsure).NCURSES_RS_CFLAGS
- well that method will trysearch for an environment variable with appropriate target prefixes
first, so a bunch of differently named env. vars will be checked first kind of breaking compatibility with the way it worked before, although this would be a better way, arguably.cargo test --all-features
compileswarning: unused doc comment
warning: unused
Resultthat must be used
for functions that would Err due to any\0
in &str whenCString::new
processes it..unwrap_or_else(|_|
but show them instead, so start with.unwrap_or_else(|e|
... and showe
- this was introduced by a commit in this PR, but now force pushed as fixed.build.rs
revamping eg. seen hereex_5
will fail on FreeBSD unless it haspkgconf
installed (ie.pkg install pkgconf
)ncurses5
thenncurses
since the latter is version 6(or presumably latest so at least 5 or more), don't we want to use the latest version? Wasncurses
ever lower version thanncurses5
in the past? Since we stop if we findncurses5
, this means we'd be using 5 instead of 6 if somehow both are present. This was the behavior before this PR.If this is checked-marked then I've switched it to: tryI left this as it was because I've no way to test that it broke before and isn't now.ncurses(w)
thenncurses(w)5
, stop on first find; same for 'menu' and 'panel'ex_6
in FreeBSD, see why it's black screen except the bottom shows<-Press Space->
- that being said, comments invim
are very dark blue which are unreadable! - Ok it hasTERM=xterm
in text console, but works well withTERM=vt100
orTERM=vt220
, tho no colors; withTERM=xterm-256color
is that dark blue from vim comments mostly, but still better than that black one from before. Gonna say it's FreeBSD at fault here becausevim
colors are also weird.tinfo(w)
as fallback in case it might exist(like on Gentoo) but won't affect NixOS which doesn't have it(due to theno it's not!); so, whencargo
's gonna ignore if it doesn't existpkg-config
(/pkgconf
) doesn't exist or i've setNCURSES_NO_PKG_CONFIG=1
andNCURSESW_NO_PKG_CONFIG=1
(andncurses
andncursesw5
don't exist on system) which emulatespkg-config
not existing, then, at least on Gentoo,libtinfo(w)
doesn't get linked in, and so for exampleex_5
it will fail to link because we have no fallback for linkingtinfo
lib too, fallback was there only forncurses
lib.And the good thing is ifit doesn't it's just like addingtinfo
isn't needed, such as on NixOS, and we could still tellcargo
viaprintln!("cargo:rustc-link-lib=tinfo");
(ortinfow
) to link it,cargo
will gracefully ignore it if it doesn't exist.(or so I hear, must test)-ltinfo
to linker, fails if it doesn't exist, like on NixOS - must find a way here... I've an idea to try.LC_CTYPE="en_US.UTF-8"
on OpenBSDTERM
is unknown on the system, errors like: error[E0432]: unresolved importconstants::TRUE
- with this fixed, I can definitely go back to trying sabotage linux's netbsd-curses then, which was failing like this before.try_link()
(which this PR added inbuild.rs
) which would fail to find libmenu but say it would still tell cargo to link it, so it worked anyway. Fixed it now to try linking with ncurses if without it fails, thus detecting that libmenu links successfully and thus not show the wrong warning.LC_ALL
,LC_CTYPE
orLANG
are set to anything withutf-8
(case insensitive) in them, then cargo warn thatwide
feature won't display correctly, but only ifwide
feature is enabled. OpenBSD 7.5 has none of these set, by default (maybe I didn't follow the install instructions, else I would've set them manually, but they're for sure not set automatically)UTF-8
exactly on OpenBSD, else it won't work. Howeveren
oren_US
or even`(empty) can be used in any case (we don't check for these though), so even
LANG=.UTF-8` works (but not on Gentoo for example)--features=not_OnceLock
and pinning build depcc="=1.0.92
and changingrust-version="1.57.0"
inCargo.toml
.cc="=1.0.92"
passescargo build
with MSRV1.53.0
but notcargo test
unless MSRV is1.63.0
cc="=1.0.95"
needs1.63.0
cc="=1.0.18"
(the pre-PR value) has MSRV1.19.0
(forcargo build
) but it doesn't passcargo test
with any rust version.cc="=1.0.40"
(randomly picked) passescargo test
for MSRV1.40.0
(coincidence) andcargo build
MSRV is1.19.0
.replaceremove OnceLock and just don't care about repetitions forOnceLock
inbuild.rs
which requires MSRV1.70.0
with something else maybeAtomicBool
+Mutex
which have MSRV1.0.0
cargo:rerun-if-env-changed
, MSRV is now1.57.0
, but remember thatcc
is1.0.95
at the moment (Cargo.lock
not being in the repo) thus MSRV is1.63.0
just likecc
needs.cargo build --features=test_build_rs_of_ncurses_rs
which was testing only some of thebuild.rs
internal code. This testing would've only be useful for devs ofncurses-rs
basically, but it wasn't testing enough of the code anyway. Did help during the PR though. Removed as per this.