Live data from Hacker News

Using Rust for 'Scripting'

chriskrycho.com

111–120 of 126 posts

Re: Using Rust for 'Scripting'

#111
post #72

This reads less as “Python style scripting in Rust” and more as “I like Rust, also it’s cross-platform.” Not that this is a bad thing, but it feels like a bit of a far cry from my hacked together workflow of throw code in iPython and write out when I’m happy. I don’t see anything here that makes Rust any more attractive than whatever your multiplatform language of choice is for this use case scenario. That being said…

I've been using Rust to build a relatively large cross-platform command-line tool, and I've been genuinely impressed at how easy it is to get things to work on Windows. The Rust standard libraries Just Work on Windows, and they provide pathname handling, threads, environment variables, and a wealth of other tools. Many third party libraries will build for Windows without any problems as well. I actually do think that…

Yup, as someone who's done x-platform C++(Windows/OSX/X360/PS3/etc) for a large part of my career the cross platform support is incredibly well done.

Not having to deal with differences between MSVC, LLVM, GCC and other obscure toolchains is a blessing.

Re: Using Rust for 'Scripting'

#112
post #110
post #76

Earlier quoted context omitted.

Have you been using windows in the past 5 years? Accepting random binaries from the net and running them is the main software distribution model.

I am talking about scenario that "a friend" gives you binary to run. It is different from downloading software from a trusted source.

This is not a random friend giving you a binary. This is where you asked a trusted friend to build you a binary, and he delivered it.

Re: Using Rust for 'Scripting'

#113
post #70

This topic is dear to me, I often deal with people without any software stacks on their machines and strict IT limits on installing new things. If I were on the same OS as the target user, I'd use pyinstaller. I've used it with very few issues over the past year on many projects. Most of them included Flask/Bottle and parts of numpy, it all worked like a charm. Cross compilation in Python is a bit of an issue, I for…

> If one wants to be closer to the metal, Go's cross compilation works out of the box, without all the LLVM/MSVC work that Rust requires (for now, that is).

That's not "closer to the metal"; it's reinventing parts of the native toolchain.

Re: Using Rust for 'Scripting'

#114
post #25
post #13

Earlier quoted context omitted.

Is this available on Windows? The author made it pretty clear the target user was on a Windows machine

The Windows rename command doesn't support recursively processing subfolders, but it can be achieved using one line of powershell: Get-ChildItem . -Recurse -Include *.cha | Rename-Item -NewName { $_.name -Replace '\.cha','.txt' }

You're probably right that Rust code isn't the most minimal way of doing this specific task, but I think the author's intended point was not "This specific task is best done by cross-compiling Rust for Windows" but rather "Rust is a viable alternative to using Python (or the like) for general-purpose cross-platform scripting; here is an example of something that's surprisingly easy to do with Rust". In this case, using a simpler example is just a way of making the demonstration of the concept easier, which I think is fairly effective.

Re: Using Rust for 'Scripting'

#115
post #4

>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 compi…

My 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"…

I think it's a great tutorial for setting up multi-platform cross-compilation. I'm just not sold on Rust as a 'scripting' language :)

Re: Using Rust for 'Scripting'

#116
post #72

Earlier quoted context omitted.

I've been using Rust to build a relatively large cross-platform command-line tool, and I've been genuinely impressed at how easy it is to get things to work on Windows. The Rust standard libraries Just Work on Windows, and they provide pathname handling, threads, environment variables, and a wealth of other tools. Many third party libraries will build for Windows without any problems as well. I actually do think that…

Yup, as someone who's done x-platform C++(Windows/OSX/X360/PS3/etc) for a large part of my career the cross platform support is incredibly well done. Not having to deal with differences between MSVC, LLVM, GCC and other obscure toolchains is a blessing.

This is one reason why I enjoyed using Java so much in the early days, even without JIT.

The differences between MSVC, LLVM, GCC are nothing to worry about, compared with the early days of C89 or C++ARM in the process of being standardized, coupled with different levels of POSIX support.

Re: Using Rust for 'Scripting'

#117
post #57
post #30

Earlier quoted context omitted.

From what I remember Include will only match items from the base directory and powershell gets stupidly complicated very quickly: http://flukus.github.io/2015/03/13/2015_03_13_Powershell-is-...

That compares Powershell to Nant. Nant tasks (inspired by Ant tasks) are more powerful than regular commands. Not even shell commands match those. He's comparing apples with an apple pie there.

I started the article as a nant vs psake (PowerShell based build tool). Psake relies on PowerShell tools for things like copying files, which makes sense.

I'm working on a similar one using make instead, which uses shell commands and it's a lot better than both.

Re: Using Rust for 'Scripting'

#118
post #4

>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 compi…

Python 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"

Thats pretty ugly

ls -Recurse -Include *.cha | % {mv $_.FullName $_. FullName.Replace(".cha", ".txt")}

Re: Using Rust for 'Scripting'

#119
post #70

This topic is dear to me, I often deal with people without any software stacks on their machines and strict IT limits on installing new things. If I were on the same OS as the target user, I'd use pyinstaller. I've used it with very few issues over the past year on many projects. Most of them included Flask/Bottle and parts of numpy, it all worked like a charm. Cross compilation in Python is a bit of an issue, I for…

> If one wants to be closer to the metal, Go's cross compilation works out of the box, without all the LLVM/MSVC work that Rust requires (for now, that is). That's not "closer to the metal"; it's reinventing parts of the native toolchain.

Sorry, I meant closer to the metal relative to Python, not relative to Rust, poor wording.

Re: Using Rust for 'Scripting'

#120
post #49

While this can be seen as an interesting exercise, I can't help but feel that rust isn't the best tool here. First, there are a handful of existing tools, as other have pointed out (I would personally go for AntRenamer). Then, there are a few scripting languages already installed (admittedly maybe not the best or most well-known). A quick Google search would probably have given a result right away, since this is a pr…

For the "right tool for the problem", you're right; really, see up-thread where someone posted the one-liner. For MSVC over MinGW/Clang: part of my point here was to first learn and then document for the community how you do cross-compilation for MSVC. There are lots of projects out there where being able to link against MSVC is important, and it's also harder than linking against MinGW (which would have just been `r…

Thanks, I didn't realise that it was meant to be this way. To me, it sounded a bit like MSVC was the only option, and you had to install if for cross compiling.

Since this is actually harder to do (from your own post), I worry a bit that a beginner might try to do it right away, to the risk of failing at it.

Post reply on HN