forked from mesonbuild/meson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement rustc controlled whole-archive linking
Rustc as of version 1.61.0 has support for controlling when whole-archive linking takes place, previous to this it tried to make a good guess about what you wanted, which worked most of the time. This is now implemented. Additionally, rustc makes some assumptions about library names (specifically static names), that meson does not keep. This can be fixed with rustc 1.67, where a new +verbatim modifier has been added. We can then force rustc to use the name we give it. Before that, we can sneak through `/WHOELARCHIVE:` in cases of dynamic linking (into a dll or exe), but we can't force the archiver to do what we want (rustc considers the archiver to be an implementation detail). The only solution I can come up with is to copy the library to the format that rustc expects. I've run into some issues with that as well, so we warn in that case. The decisions to leave static into static broken on MSVC for 1.61–1.66 was made because: 1) The work around is non-trivial, and we would have to support that workaround for a long time 2) The number of users of Rust in Meson is small 3) The number of users of Rust in Meson on Windows, with MSVC is tiny 4) Using rustup to update rustc on windows is trivial, and solves the problem completely Fixes: mesonbuild#10723 Fixes: mesonbuild#11247 Co-authored-by: Nirbheek Chauhan <nirbheek@centricular.com>
- Loading branch information
Showing
14 changed files
with
113 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
#![crate_name = "stuff"] | ||
|
||
pub fn explore() -> &'static str { "librarystring" } | ||
extern "C" { | ||
fn c_value() -> i32; | ||
} | ||
|
||
pub fn explore() -> String { | ||
unsafe { | ||
format!("library{}string", c_value()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int c_value(void) { | ||
return 7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
project('rust static library', 'rust') | ||
project('rust static library', 'rust', 'c') | ||
|
||
l = static_library('stuff', 'stuff.rs', install : true) | ||
o = static_library('other', 'other.rs') | ||
v = static_library('value', 'value.c') | ||
l = static_library('stuff', 'stuff.rs', link_whole : [o, v], install : true) | ||
e = executable('prog', 'prog.rs', link_with : l, install : true) | ||
test('linktest', e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub fn explore( | ||
value: i32, | ||
) -> String { | ||
format!("library{}string", value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
extern crate stuff; | ||
|
||
fn main() { println!("printing: {}", stuff::explore()); } | ||
fn main() { | ||
println!("printing: {}", stuff::explore()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
#![crate_name = "stuff"] | ||
|
||
pub fn explore() -> &'static str { "librarystring" } | ||
extern crate other; | ||
|
||
extern "C" { | ||
fn c_explore_value() -> i32; | ||
} | ||
|
||
pub fn explore( | ||
) -> String { | ||
unsafe { | ||
other::explore(c_explore_value()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int | ||
c_explore_value (void) | ||
{ | ||
return 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <stdio.h> | ||
|
||
void hello_from_rust(void); | ||
|
||
static void hello_from_c(void) { | ||
printf("Hello from C!\n"); | ||
} | ||
|
||
void hello_from_both(void) { | ||
hello_from_c(); | ||
hello_from_rust(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
#include <stdio.h> | ||
|
||
void f(); | ||
void hello_from_both(); | ||
|
||
int main(void) { | ||
printf("Hello from C!\n"); | ||
f(); | ||
hello_from_both(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#![crate_name = "stuff"] | ||
|
||
#[no_mangle] | ||
pub extern fn f() { | ||
pub extern "C" fn hello_from_rust() { | ||
println!("Hello from Rust!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters