Tree-sitter: `ts_record_realloc` is not provided in release+debuginfo builds (link-time error)

Created on 9 Oct 2020  Â·  5Comments  Â·  Source: tree-sitter/tree-sitter

With rustc 1.47, with a release build, I'm getting tons of linker errors related to ts_record_realloc and friends.

  • tree-sitter version: 0.17.0
  • tree-sitter-highlight version: 0.3.0
  • OS: Linux (ArchLinux on WSL2)
  = note: /usr/sbin/ld: /home/amos/ftl/futile/target/release/deps/libtree_sitter-298d031b2e4e0adc.rlib(lib.o): in function `ts_realloc':
/home/amos/.cargo/registry/src/github.com-1ecc6299db9ec823/tree-sitter-0.17.0/src/././././././alloc.h:29: undefined reference to `ts_record_realloc'
/usr/sbin/ld: /home/amos/ftl/futile/target/release/deps/libtree_sitter-298d031b2e4e0adc.rlib(lib.o): in function `ts_calloc':
/home/amos/.cargo/registry/src/github.com-1ecc6299db9ec823/tree-sitter-0.17.0/src/././././././alloc.h:25: undefined reference to `ts_record_calloc'
(etc.)

Extract of Cargo.toml:

[profile.release]
debug = 1 # less debug info
incremental = true # faster recompiles

[profile.dev.package."*"]
opt-level = 2

[dependencies]
tree-sitter-highlight = "0.3.0"
tree-sitter-collection = { git = "https://github.com/fasterthanlime/tree-sitter-collection", rev = "9fc44e34047da3fefe2faf91f9359a4374097286" }
tree-sitter = "0.17.0"

Here's a link to the full Cargo.toml.

Cargo invocation:

$ cargo build --release

I'm seeing similar errors with both GNU ld and lld.

Note that debug builds (just cargo build) build and link just fine.

Unfortunately my repository is closed-source, but if someone wants to take a look I can add them to the private repo for a repro. (I realize that's not ideal at all).

Also note that checking out tree-sitter and compiling it in release mode works fine on my machine.

I'm thinking something in binding_rust/util.rs is a bit too smart, and breaks sometimes, but I can't really tell what to do about it right now.

Thanks for taking a look ✨

bug

All 5 comments

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.97. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Okay, this line in the Cargo.toml is what breaks it:

[profile.release]
debug = 1

I'm betting that it's because of the cfg(debug_assertions).

This is no longer a blocker for me so it feels like a nice "fix some day" issue now.

You can easily reproduce it by just checking out tree-sitter itself, editing its own Cargo.toml to add the two lines above (the top-level Cargo.toml - the workspace one), and running cargo build --release.

I'm thinking just changing this

https://github.com/tree-sitter/tree-sitter/blob/857a9ed07b983e2e6cff6dc851fcf9b37aec8e5a/lib/binding_rust/build.rs#L24-L27

To something like:

println!("cargo:rerun-if-env-changed=PROFILE");
if env::var("PROFILE").map(|s| s == "debug").unwrap_or(false) { {
  config.define("TREE_SITTER_TEST", "");
}

Would fix it. See https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts

Thanks for looking into this! I think your suggested fix is right.

Thanks for the fix! ✨💙

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ubolonton picture ubolonton  Â·  3Comments

francisdb picture francisdb  Â·  3Comments

Aerijo picture Aerijo  Â·  3Comments

Dekker1 picture Dekker1  Â·  3Comments

worudso picture worudso  Â·  4Comments