• rebar3 escriptize


    Here's a full example using rebar3 escriptize:
    λ /tmp → rebar3 new escript hello
    ===> Writing hello/src/hello.erl
    ===> Writing hello/src/hello.app.src
    ===> Writing hello/rebar.config
    ===> Writing hello/.gitignore
    ===> Writing hello/LICENSE
    ===> Writing hello/README.md
    λ /tmp → cd hello
    → vim src/hello.erl
    λ hello → cat src/hello.erl
    
    -module(hello).
    
    %% API exports
    -export([main/1]).
    
    %% escript Entry point
    main(_Args) ->
        io:format("Hello World~n", []),
        erlang:halt(0).
    λ hello → rebar3 escriptize
    ===> Verifying dependencies...
    ===> Compiling hello
    ===> Building escript...
    λ hello → _build/default/bin/hello
    Hello World
    
    So what does this require? First of all, let's take a look at the rebar.config file:
    {deps, []}.
    
    {escript_incl_apps,
     [hello]}.
    {escript_main_app, hello}.
    {escript_name, hello}.
    {escript_emu_args, "%%! +sbtu +A0\n"}.
    the big deal is having the escript_main_app set to the application name I want to use. (here, hello)
    That application has a module with the same name (hello) that exports a function main/1
    if your application has runtime dependencies, they should be declared in the applications tuple of your .app.src file (in src/)
    With these two things we can build an escript. The escript, as @fenollp said, ships without the Erlang VM and requires it to be installed. It makes Erlang become a scripting language the same way Python or Ruby would be, in some ways. It is still compiled and bundles its own code, but depends on a runtime environment being present.
    If you want to boot your application in the escript, then calling application:ensure_all_started(YourApp) is likely the best way to go, and a timer:sleep(infinity). will help things keep running.
    Let us know if you need more assistance.

  • 相关阅读:
    [LeetCode] 617. Merge Two Binary Trees
    [LeetCode] 738. Monotone Increasing Digits
    289. Game of Life
    305. Number of Islands II
    288. Unique Word Abbreviation
    271. Encode and Decode Strings
    393. UTF-8 Validation
    317. Shortest Distance from All Buildings
    286. Walls and Gates
    296. Best Meeting Point
  • 原文地址:https://www.cnblogs.com/unqiang/p/15632542.html
Copyright © 2020-2023  润新知