Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out how to embed the script in the executable on Windows #2

Open
fredrikekre opened this issue May 10, 2019 · 3 comments
Open

Comments

@fredrikekre
Copy link
Owner

Otherwise stuff break when the source code of jlpkg is removed.

@heetbeet
Copy link

heetbeet commented Feb 8, 2021

You can use this to make a template for jlpkg:
jlpkg.zip

The main trick is to add the following to the top of a .cmd file:

@eval 1 #= 2>nul 
@call julia "%~dp0%~n0.cmd" %*
@exit /b %errorlevel%
=#
  1. @eval 1 #= 2>nul

    For cmd the @ sign suppresses this line to not be echod to the console and the 2>nul part suppresses any errors. Otherwise you would see 'eval' is not recognized as an internal or external command

    For julia this line is a macro that basically does nothing nothing, following with #= as the start of a multi line comment block.

  2. @call julia "%~dp0%~n0.cmd" %*

    For cmd this will run the current file under julia (note that the file extension still needs to be manually stated, since cmd cannot infer this information if the script is called like jlpkg and not jlpkg.cmd). Julia will simply skip over the cmd header and start executing the julia part of the file.

  3. @exit /b %errorlevel%

    For cmd this will return the error code of the julia run, and exit without arriving at the julia part of the file.

@heetbeet
Copy link

heetbeet commented Feb 8, 2021

Just replace the @call julia "%~dp0%~n0.cmd" %* part with the following juxtaposed string when generating the cmd file: "@call $(julia) $(join(julia_flags, ' ')) $(abspath(@__DIR__, "cli.jl")) %*"

Similarly to what you have here

$(julia) $(join(julia_flags, ' ')) $(abspath(@__DIR__, "cli.jl")) %*

@heetbeet
Copy link

heetbeet commented Feb 9, 2021

#20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants