{"id":22297835,"url":"https://github.com/dot-asm/min-crt-poc","last_synced_at":"2025-03-25T22:44:36.977Z","repository":{"id":85605923,"uuid":"478929943","full_name":"dot-asm/min-crt-poc","owner":"dot-asm","description":"Trimmed-down MinGW DLL entry point in Rust","archived":false,"fork":false,"pushed_at":"2024-07-13T17:45:21.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T20:17:02.339Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dot-asm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-07T10:12:16.000Z","updated_at":"2024-07-13T17:45:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"210dfb54-1f17-4229-abd7-b107d52bd441","html_url":"https://github.com/dot-asm/min-crt-poc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dot-asm%2Fmin-crt-poc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dot-asm%2Fmin-crt-poc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dot-asm%2Fmin-crt-poc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dot-asm%2Fmin-crt-poc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dot-asm","download_url":"https://codeload.github.com/dot-asm/min-crt-poc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245556960,"owners_count":20634889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T17:51:37.036Z","updated_at":"2025-03-25T22:44:36.959Z","avatar_url":"https://github.com/dot-asm.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"MinGW compilers come in multiple flavours, \"mingw\", \"ucrt\" and \"clang\"/\"llvm\". This asks for the question how many Rust targets there should be. While both MinGW GCC and LLVM toolchains use the same C run-times, they are utilizing different exception handling mechanisms. This makes it impossible to produce a \"universal\" non-MSVC Windows target that would work with both GCC and Clang. But what about \"mingw\" vs. \"ucrt\"? The suggested approach aims to facilitate run-time-neutral `\u003carch\u003e-pc-windows-gnu` target. In more practical terms, after executing `rustup target add \u003carch\u003e-pc-windows-gnu` users will be free to choose between msvcrt and ucrt by simply adjusting their `PATH` environment variable(\\*\\*).\n\nThe key component is [`dllmain.rs`](src/dllmain.rs), a trimmed-down MinGW CRT initialization module, that should allow linking `std-\u003crelease-id\u003e.dll` without reference to a specific run-time, legacy msvcrt.dll or Universal CRT.\n\nWhile compiling with `-C prefer-dynamic` might not be that popular, the fact that the `std-\u003crelease-id\u003e.dll` can be linked without reference to a specific run-time strongly suggests that the static `libstd-\u003crelease-id\u003e.rlib` and Rust-generated code in general don't actually have the dependency either. Or rather it's not strong enough(\\*) to prevent the choice of the run-time to be postponed till the application link time. This is the main proposition.\n\nThe rest of the crate is a test-bed PoC around the `dllmain.rs`. You're more than likely going to have to run `cargo run ...` twice to test. This is because application code gets linked before the library is available. If you know how to arrange the link invocations in specific order, do tell:-) Either way, once confirmed to execute, double-check that `poc.dll` doesn't have imports from your CRT. The test registers a pre-main subroutine, an equivalent to `__attribute__((constructor))` in C, spawns a [rayon](https://docs.rs/rayon/) thread and prints the value set by the \"constructor.\"\n\nEven though the primary target is MinGW, the dllmain.rs and PoC work even with MSVC.\n\n(\\*) Rust compiler depends on memcpy/move/set/cmp and strlen being externally available. These are interchangeable between all known run-times.\n\n(\\*\\*) Caveat lector. By default Rust compiler drivers invokes `x86_64-w64-mingw32-gcc` to link the final binary. The catch is that some MinGW clang packages were spotted to provide `x86_64-w64-mingw32-gcc`, presumably to smooth the switch. Since it's the C compiler driver that is responsible for linking the exception handling library, it would be a problem if the exception flavours chosen by Rust and first-on-the-PATH C compiler mismatch. In the context one can make a case for a sanity check for a matching C compiler. Most notably MinGW GCC target driver could verify that the library search path in `x86_64-w64-mingw32-gcc -print-search-dirs` output has corresponding exception handling library, `libgcc_eh.a`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdot-asm%2Fmin-crt-poc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdot-asm%2Fmin-crt-poc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdot-asm%2Fmin-crt-poc/lists"}