rustdirectxrust-cargodirectx-12

How to export symbols in rust binaries


I'm learning DirectX and rust and i want to use the DX Agility SDK in my project. In order to do so i need to export two symbols in the final executable so that DirectX can load the best dll available in the system as stated in this guide.

This is what i tried:

#[used]
#[no_mangle]
#[export_name = "D3D12SDKVersion"]
pub static D3D12_SDK_VERSION: u32 = 711;    // SDK 1.711.3-preview

Then I used the dumpbin tool to check if the executable contains the exported symbol (it didn't):

dumpbin .\test.exe /EXPORTS
Microsoft (R) COFF/PE Dumper Version 14.40.33521.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file .\test.exe

File Type: EXECUTABLE IMAGE

  Summary

        1000 .data
        4000 .pdata
       10000 .rdata
        1000 .reloc
       33000 .text

But I expect it to output something like this:

dumpbin .\test.exe /EXPORTS
Microsoft (R) COFF/PE Dumper Version 14.40.33521.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file .\test.exe

File Type: EXECUTABLE IMAGE

Section contains the following exports for WinLauncher.exe

    00000000 characteristics
    FFFFFFFF time date stamp
        0.00 version
           1 ordinal base
           2 number of functions
           2 number of names

    ordinal hint RVA      name

          1    0 00030220 D3D12SDKVersion

  Summary

        1000 .data
        4000 .pdata
       10000 .rdata
        1000 .reloc
       33000 .text

I really have no idea how to set up the compiler and the build script to export those costants. Any help is really appreciated!


Solution

  • Rust by default does not export things from executables. There exists the -Z export-executable-symbols nightly flag that can be passed to rustc (e.g. cargo +nightly rustc -- -Zexport-executable-symbols) that does export them, but on stable I don't believe this can be done.