5 ms·
>Writing it in Rust means I can compile it and hand it to him, and he can run it. And that’s it. As wonderful as they are, the fact that languages like Python,
by fnovd 10y ago
>Writing it in Rust means I can compile it and hand it to him, and he can run it. And that’s it. As wonderful as they are, the fact that languages like Python, Perl, Ruby, JavaScript, etc. require having the runtime bundled up with them makes just shipping a tool a lot harder—especially on systems which aren’t a Unix derivative and don’t have them installed by default.
I'm wondering what part of the twelve step compilation process was found to be easier than simply installing Python on the target machine?
Does the friend have any ability to audit the compiled binary before he runs it? Can he make a small change when he wants to re-use part of the solution?
- officialchicken 10y agoI agree. Instead the "friend" is taught the bad behavior of running untrusted (and I didn't see any tests, so untested and undocumented too) code in binary format on their machine. The glob-rename is exactly the sort of problem a script is supposed to solve easily. I feel the author justified the use of Rust and cross-compilation simply to avoid usage of a Windows OS (or VM) for such a trivial task. If the goal was to avoid installing additional run time/deps on the user's machine it seems that (#1) using powershell would have been the best option followed by (#2) a classic .cmd shell file as second best solution.
- cgag 10y agoWhat? You mean like every other program they've ever run in their lives if they're not a developer, except developed by a personal friend? Compiling is easy. Configuring path variables and installing interpreters are arcane to non-developers.
- yitchelle 10y ago> Instead the "friend" is taught the bad behavior of running untrusted (and I didn't see any tests, so untested and undocumented too) code in binary format on their machine. Being paranoid in the software you run on your machine is a double edge sword. How many people vet their software before using it, and how much vetting do you really need to do?
- mathw 10y agoAnd as the author said, they don't know PowerShell or batch files very well. They also didn't pretend they had a strong justification for doing it. Rust was what they wanted to use, and hey look, Rust let them do it _and_ cross-compile it. I don't think there was an intention to say that everyone should do this instead of using shell scripts. It's not untrusted code, it's code that a friend wrote to help you out. That's not at all the same as installing random untrusted code off the internet. I write code to help out my friends with things they want to do - are you saying they shouldn't accept it from me just because they can't code themselves? I can give them the source code, but what good is that to them when they can't program and don't want to?
- lambda 10y ago> I'm wondering what part of the twelve step compilation process was found to be easier than simply installing Python on the target machine? That part is something that you can control. Giving instructions for someone non-technical to install Python and run a script with it, and then helping them figure out how to interpret those instructions, is a heck of a lot more complicated. And yeah, you can diddle around with cx_freeze and then having to spend some time with InnoSetup or WiX to build an installer, and then do the same on OS X but putting everything into an app bundle inside of a disk image instead, and finally on Linux trying to figure out how to bundle something up to play nicely with all of the major distros and packaging systems, and get something to work, though it doesn't support cross compilation so you now need to set up and maintain three different build machines, which is definitely no simpler than the solution described. All of these solutions have their ups and downs. But being able to relatively easily (modulo installing a linker and a few libraries) cross compile from Rust to a static executable for any of the major desktop platforms is pretty nice, after you've dealt with enough of these funky build and packaging systems or trying to walk people through figuring out how to add Python to their path on Windows.
- ajmurmann 10y agoNot inconveniencing non-technical users cannot be underlined enough. I'd rather write this in C++ which I haven't touched in ten years than explaining my parents over the phone how to install Python or even just a screen sharing solution so that I can do it. I'm still traumatized from trying to get my dad to visit 192.168.1.1 in his browser.
- lqdc13 10y agoThere are multiple ways of making exes on Windows from Python. It's not too much work either.
- jwdunne 10y agoOh my dad wouldn't stand for that. If something happens, like malware, it would be my fault for making him put some "dodgy coding" in the internet and now every result in Google redirects to Adult Friend Finder and I am obliged to admit my wrongdoing and fix the problem - even though it's the address to his router portal...
- mistaken 10y agoPython scripts can also be compiled to an exe file, although I think that the following batch one-liner is the best for this job: for /r startdir %%i in (*.cha) do ECHO ren "%%i" "%%~ni.txt"
- Annatar 10y agoYep, one liner crushes the problem because a shell script is the perfect tool for the job!
- chriskrycho 10y agoFor the record, as the author of the linked post… this is exactly what one "should" do for convenience in this situation. Compiling Python to exe from Mac to run on Windows is actually a lot of work, though it's doable (I've done it more than once in the past).
- rat87 10y agoThats pretty ugly ls -Recurse -Include *.cha | % {mv $_.FullName $_. FullName.Replace(".cha", ".txt")}
- chriskrycho 10y agoMy friend actually has the source code, so yes, he could do all of this. :) Also, worth note that these "twelve steps" are: - inclusive of literally everything including installing Rust and adding dependencies; this is like including "install Python" and "pip install" for a Python tutorial. The point was to be approachable for anyone. I think it succeeded. - inclusive of the "copy the executable to hand to a friend" step in both cases, which is intentionally over the top in the true listicle style - inclusive of a bunch of steps you only ever have to do once to get full MSVC-compatible cross compilation happening for Windows. It's almost like I was intentionally using this tiny project (which isn't especially interesting in its own right; as many have noted it's a one-liner batch file) to provide a one-stop shop for the basics of getting a cross-compiled setup with Rust. ;)
- jsjohnst 10y ago> It's almost like I was intentionally using this tiny project (which isn't especially interesting in its own right; as many have noted it's a one-liner batch file) to provide a one-stop shop for the basics of getting a cross-compiled setup with Rust. ;) That was my initial thought reading this. Even the most devout Rust enthusiast wouldn't go to this much trouble to avoid executing 'find' one would hope (yes, find does everything you need here for those wondering)
- notriddle 10y agoWindows, remember? The OP is building a program on his Mac and sending it to his Windows-using friend. Windows has a "find" command, but it's a full-text search thing, unlike on *nix where it does find-by-name. See: http://www.computerhope.com/findhlp.htm http://www.computerhope.com/findhlp.htm
- jsjohnst 10y agoCygwin / WSL. ;)
- fnovd 10y agoI think it's a great tutorial for setting up multi-platform cross-compilation. I'm just not sold on Rust as a 'scripting' language :)