question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mixing generated and static sources with rust

See original GitHub issue

Rust works somewhat differently than languages like C do, it uses the filesystem hierarchy to find imports, and lacks a mechanism like C’s -I. This makes using generated sources quite difficult, as meson separates generated sources and static sources into the build and source trees.

The most obvious solution to fix this is to copy or link the static sources into the build tree so that the hierarchy looks like what rustc expects. It would be best if this could be done transparently, and only when there are generated sources as well as

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dcbakercommented, Jan 6, 2021

Okay, it looks like the way that cargo handles this is with an environment variable (of course). Basically you add something like:

include!(concat!(env!("OUT_DIR"), "/generated.rs"));

in your source, and cargo set’s OUT_DIR to the place it puts the generated files.

That is probably workable (rust really like environment variables, so we probably need a solution for them anyway 😕), with the one caveat that we need to ensure that all of the generated sources end up in a single output directory. That’s ugly, but probably workable.

0reactions
dcbakercommented, Jan 6, 2021

https://github.com/rust-lang/rust/issues/78913

I seem to be mis-remembering a bit of this discussion, it’s been a while. This may actually be possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rust - The Meson Build system
Mixing Generated and Static sources ... You can use a structured_src for this. Structured sources are a dictionary mapping a string of the...
Read more >
Linkage - The Rust Reference - Learn Rust
The compiler supports various methods to link crates together both statically and dynamically. This section will explore the various methods to link crates ......
Read more >
Interacting with assembly in Rust - LogRocket Blog
The quickest and easiest way to generate assembly is with the compiler itself. This method doesn't require installing any additional tools, but ...
Read more >
Mixing static and dynamic libraries in Rust FFI - Stack Overflow
My executable Rust crate uses a native library libfoo.a which depends on a shared library libbar.so , but does not expose it at...
Read more >
Linkage - The Rust Reference
--crate-type=dylib , #[crate_type = "dylib"] - A dynamic Rust library will be produced. This is different from the lib output type in that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found