microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.44k stars 493 forks source link

Possible link attributes generated for things outside Windows SDK #706

Closed Awfa closed 3 years ago

Awfa commented 3 years ago

build!ing Windows::Win32::FileSystem::NetShareEnum generates:

#[link(name = "srvcli")]
extern "system" {
    pub fn NetShareEnum(
        servername: super::SystemServices::PWSTR,
        level: super::NetManagement::Net_level,
        bufptr: *mut *mut u8,
        prefmaxlen: u32,
        entriesread: *mut u32,
        totalentries: *mut u32,
        resume_handle: *mut u32,
    ) -> u32;
}

which tells Rust to link to srvcli.lib.

But it can't find it in my window's sdk, which has the following libs:

AclUI, ActiveDS, ADSIid, AdvAPI32, advpack, ahadmin, amsi, amstrmid, api-ms-win-net-isolation-l1-1-0, appmgmts, appmgr, appnotify, audiobaseprocessingobject, AudioBaseProcessingObjectV140, audioeng, audiomediatypecrt, AuthZ, aux_ulib, avifil32, avrt, basesrv, bcrypt, Bits, BluetoothApis, bthprops, BufferOverflow, BufferOverflowU, Cabinet, certadm, certca, certcli, CertIdl, CertPolEng, cfgmgr32, Chakrart, cldapi, clfsmgmt, clfsw32, ClusApi, ComCtl32, ComDlg32, CompPkgSup, compstui, computecore, computenetwork, computestorage, ComSvcs, CoreMessaging, corrEngine, Credui, Crypt32, cryptdll, CryptNet, cryptui, cryptxml, cscapi, cscdll, d2d1, d3d10, d3d10_1, d3d11, d3d12, d3d9, d3dcompiler, d3dcsx, d3dcsxd, davclnt, DbgEng, DbgHelp, DbgModel, dciman32, dcomp, ddraw, devenum, deviceaccess, devmgr, dflayout, DhcpCSvc, DhcpCSvc6, dhcpsapi, difxapi, dinput8, dloadhelper, dmoguids, dmprocessxmlfiltered, DnsAPI, dnscrcli, dnslib, dnsperf, dnsrpc, dnsrslvr, dpx, drt, drtprov, drttransport, dsound, DSProp, dssec, dststlog, DSUIExt, DtcHelp, dwmapi, dwrite, dxcompiler, dxgi, dxguid, dxtmsft, dxtrans, dxva2, eappcfg, eappprxy, easregprov, efswrt, ehstorguids, elfapi, els, ElsCore, esent, evr, FaultRep, feclient, FhSvcCtl, fileextd, fltLib, fontsub, FrameDyd, FrameDyn, fwpuclnt, fxsutility, Gdi32, gdiplus, glmf32, GlU32, GPEdit, gpmuuid, hbaapi, hhsetup, hid, HLink, hrtfapo, Htmlhelp, httpapi, iashlpr, Icm32, Icmui, icuin, icuuc, IEPMAPI, iesetup, ImageHlp, imgutil, Imm32, infocardapi, inkobjcore, InputInjection, inseng, iphlpapi, Iprop, irprops, iscsidsc, jsrt, kerbcli, kernel32, kernel32legacylib, keycredmgr, KSProxy, ksuser, ktmw32, LoadPerf, locationapi, Lz32, magnification, MAPI32, mbnapi_uuid, mciole32, mdmlocalmanagement, MDMRegistration, Mf, Mfcore, mfgphone, Mfplat, mfplay, mfreadwrite, mfsensorgroup, Mfsrcsnk, mfuuid, MgmtAPI, mi, mincore, mincore_downlevel, MMC, mmdevapi, mmos, Mpr, Mprapi, mprsnap, MqOA, MqRt, MrmSupport, msaatext, MSAcm32, MSAJApi, Mscms, MsCtfMonitor, msdasc, msdelta, msdmo, msdrm, Msi, MSImg32, mspatcha, mspatchc, mspbase, msports, MSRating, MSTask, msv1_0, msvfw32, MsWSock, MsXml2, msxml6, Mtx, mtxdm, muiload, nanosrv, ncrypt, nddeapi, ndfapi, ndproxystub, NetAPI32, netlib, NetSh, newdev, ninput, normaliz, nt, ntdll, ntdllp, ntdsa, NtDsAPI, ntdsatq, ntdsetup, ntfrsapi, ntlanman, ntmarta, NtQuery, ntstc_libcmt, ntstc_msvcrt, objsel, odbc32, odbcbcp, odbccp32, OemLicense, Ole32, OleAcc, OleAut32, olecli32, oledb, OleDlg, olesvr32, ondemandconnroutehelper, OneCore, OneCoreUAP, OneCoreUAP_apiset, OneCoreUAP_downlevel, OneCore_apiset, OneCore_downlevel, OpenGL32, opmxbox, osptk, p2p, p2pgraph, pathcch, Pdh, PeerDist, PhotoAcquireUID, PortableDeviceGuids, powrprof, prntvpt, ProjectedFSLib, propsys, Psapi, quartz, query, qwave, RASAPI32, RASDlg, rasuser, resutils, rilProxy, rimapi, rometadata, rpcexts, Rpcns4, rpcproxy, RpcRT4, rpcutil, rstrtmgr, Rtm, rtutils, RTWorkQ, runtimeobject, samlib, samsrv, SAPI, sas, sbtsv, SCardDlg, scecli, scesrv, schannel, ScrnSave, ScrnSavW, SearchSDK, Secur32, security, sens, SensAPI, sensorsapi, SensorsUtils, SetupAPI, Sfc, shcore, shdocvw, shell32, ShFolder, ShLwApi, slc, slcext, slwga, SnmpAPI, spoolss, SpOrder, SrClient, srpapi, ssdpapi, Sti, strmbase, strmiids, strsafe, structuredquery, Svcguid, swdevice, synchronization, t2embed, Tapi32, tapi32l, taskschd, tbs, tdh, tokenbinding, Traffic, TranscodeImageUID, tsec, tspubplugincom, twinapi, txfw32, ualapi, UIAutomationCore, umpdddi, Urlmon, UsbPmApi, User32, UserEnv, USP10, Uuid, Uxtheme, vccomsup, vds_uuid, Version, vertdll, Vfw32, Virtdisk, vmdevicehost, vmsavedstatedumpprovider, vscmgr, vssapi, vss_uuid, vstorinterface, wbemuuid, wcmapi, wcmguid, wdsbp, wdsClientAPI, wdsmc, wdspxe, wdstptc, WebServices, websocket, wecapi, Wer, wevtapi, WiaGuid, wiaservc, wiautil, WinBio, windows, windows, windows, windows, WindowsApp, WindowsApp_downlevel, windowscodecs, windowssideshowguids, winfax, winhttp, WinHvEmulation, WinHvPlatform, WinInet, winml, WinMM, winsatapi, winscard, WinSpool, winsqlite3, winsta, WinStrm, WinTrust, winusb, wlanapi, wlanui, Wldap32, Wldp, wmcodecdspuuid, wmip, wmiutils, wmvcore, wnvapi, wofutil, workspaceax, wpprecorderum, WS2_32, wsbapp_uuid, wsbonline, wscapi, wsclient, wsdapi, wsmsvc, WSnmp32, WSock32, WtsApi32, wuguid, xapobase, xapobase2_8, xaswitch, xaudio2, xaudio2_8, xinput, Xinput9_1_0, xinputuap, xmllite, xolehlp, xpsdocumenttargetprint, xpsprint

