AutoHotkey / Ahk2Exe

Official AutoHotkey script compiler - written itself in AutoHotkey
https://autohotkey.com/
Do What The F*ck You Want To Public License
615 stars 115 forks source link

How to compile AHK v2 scripts? #82

Closed natiiix closed 3 years ago

natiiix commented 3 years ago

Believe me, I really did not want to bother you about this, but I just can't seem to be able to compile a v2 script.

I know there is a guide, both in the included offline help and on the official web, but they seem rather vague and perhaps not entirely up-to-date to me, or maybe I'm just stupid, and I don't understand it.

I tried several approaches, including using the AHK_H Ahk2Exe and the AHK v2 .exe, but I had no success. Well, technically, the aforementioned technique sort of works, but the resulting .exe is not standalone, which makes it useless to me. It basically just generates a version of the AHK v2 interpreter, hardcoded to auto-run an .ahk script with the same base path and name. I even tried Compile_AHK, but that project is probably way outdated or something.

Here's what I'm doing:

Once again, I'm sorry to bother you about this and hope this is the correct place to ask a question like that. I couldn't find a public contact to any of the people in change of AHK's development.

I'm really excited about v2, but without being able to compile the scripts, it kind of sucks for me because the v1 is frankly a bit of a nightmare compared to v2, syntax-wise.

Thank you for your continued effort and I wish for v2 to become mainstream soon because it's just so much better.

TAC109 commented 3 years ago

I have just built a new Ahk2Exe1.1.34.00_Beta_1 that you can use for v1 and v2 compiles. It is compatible with AutoHotkey v2.0-beta.1. See this link for details.

You don’t need .bin files for v2 compiles (and they are not included with the v2 beta). Therefore there is no need to generate the AutoHotkey v2 bin files from the source.

When compiling your v2 scripts you select either the v2 AutoHotkeyU32.exe or AutoHotkeyU64.exe file as the base file.

AutoHotkey_H Ahk2Exe is not compatible with the standard AutoHotkey line and shouldn’t be used.

Cheers

natiiix commented 3 years ago

I have seen that thread, but the download link seems dead, as if the release had been since deleted.

