-
Notifications
You must be signed in to change notification settings - Fork 165
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
Replace hyper with reqwest #330
Conversation
@spl Thanks for undertaking this! After a quick skim, it looks like you're very much on the right track here. No major comments about what's in the diffs thus far. As for testing … Tectonic's testing for this kind of thing is not as thorough as I'd like. To test this particular subsystem well, I'm pretty sure you'd need to stand up your own local HTTP server and hardcode various scenarios. That wouldn't be impossible, but not easy either. Might be worth taking a look at other comparable crates and see if they have any clever approaches to testing that we can borrow. |
Just an observation: This update adds a bunch of new dependencies from the async/tokio ecosystem.
It might be nice to feature-gate the networking code with an on-by-default flag. |
@Mrmaxmeier That's a good point to raise. I'm surprised that tokio/async adds that much to the binary size ... isn't that stuff all supposed to compile down nice and efficiently? But |
Based on a rough diff of
I'm sure we could. It probably won't be as convenient, esp. for things like redirect handling and proxy handling. Are there any other HTTP client crates that should also be considered? |
This StackOverflow post presents a similar concern about binary size and one answer mentions some smaller-sized HTTP clients. I've looked through them, but I'm not seeing one that is going to be better and better maintained than |
On redirect handling: It seems like there is no plan to implement this in On proxy: There is a |
I've done a bit more research on
It is possible to disable the |
I looked at I'm leaning toward biting the bullet on the larger binary size and using As for a Cargo feature to control the HTTP dependencies, I don't know what that would look like. I suppose, if disabled, would Thoughts? What should be the next step? |
I also lean towards biting the bullet on this one. I'd like to keep the binary small, but in my view it's more important to deliver good functionality, and adding the ability to honor HTTP proxy settings would be valuable. It looks like there's a gap in the ecosystem for a get-me-the-damn-file HTTP client crate that supports things like redirects and proxies (thanks for researching this, @spl) — if one comes along, we can definitely revisit this in the future. If we added a feature to disable HTTP, people could use the local cache and/or locally stored bundle files, although there's very little in the way of infrastructure to support the latter. (In principle you can build your own following the instructions in the |
@spl BTW as far as you're concerned, is this still a "draft" PR, or is this ready for testing and review? |
I think the basic change is done, assuming I got my logic right. My current thoughts on what needs to be done:
I can look at it again tomorrow. I checked the “allow edits from maintainers” checkbox if you want to push directly to this branch. (But preferably no force-pushes since it's now shared.) |
There is an (allowed) error building with
This seems to be due to the use of [dependencies]
proc-macro2 = "0.4" Researching the issue, I came upon #259, which is related to the same problem but with I'm not aware of any way of using I'm not sure, but there might have been some recent work toward a resolution of this problem in rust-lang/rust#58575 (tracking issue: rust-lang/rust#59302). @malbarbo: I see that you commented there. Could you help us understand this? |
@spl: See rust-lang/cargo#5266 for the upstream issue. Setting the environment variable |
@sanmai-NL Thanks for the pointer. If we set the |
@sanmai-NL Thanks. I did read that issue but didn't understand it at the time. Now, having read some of RFC 1721, I think I get the gist of it. The important part is this, I believe:
To clarify what I understand, the |
Codecov Report
@@ Coverage Diff @@
## master #330 +/- ##
==========================================
- Coverage 42.12% 39.62% -2.51%
==========================================
Files 135 135
Lines 63366 59506 -3860
==========================================
- Hits 26694 23579 -3115
+ Misses 36672 35927 -745
Continue to review full report at Codecov.
|
Since I don't think it's easy to resolve the As far as I'm concerned, this PR is ready to go. |
It's not entirely true, see rust-lang/rust#55566. |
@mati865 Thanks for chiming in with that. The summary in the last comment, rust-lang/rust#55566 (comment), if true, sounds attractive. However, the gist of preceding comments seem to imply that the PR'd solution was not preferred over the one in rust-lang/rust#58575, to which I linked above. But I'm sure I'm missing a lot of context here. That said, for Tectonic, I think it would be better to skip on the issue for now. If change comes later to the musl target, Tectonic can always be updated to take advantage of it then. (After all, we're only talking about a few lines of HTTP header type-safety. What can go wrong? 🙄) |
Discussions about musl target desing were scattered all over the place so it's hard to get what is going on.
That's the current standing. It won't fix Procedural Macros though. |
Later versions of hyper (0.11, 0.12) have dropped a number of features, and reqwest has picked up those features. This change migrates the HTTP code from using an old version of hyper to using the latest version of reqwest. Other changes: * Remove old and unused hyper_seekable * Add UnexpectedHttpResponse
@spl I've locally rebased this onto current |
No, go for it.
|
Ah, it seems that the static target once again has a proc-macro issue, due to |
Ohhhhhhh — I figured something out about the MUSL issue. It might have been obvious to other people, but it wasn't to me, so in case it comes in handy: What I didn't get, until now, is that one of the key facets of the proc-macro problem is the distinction between the cross-compilation use case and the ... non-cross-compilation one. Proc-macro crates have to be dynamically linked into the compiler. When you're cross-compiling, that means that they're built for the build platform/toolchain not the host platform/toolchain. So if you're cross-compiling for MUSL from a regular Linux host, things work fine. It gets sticky when, as our build system currently tries, both "host" and "build" are static/MUSL. I am pretty sure that if we could set things up to compile the static executable via cross-compilation, it would work. I don't know if we can set things up to be able to do that while also pulling in external static libraries such as Freetype. (edit: note that here I am using GNU terminology, where "build" is the machine that you're building on and "host" is the machine your program will run on. In Rust-land, it seems like the common terminology is that "host" is the machine you're building on and "target" is the machine it will run on. [In GNU-land, "target" is the architecture that the program you're building will target, if it happens to be a compiler of some sort. If you cross-compile a cross-compiler, the three platforms might all be different.]) |
12 hours later ... it works! I have a proof-of-concept that creates a static executable and includes the procedural macro features. So @spl go ahead and put Bad news #1: the executable that I'm creating right now weighs in at 90 MB. Bad news #2: I couldn't figure out a way to get it working that didn't involve manually cross-compiling all of our system deps in the musl target, so that's fun. It's not pretty, but this is a problem that a lot of people have been struggling with: see for instance emk/rust-musl-builder#65, rust-lang/rust#36710 . So I'm pretty happy that I figured something out here. Code forthcoming ... |
After much wailing and gnashing of teeth, I think I have an approach that fixes the static Linux build in the face of proc-macro usage. In particular, proc-macros can work if we cross-compile. Here, we set up a Docker container with a fakey cross-compilation setup that farms out the work to an Alpine Linux chroot. That way we can take advantage of the statically linked, MUSL-based libraries that Alpine provides. We can now build static Tectonic without having to gate any features and using Rust stable, so this should update the CI to not ignore the problem if the static build fails.
Even better version pushed! We're not manually compiling the deps anymore, and the final executable is down to 60 MB. edit: log of the static build |
This reverts commit b962502. (This commit has been squashed into the one adding support for reqwest.)
The Travis failure is some unrelated, probably transient, issue on macOS, and Circle has a QEMU timeout. The static build on Travis succeeded, proc macros and all (log). Going to go ahead and merge! |
I haven't looked at everything you've done, @pkgw, but it certainly sounds good. As an aside, you might want to update the Travis-CI macOS image to |
This is an attempt to replace hyper with reqwest.
I'm not familiar with either package, and I'm still pretty new to Rust, so I'm posting a draft PR to get feedback before finalizing it. Also, I left in my intermediate commits, but in the end, it would probably be better to squash them before merging.
My goal is to bring in a newer HTTP dependency than hyper 0.10. First, reqwest seems pretty decent for what's being done in Tectonic. Second, it will allow for a simple solution to introducing a proxy (#59).
Some highlights:
client
,req
) where it didn't seem like they added much to the code.UnexpectedHttpResponse
for several errors. I'm not sure if I did everything correctly there.MAX_HTTP_REDIRECTS_ALLOWED
. You may want to do something different here.