In the winapi crate, their NetShareEnum I believe links to Netapi32.lib.

The Microsoft docs also show this coming from Netapi32.lib

Would this be a windows-rs issue, a win32metadata issue, or an issue with my window's sdk?

Below is the ILSpy output for Windows.Win32.FileSystem.Apis.NetShareEnum to save you some time:

.method public hidebysig static pinvokeimpl("srvcli" nomangle winapi) 
    uint32 NetShareEnum (
        [in] [opt] valuetype [Windows.Win32.winmd]Windows.Win32.SystemServices.PWSTR servername,
        [in] uint32 level,
        [out] uint8** bufptr,
        [in] uint32 prefmaxlen,
        [out] uint32* entriesread,
        [out] uint32* totalentries,
        [in] [out] [opt] uint32* resume_handle
    ) cil managed preservesig 
{
    .custom instance void [Windows.Win32.Interop]Windows.Win32.Interop.SupportedOSPlatformAttribute::.ctor(string) = (
        01 00 0f 77 69 6e 64 6f 77 73 35 2e 31 2e 32 36
        30 30 00 00
    )
} // end of method Apis::NetShareEnum
Awfa commented 3 years ago

Ran into this issue as well for: Windows::Win32::NetManagement::NetApiBufferFree trying to link netutils.lib when it seems the documentation points it to Netapi32.lib

kennykerr commented 3 years ago

This looks like a duplicate of #463 - we can add a workaround for it in the short term. In the long term, this is fixed with raw-dylib.

Here's a test branch I've used to validate this - works great. 😉

Here's where the workaround goes:

https://github.com/microsoft/windows-rs/blob/8dd4ef3f34dd817573dee6f47f78bbc3a7797a19/crates/gen/src/types/function.rs#L48-L51

kennykerr commented 3 years ago

Duplicate of #463

kennykerr commented 3 years ago

Let me know if you need me to add a workaround for a some lib files. Otherwise I'll track this as part of #463.