I have noticed the lack of .bin files packed with the executable, but I assumed it was done just for the same of simplicity. If the compilation uses the interpreter directly, rather than a .bit, that makes sense, but it also presumably requires the latest version of Ahk2Exe, because 1.1.33.03 (or any other of the last few releases that I've tried) doesn't appear to support .exe files as base. Also, when I run the upstream version, the window title says "1.1.30.00", which is a bit odd, so I'm not sure if that's an even older version of what.

Someone suggested using AHK_H compiler in an old post, and it almost worked, because it also uses the .exe files as base, but it doesn't actually embed the script into the executable for some reason.

However, the upstream version, despite the odd version info in the window title, appear to work perfectly fine for v2 compilation, even if the release/tag is missing, so thanks for the information! I have seen that the v2 Beta version has very recently appeared, but even at this stage, it would be nice to update the documentation to include a beginner-friendly guide to the compilation process because it has been a bit of a ride for me to get to a working .exe. Among other things, the base file discovery puzzles me quite a bit. It seems to offer base file from directories in the parent directory, or something like that, which could become troublesome if you put Ahk2Exe into a project directory with thousands of other huge projects. Regardless, thanks a bunch for the work on v2 because it was a much-needed step in the right direction!

joedf commented 3 years ago

Try this download link? https://github.com/AutoHotkey/Ahk2Exe/releases/tag/untagged-437cab7b048152c2c0db

natiiix commented 3 years ago

@joedf Yeah, that's exactly the link I'm talking about. It's giving me a 404. Tried it in all of my browser, tried deleting cache and cookies, to no avail. The commit it references doesn't even seem to exist any more, so it feels to me like someone force-pushed into the branch and overwrote it. Or you've created it as some kind of private release, unavailable to the public. Regardless, I can just clone master and use that, which works fine, but people with no Git(Hub) may find this a bit challenging.

joedf commented 3 years ago

Oh okay, I see. Try this zip, directly copied from there to this discussion here. Ahk2Exe1.1.34.00_Beta_1.zip

natiiix commented 3 years ago

@joedf Ok, this one works fine for me. It's not signed, so it gives me a Windows security warning, which I didn't get from the other releases, but other than that, it appears to work correctly. Thanks!

joedf commented 3 years ago

We have stopped all autohotkey binaries signing since v1.1.33+ due to it being overpriced and giving in to an experience and culture we cannot really support. For releases we now release them with sha256 hashes.

natiiix commented 3 years ago

@joedf I'm not concerned about the security as much as I'm concerned about some users seeing this as a nuisance. Although, I assume this only affects standalone binaries rather than installers, which would mean that very few people would notice. I run the .ahk version of the compiler, which won't give me the security warning, but I can easily imagine this could be very worrying to many users. It's a shame that all of these increasingly necessary services are adopting an extortionate model, forcing developers to pay for their nonsense. 😕

TAC109 commented 3 years ago

Ok, this one works fine for me. It's not signed, so it gives me a Windows security warning, which I didn't get from the other releases, but other than that, it appears to work correctly. Thanks!

To remove the security warning you need to unblock the .zip file as described in the link I posted earlier. Also check out where Ahk2Exe fits into the recommended file structure at the same link. This version of Ahk2Exe searches around its location looking for suitable Base files to use, so may be slow to start if run from an inappropriate directory.

If you are looking for the Ahk2Exe release on GitHub, you need to click on '+n releases' on the right to see all the Beta releases.

Cheers

natiiix commented 3 years ago

@TAC109 I have never noticed the "unblock" checkbox mentioned by any other unsigned program before, but ok, I guess that works. It still seems a bit shady for actual major public releases.

The download link in the forum post still doesn't work, giving a 404. There is no recent release available on the Releases page. The latest release is 1.1.33.09_Beta_1 / 1ad8222 from 2021-05-01.

I'm still not sure what the binary discovery logic is. There's a directory tree in the post, but it doesn't make it very clear into which directories the compiler looks. If it only goes one directory up and then recurses into the subdirectories, then that's what I would have guessed, but there are other .exe files mentioned as well, and it's not obvious if they'll also be found by Ahk2Exe or not. I mean, who would put the extracted AHK release archives nested into the Compiler directory inside another AHK installation (which would be Program Files, requiring admin rights for any file operation)? That seems a bit convoluted and cluttersome, so I would assume that anyone using these releases stores them somewhere more accessible. However, complicated binary discovery makes it quite awkward to store AHK repos alongside other projects, and essentially forces once to put AutoHotKey_L and Ahk2Exe repos' directories into a wrapper directory to prevent the compiler from crawling through other irrelevant directories.

TAC109 commented 3 years ago

@natiiix It is odd that you can’t see the Ahk2Exe1.1.34.00_Beta_1 release - I clicked on the 'Releases' link in your previous post, and there it was at the top of the list. Peculiar!

The new Base file discovery logic is needed for future releases of the AutoHotkey installer which will encompass v1 and v2. If Ahk2Exe is located correctly in the directory structure before use there should be no problem. I’ll add a description to the forum post to describe the search algorithm in more detail.

Cheers

TAC109 commented 3 years ago

@natiiix Ok, I’ve found that I hadn’t published the release correctly, and this is now fixed.

Apologies for the confusion.

Regards

natiiix commented 3 years ago

@TAC109 Thank you very much! I know it may seem very much obvious to you, since you've designed it, but from the perspective of an external observer, it may be rather confusing, so having a bit of extra documentation never hurts in the long run, as far as my experience goes.

Frankly, I often find myself struggling to understand my own code and what logic drove me to write it just a few months back, just because I didn't bother explaining it in a comment.

I can confirm that I can now indeed see the 1.1.34 Beta release and the link from the forum post works correctly.

Thank you for your patience and I will now close this issue, as it has been resolved, and I do not wish to bother you any longer. I wish you the best of luck with this project. It has been a reliable companion of mine for nearly a decade now.