Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD cycle detected when const-evaluating #157

Closed
ryanavella opened this issue Dec 27, 2023 · 5 comments
Closed

FreeBSD cycle detected when const-evaluating #157

ryanavella opened this issue Dec 27, 2023 · 5 comments

Comments

@ryanavella
Copy link

I get the following error both when running cargo install https and git clone ... && cd http && cargo build (i.e. latest commit on master branch)

I'm not exactly sure what your build.rs is doing, but FreeBSD has the function getbsize which might be helpful here?

error[E0391]: cycle detected when const-evaluating + checking `util::os::non_windows_non_macos::BLKGETSIZE`
  --> http/target/debug/build/https-db5e3b91851aac53/out/ioctl-data/ioctl.rs:3:1
   |
3  | static BLKGETSIZE: libc::c_ulong = BLKGETSIZE as libc::c_ulong;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires const-evaluating + checking `util::os::non_windows_non_macos::BLKGETSIZE`...
  --> http/target/debug/build/https-db5e3b91851aac53/out/ioctl-data/ioctl.rs:3:36
   |
3  | static BLKGETSIZE: libc::c_ulong = BLKGETSIZE as libc::c_ulong;
   |                                    ^^^^^^^^^^
   = note: ...which again requires const-evaluating + checking `util::os::non_windows_non_macos::BLKGETSIZE`, completing the cycle
note: cycle used when elaborating drops for `util::os::non_windows_non_macos::file_length_impl`
  --> src/util/os/non_windows_non_macos.rs:39:47
   |
39 |             let ok = unsafe { ioctl(dev_file, BLKGETSIZE, &mut block_count as *mut c_ulong) } == 0;
   |                                               ^^^^^^^^^^
   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

For more information about this error, try `rustc --explain E0391`.
error: could not compile `https` (bin "http") due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `https` (bin "httplz") due to previous error

Meta

rustc --version --verbose:

rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: x86_64-unknown-freebsd
release: 1.74.1
LLVM version: 17.0.4

cargo --version --verbose

cargo 1.74.1 (ecb9851af 2023-10-18)
release: 1.74.1
commit-hash: ecb9851afd3095e988daaa35a48bc7f3cb748e04
commit-date: 2023-10-18
host: x86_64-unknown-freebsd
libgit2: 1.7.1 (sys:0.18.0 vendored)
libcurl: 8.4.0-DEV (sys:0.4.68+curl-8.4.0 vendored ssl:OpenSSL/1.1.1u)
ssl: OpenSSL 1.1.1u  30 May 2023
os: FreeBSD 14.0-RELEASE-p3 [64-bit]

uname -imrs

FreeBSD 14.0-RELEASE amd64 GENERIC
@ryanavella
Copy link
Author

ryanavella commented Dec 27, 2023

I tried the following quick hack to bypass build.rs:

-#[cfg(any(target_os = "windows", target_os = "macos"))]
+#[cfg(any(target_os = "windows", target_os = "macos", target_os = "freebsd"))]
 fn get_ioctl_data() {}
 
-#[cfg(not(any(target_os = "windows", target_os = "macos")))]
+#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "freebsd")))]
 fn get_ioctl_data() {
     let ioctl_dir = Path::new(&env::var("OUT_DIR").unwrap()).join("ioctl-data");

Compilation proceeded even further but it still produces an error:

error: couldn't read http/target/debug/build/https-db5e3b91851aac53/out/ioctl-data/ioctl.rs: No such file or directory (os error 2)
 --> src/util/os/non_windows_non_macos.rs:9:1
  |
9 | include!(concat!(env!("OUT_DIR"), "/ioctl-data/ioctl.rs"));
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `https` (bin "http") due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `https` (bin "httplz") due to previous error

So unfortunately I don't think there is a quick-fix. Currently FreeBSD is compiled as if it were Linux, but FreeBSD doesn't have an ioctl parallel to BLKGETSIZE so I think it may need its own separate cfg.

@ryanavella
Copy link
Author

@nabijaczleweli You mentioned over in #158

this should probably use the same methodology as I do in voreutils (https://git.sr.ht/~nabijaczleweli/voreutils/tree/02bcd701febb555147b67e0fa7fdc1504fe3cca2/item/cmd/wc.cpp#L155-177), which includes Linux, {Free,Net}BSD, OpenBSD, and the illumos gate. maybe drop the illumos gate. I'll probably do this in a bit but this is incredibly annoying to do in Rust

Can you clarify which part is "incredibly annoying" about porting this from C++ to Rust? Is it the fact that macro-expanding requires invoking cc in build.rs?

I'm wondering if perhaps we could pre-expand it to a constant and trust that the constant is unlikely to change.

If you take a look at git-blame for FreeBSD's DIOCGMEDIASIZE constant, the most recent commit was 13 years ago, and even that only modified a comment and not the macro itself. So I do think the macro is likely relatively stable.
https://github.com/freebsd/freebsd-src/blob/fb03f7f8e30d21ad74ef7a3ee1b4a7e546fef852/sys/sys/disk.h#L35

@nabijaczleweli
Copy link
Collaborator

"Closes:" tag closed the PR but not the issue? Must be a wednesday in githubland. Anyway, try with current develop (at least be7de13)?

@ryanavella
Copy link
Author

Excellent, be7de13 works for me, thanks for looking into this!

@nabijaczleweli
Copy link
Collaborator

Released in v2.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants