5 ms·
Halfix – A portable x86 emulator written in C99
- peter_d_sherman 4y agoRelated: https://nepx.github.io/halfix-demo/ https://nepx.github.io/halfix-demo/
- deleted 4y ago[deleted]
- dmitrygr 4y ago> # Win32 API build (no SDL required) > node makefile.js win32 Node.js now required to build a pure c project? I don’t want to live on this planet anymore…
- girvo 4y agoUntil CMake stops having so many pain points, I imagine this will only get worse, I feel.
- dmitrygr 4y agonormal make has built-in rules for C
- jonpalmisc 4y agoAny examples of pain points with CMake? I use it every day and rarely have issues, yet I seem to see complaints online rather often.
- b_m_x 4y agoeasy, CMake 3.xx or higher is required.
- jonpalmisc 4y agoSo… a build of CMake from within the last 8 years? Seems like a reasonable requirement.
- jamesfinlayson 4y agoI haven't tried CMake recently but I remember using it in 2012 and it was awful - the documentation was unhelpful and as soon as I tried to do anything not in the examples I was on my own.
- Teknoman117 4y agoI'd love to hear why you think that's a bad thing. IMHO it's a huge quality of life improvement over 2.x. Everything is part of a target (flags, defines, dependencies, etc.) and far, far fewer magic variables that pollute random projects whenever you try to compose them.
- 0x20cowboy 4y agoCmake is confusing as all get out. Make follows the Unix philosophy of just doing one thing - call other programs. It comes with almost all tool chains you’d care about. You can pick up the basics of a makefile in an afternoon… I still don’t know where cmake functions come from, how you would know about them or how to write your own. Let alone which version is the right one. It’s like jsonnet to me - if you need config files that make config files something has gone horribly wrong. Then again, I stopped bothering trying to learn Cmake. If I see Cmake I don’t bother with the project so there’s that - and also not a fan of c++ so I am probably the wrong audience anyway.
- self_awareness 4y agoWhat is confusing about CMake? cmake_minimum_required(VERSION 3.5) add_executable(exe file.cpp) Do you think that's more complicated than the basics of a Makefile? [1] [1]: https://anadoxin.org/blog/is-it-worth-using-make.html/ https://anadoxin.org/blog/is-it-worth-using-make.html/
- amag 4y agoThere are very few projects for which the above CMakeLists.txt would be enough. Once your project reaches a certain size you will inevitably end up in a part of CMake that is confusing.
- self_awareness 4y agoWell, first argument is that it actually IS enough for lots of small tools, and second argument is that if it's not enough and must be extended, it still requires much less complication than an equivalent Makefile.
- ori_b 4y agoThe comparable makefile: exe: file.cpp Default rules take care of the rest. And if you argue that the barebones example is insufficient for a real project: absolutely true. The same applies to your cmake example.
- nspattak 4y agoif you rarely have issues, either someone else dealt with them before you knew it, either your project is very simple, either your project doesn't ever change or all of the above. I would like to work with your devops :)
- lifthrasiir 4y agoMakefile.js here is actually Makefile plus configure, which makes more sense. The very need for configure is why a pure C project can be annoying to build, especially when you have a complex or auto-generated dependency or have to support multiple platforms.
- dmitrygr 4y agoActually, no Read the code. It literally reinvents all of GNU make...badly. Incl checking file dates to decide what to rebuild, implementing "clean", etc...
- lifthrasiir 4y agoI've read the code and I know that it reimplements a substantial portion of Make. The point is however, this project doesn't work with a single Makefile either. Traditional projects would typically use configure plus (generated) Makefile, where configure is a shell script typically built from autoconf which is an abomination. In order to avoid autoconf some projects replace configure with other languages like JS. This project went further by merging that JS configure with Makefile. All of this hassle would be pointless unless you consider one important platform: Windows, where you don't natively have Make anyway. You may still argue that this project still requires GCC and thus there should be Make even in Windows. That's reasonable, but right now I have GCC and Clang but no Make in my Windows console. If you can remove a hard dependency on Make with a reasonable cost (and I don't claim it's the case with this project, I would have used Ninja instead [1]) it's pretty worthwhile in my opinion. [1] See https://github.com/lifthrasiir/j40/blob/main/make.cmd https://github.com/lifthrasiir/j40/blob/main/make.cmd and https://github.com/lifthrasiir/j40/tree/main/extra/build https://github.com/lifthrasiir/j40/tree/main/extra/build for example; with this setting `make` works both in the standard *nix and Windows.
- badsectoracula 4y ago> All of this hassle would be pointless unless you consider one important platform: Windows, where you don't natively have Make anyway. [...] You may still argue that this project still requires GCC and thus there should be Make even in Windows. I think that is a very good argument though: Windows doesn't have MSVC or any other compiler out of the box either, it is up to you to install the requirements so having Make as a requirement - especially considering how standard it is - is perfectly fine. Using something like MSYS2 gives you a Linux-like shell with all the tools you'd expect there. There is no real reason to require Node aside from the author wanted to play around with it, the functionality that tool provides can be provided by other existing tools (Autotools, premake, CMake, meson/muon, etc) or even GNU Make itself (using its extensions that wont be compatible with other "makes" though). (also while Autotools can feel a bit arcane, they have one feature that other similar tools do not have: you do not need to have Autotools installed to build the project, only some shell and some make, both being very standard in pretty much any unix-like OS and for Windows, well, see the first paragraph :-P)
- vonwoodson 4y agoRight? The idea that an x86 emulator, written in C99, would require node to build is a smell if I’ve ever smelled one. If a dev can’t be bothered to use standard tooling, can he be bothered to write safe and performant C? Is this kind of “cleverness” running throughout his code? Maybe the build process is “too complicated” for standard tools, which is a problem for sure. This is more of a question for the next developer who tries to pull something like this, I don’t really want the OP to be discouraged from continuing their work. Just, maybe next time, don’t force JavaScript into a round hole.
- bitwize 4y agoNode is standard tooling for younger devs -- who also find JavaScript more tractable than Make, CMake, or Autotools. Tbh I'm kind of surprised they didn't use Gulp.
- laundermaf 4y agoThe only crime I see is how they wrapped this function https://github.com/nepx/halfix/blob/37a2d1394617397b817bbcd6fdb6260bbee26a10/makefile.js#L582 https://github.com/nepx/halfix/blob/37a2d1394617397b817bbcd6...
- userbinator 4y agoPerformance isn't terrible, but it isn't fantastic either (70-100 MIPS native, 10-30 MIPS browser) Those screenshots must've taken some extreme patience. Especially that Windows 10 one. 70-100 MIPS is roughly a fast 486. It sounds like this isn't even a JIT, unlike QEMU's emulation mode, and the latter is already quite noticeably slower when running modern OSs on modern hardware.
- mburee 4y agoCan't take more than a couple of hours, if booting linux to an X session only took about a day on an AVR
- ClassyJacket 4y agoForgive me if this is wrong/ignorant, but you can't really do a JIT and keep it portable, no?
- wolf550e 4y agoRight, but it kinda depends on what you mean by "portable". Only an interpreter will work without modification on a new host arch, but code for a JIT that is organized in such a way that makes it easy to add support for new host arch might also be called "portable".
- euclaise 4y agoIf I recall correctly, QEMU did portable JIT by implementing the instructions in C and then copying their compiled versions out of the emulator binary instead of calling them as functions.
- blondin 4y agovery curious about this one. is nodejs needed here because of its build tools?
- joshxyz 4y agomakefile.js notes // Special build system used for Halfix builds. Supports the following features: // - All built object files go in build/objs (no cluttering src/) // - Build multiple targets at once (i.e. switch between Emscripten and native // builds without having to clean) // - Parallel build (same as make -j) // - Certain files can be conditionally built based on the target // - Dependency resolution and conditional compilation (note: this is a bit // buggy) // - Automatic dependency regeneration (via redep) // - Simple to use (no configuration, multi-platform, etc.) // Usage: // node makefile.js [target] [options] // Omit "target" for default native build. // Run with --help for options and target list.
- armitron 4y agoI was going to play with this until I saw node.js required for build which means I am not going to bother. Use the right tool for the job, if there exists a job for node.js it certainly isn’t building C projects.
- eterevsky 4y agoI wonder why HN likes projects written in C so much. C has its uses, but most of the modern code should be written in Rust, C++ or higher-level languages.
- jlokier 4y agoFrom the project's README: > Why? I made this mostly for fun Some people find C more fun to write than Rust or C++. >> most of the modern code should be written in It's for fun; "should" doesn't apply to projects written for fun.
- fortran77 4y ago> It's for fun; "should" doesn't apply to projects written for fun. It shouldn't apply to any project. We shouldn't accept the Rust astroturfers injecting themselves into every thread here. Rust has problems, too, and there are many better choices for many applications.
- ddevault 4y agoSure is a good thing that you found out that this random pet project is written in C before you shipped it to production and filled it with sensitive medical data! I'm sure you're running Redox anyway, so you would have been safe regardless. Close shave!
- rurban 4y agoOk, so let's not talk about Linux or Windows anymore. Only Pascal operating systems, you know, the ones with all the modern safeties.
- pjmlp 4y agoOk, https://www.folklore.org/StoryView.py?project=Macintosh&story=Well_See_About_That.txt https://www.folklore.org/StoryView.py?project=Macintosh&stor... https://www.folklore.org/StoryView.py?story=3rd_Party_Developers_and_Macintosh_Development.txt https://www.folklore.org/StoryView.py?story=3rd_Party_Develo... https://www.folklore.org/StoryView.py?project=Macintosh&story=MacPaint_Evolution.txt https://www.folklore.org/StoryView.py?project=Macintosh&stor... https://en.wikipedia.org/wiki/Apollo_Computer https://en.wikipedia.org/wiki/Apollo_Computer https://en.wikipedia.org/wiki/Corvus_Systems https://en.wikipedia.org/wiki/Corvus_Systems