ptal / oak

A typed parser generator embedded in Rust code for Parsing Expression Grammars
Apache License 2.0
142 stars 14 forks source link

Oak causes Rust to build any project including "oak_runtime" as dynamically linked #97

Closed jasonl closed 7 years ago

jasonl commented 7 years ago

TL;DR: Because oak_runtime includes extern crate syntax, but is a runtime crate rather than a compiler plugin, rustc produced a dynamically linked executable instead of a statically-linked one, which makes distribution difficult/impossible.

According to Alex Chrichton at https://github.com/rust-lang/rust/issues/32996, it is intended behaviour for rustc to switch to using dynamic linking when syntax is referred to in a project, because the rlib for that crate is not included with the Rust standard library distribution, but only a .so library, presumably on the assumption that only the compiler will need to dynamically link to that library when it loads a compiler plugin.

However, because of Rust's linking strategy resolution (as detailed in the comments above), any of the final libraries referring to it will cause Rust to decide to dynamically link all libraries for the executable produced.

This becomes a problem at it precludes the use of the x86_64-unknown-linux-musl architecture, which is useful for packaging up the Rust executable with the very lightweight Alpine Linux in a docker container for deployment, or even using a full distribution like Ubuntu, as the produced executable won't run without the dynamic libraries in the rust toolchain - again making it almost impossible to distribute. In effect, any rust program that includes oak_runtime can only be executed with cargo run, which is not a suitable thing for production systems.

It seems the commit which introduced this issue is https://github.com/ptal/oak/commit/41e355feacd049cab6a525210f06eebf9d73633a

ptal commented 7 years ago

Hello,

I ran into this problem months ago with a project of mine and asked help on the IRC since I could not figure out what was the problem. Actually, I did not have a conclusive answer and naively waited for a "fix" of rustc and used nasty hack to distribute oak (exporting rust libraries in the path...).

I removed the dependency to syntax. Actually, I wanted to use the Span of rustc to be more "uniform" with the span Oak produces. I just created a span structure and remove the dependency of syntax. The new version is on crate as 0.4.8 for oak and 0.4.3 for oak-runtime.

Thank you so much for your explanations!! Best

jasonl commented 7 years ago

Awesome, the new version works great! Thanks so much.