rust-lang / rust-lang/libs-team
`std::file!`/`core::file!` should normalize to using forward slashed path instead.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 178
- Forks
- 28
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
I'm doing a sick hack to generate Rust callsite from C++ using export_name:
src/main.rs:
fn main() {
println!("{:?}", unsafe { from_cpp() });
println!("Hello, world!");
}
#[unsafe(no_mangle)]
#[unsafe(export_name = concat!("foo", "$", core::file!()))]
unsafe extern "C" fn foo(n: usize) -> usize {
println!("cpp passed us: {}", n);
n + 1
}
unsafe extern "C" {
fn from_cpp() ;
}
Then I can have it in C++:
foo.cpp
#include <stdio.h>
extern "C" int foo_src_main(int a)
#ifdef _MSC_VER
__pragma(comment(linker, "/alternatename:foo_src_main=foo$src\\main.rs"))
#elif defined(__clang__)
asm("foo$src/main.rs")
#else
asm("\"foo$src/main.rs\"")
#endif
;
extern "C"
{
void from_cpp()
{
printf("rust gave us: %d\n", foo_src_main(1234));
}
}
This is then linked with cc and then built as an executable and it worked. However on Windows, I noticed core::file!() actually expands to src\\main.rs. We should normalize this behavior so that we can go easy on the C++ call site code generator.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example with core::file!() on Windows and compare its expansion with the forward-slash form used in src/main.rs and foo.cpp. Locate the file! macro implementation and any related tests, then verify that the macro produces forward-slash paths without breaking existing platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100