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

Fix contractenvmetav0 not being emitted (again) #388

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions macros/src/derive_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,6 @@ pub fn derive_fn(
pub mod #hidden_mod_ident {
use super::*;

/// Exposing the env meta XDR ensures that the link section in the
/// SDK is included in the build for this contract function. See
/// [soroban_sdk::__env_meta_xdr] for more details.
pub fn env_meta_xdr() -> &'static[u8] {
soroban_sdk::__env_meta_xdr()
}

#[deprecated(note = #deprecated_note)]
#export_name
pub fn invoke_raw(env: soroban_sdk::Env, #(#wrap_args),*) -> soroban_sdk::RawVal {
Expand Down
28 changes: 20 additions & 8 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,29 @@ fn handle_panic(_: &core::panic::PanicInfo) -> ! {
core::arch::wasm32::unreachable()
}

/// Env meta XDR returns the env meta XDR that describes the environment this
/// SDK is built with. This link section exists inside an exported function
/// which is imported by each contract function to ensure that the link section
/// is referenced by every object file that gets built, to ensure the link
/// section isn't only referenced in an object file that gets discarded.
/// __link_sections returns and does nothing, but it contains link sections that
/// should be ensured end up in the final build of any contract using the SDK.
///
/// In Rust's build system sections only get included into the final build if
/// the object file containing those sections are processed by the linker, but
/// as an optimization step if no code is called in an object file it is
/// discarded. This has the unfortunate effect of causing anything else in
/// those object files, such as link sections, to be discarded. Placing anything
/// that must be included in the build inside an exported function ensures the
/// object files won't be discarded. wasm-bindgen does a similar thing to this,
/// and so this seems to be a reasonably accepted way to work around this
/// limitation in the build system.
///
/// This has an unfortunate side-effect that all contracts will have a function
/// in the resulting WASM named `_`, however this function won't be rendered in
/// the contract specification. The overhead of this is very minimal on file
/// size.
///
/// See https://github.com/stellar/rs-soroban-sdk/issues/383 for more details.
#[doc(hidden)]
pub fn __env_meta_xdr() -> &'static [u8] {
#[export_name = "_"]
fn __link_sections() {
#[cfg_attr(target_family = "wasm", link_section = "contractenvmetav0")]
static __ENV_META_XDR: [u8; env::meta::XDR.len()] = env::meta::XDR;
&__ENV_META_XDR
}

pub use soroban_sdk_macros::{contractimpl, contracttype, ContractType};
Expand Down