Giter Club home page Giter Club logo

bakeware's People

Contributors

christhekeele avatar connorrigby avatar fhunleth avatar fl4m3ph03n1x avatar jjcarstens avatar kianmeng avatar kritarthh avatar polvalente avatar sergiotapia avatar simonmcconnell avatar vans163 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bakeware's Issues

Improve build output prints

Currently, the build output looks like this:

Bakeware successfully assembled executable at _build/prod/rel/bakeware/simple_script

Release created at _build/prod/rel/simple_script!

    # To start your system
    _build/prod/rel/simple_script/bin/simple_script start

Once the release is running:

    # To connect to it remotely
    _build/prod/rel/simple_script/bin/simple_script remote

    # To stop it gracefully (you may also send SIGINT/SIGTERM)
    _build/prod/rel/simple_script/bin/simple_script stop

To list all commands:

    _build/prod/rel/simple_script/bin/simple_script

The first line is the important one, but it's hidden behind the release script info. It would be nice if the Bakeware line was more prominent.

Add rebar3 support

It really seems like this could work just as well on non-Elixir projects. This is a placeholder issue for posting notes to help us out for when time opens up to look into it.

How to call to running agent in production?

I know that using a dev build, I can call in to a running application with binary_name rpc "function". Once I move to production, I don't understand how to call the running application. Any tips?

Look here! Important stuff!

We're getting a lot of questions so I figured that I'd answer a few here:

  1. First, thanks for your interest in this project!
  2. This was built over a weekend for SpawnFest. Our goal was to have a usable proof-of-concept, and there are several areas that we'd want to improve for regular use. (like remove debug prints)
  3. The repository is read-only while the SpawnFest judges review entries. That means that we can't merge any PRs or push bug fixes ourselves to the repository.
  4. Yes, we plan to work on this more after SpawnFest is over.

If you're interested in helping out (especially if you're a regular Windows user), please let us know.

Missing `release` in `assembler` struct during bakeware.assemble

Hey there!

I'm getting this error when trying to run the mix bakeware.assemble task:

(UndefinedFunctionError) function nil.options/0 is undefined.

Stack trace points to this line:

compression_level = assembler.release.options[:compression_level] || 15

I think it's possible I'm hitting this entrypoint instead of this one that properly sets up the value of release in the assembler struct?

Reproduction repo here, with pinned erlang, elixir, and bakeware version numbers: https://github.com/christhekeele/bakeware_issue

Quite possible this is a user error, and I've missed something from the documentation? Am I missing a required flag or config option somewhere? Thanks for any help!

generating coveralls reports requires BAKEWARE_ARGC to be set

==> scanado_worker
Cover compiling modules ...
warning: Caught exception in main/1: :error => :function_clause
  (elixir 1.10.3) lib/integer.ex:232: Integer.parse(nil, 10)
  (scanado_worker 0.1.0) lib/bakeware/script.ex:35: ScanadoWorker._main/0
  (elixir 1.10.3) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
  (stdlib 3.12.1) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

there isn't a default value set if it isn't there and during a

mix coveralls.html

it requires the setup of this argument to continue

IE:

export BAKEWARE_ARGC=0

Fantastic job!

This looks amazing!

Let me know if you believe there are improvements we can do to our release scripts. In particular, I wonder if it is worth supporting bin/my_app start ARGV so you can access argv as System.argv directly. :)

Bakeware script is called even in dev env and halts vm

https://github.com/bake-bake-bake/bakeware/blob/main/lib/bakeware/script.ex

So I am a little lost now but I included https://github.com/xenomorphtech/xelnagatemple into another project and when I run that other project I get

warning: Caught exception in main/1: :error => :function_clause
  (elixir 1.11.1) lib/integer.ex:232: Integer.parse(nil, 10)
  (xelnagatemple 0.1.0) lib/bakeware/script.ex:35: XNT.Bakeware._main/0
  (elixir 1.11.1) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
  (stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

And it halts. It seems the module is somehow being evaluated at compile time or something and the using starts the app (no idea why the using is causing app to start), https://github.com/xenomorphtech/xelnagatemple/blob/master/lib/ex_bakeware.ex, even tho there is a conditional set.

* (ArgumentError) unknown application: :bakeware

Background

When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:

* assembling market_manager-2.1.5 on MIX_ENV=prod
* using config/runtime.exs to configure the release at runtime
←[32m* assembling←[39m bakeware market_manager

** (ArgumentError) unknown application: :bakeware
    (elixir 1.15.4) lib/application.ex:1010: Application.app_dir/1
    (elixir 1.15.4) lib/application.ex:1041: Application.app_dir/2
    (bakeware 0.2.4) lib/bakeware/assembler.ex:71: Bakeware.Assembler.create_paths/1
    (bakeware 0.2.4) lib/bakeware/assembler.ex:83: Bakeware.Assembler.do_assemble/1
    (bakeware 0.2.4) lib/bakeware/assembler.ex:37: Bakeware.Assembler.assemble/1
    (mix 1.15.4) lib/mix/tasks/release.ex:1064: Mix.Tasks.Release.run_steps/1
    (mix 1.15.4) lib/mix/task.ex:447: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.15.4) lib/mix/cli.ex:92: Mix.CLI.run_task/2

I am using PowerShell with Admin privileges and I have set the following env variables:

$env:CC="gcc"
$env:MAKE="make"
$env:MIX_ENV="prod"

I have installed all the dependencies via choco with choco install -y zstandard make mingw.

Further, here are my system settings:

Edition	Windows 11 Home
Version	22H2
OS build	22621.2283
Experience	Windows Feature Experience Pack 1000.22662.1000.0

I am using: {:bakeware, "~> 0.2.4"} with Elixir 1.15.4 (compiled with Erlang/OTP 24)

I develop for windows users, so I can't use Linux here.

Question

Why cant I make bakeware work?

Create a README file in the cache directory like Go does

Obviously, Go's use of the cache directory is different, but I thought that it will really nice of Go to put a short readme in it. I think we should do something similar. For reference, here's what Go's readme looks like:

$ cat ~/.cache/go-build/README
This directory holds cached build artifacts from the Go build system.
Run "go clean -cache" if the directory is getting too large.
See golang.org to learn more about Go.

On hex 0.1.2 zstd.h issue

Had to switch to:

      {:bakeware, github: "bake-bake-bake/bakeware", branch: "main"},

to get around

cc -c -O2 -Wall -Wextra -Wno-unused-parameter -pedantic -o /app/_build/prod/lib/bakeware/obj/unzstd.o src/unzstd.c
src/unzstd.c:2:10: fatal error: zstd/lib/zstd.h: No such file or directory
    2 | #include "zstd/lib/zstd.h"
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:52: /app/_build/prod/lib/bakeware/obj/unzstd.o] Error 1
could not compile dependency :bakeware, "mix compile" failed. You can recompile this dependency with "mix deps.compile bakeware", update it with "mix deps.update bakeware" or clean it with "mix deps.clean bakeware"
==> chira_submit
** (Mix) Could not compile with "make" (exit status: 2).

Conflict with escript

When bakeware and escript are used at the same time, the generated application will invoke main function twice.

How to reproduce

Taking the simple_script as an example.

Modify mix.exs by adding escript settings, as follows:

defmodule SimpleScript.MixProject do
  use Mix.Project

  @app :simple_script

  def project do
    [
      app: @app,
      version: "0.1.0",
      elixir: "~> 1.10",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      releases: [{@app, release()}],
      escript: escript(), # <-- !! newly added
      preferred_cli_env: [release: :prod]
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      mod: {SimpleScript, []}
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:bakeware, path: "../..", runtime: false}
    ]
  end

  defp release do
    [
      overwrite: true,
      cookie: "#{@app}_cookie",
      quiet: true,
      steps: [:assemble, &Bakeware.assemble/1],
      strip_beams: Mix.env() == :prod
    ]
  end

  # !! newly added
  defp escript do
    [main_module: SimpleScript]
  end
end

After running mix escript.build, you can get the following result:

~/workspace/bakeware/examples/simple_script $ ./simple_script
Pass me some arguments and I will upcase them if you specify --upcase
Pass me some arguments and I will upcase them if you specify --upcase

Questions

My understanding is that when the program starts, module specified by mod is executed, then escript invokes the main function second time.

Now my questions are:

  1. Is it unexpected behavior?
  2. Is there any workaround to bypass it? (Maybe using another option instead of mod?)

adding rlwrap

Using the up arrow key (on linux) in a release produced escape codes
image

If running with rlwrap, the keys work fine.

Maybe we can also pack rlwrap into the binary, and make the runner call rlwrap ./mybakedapp

Any plans for a bakeware:alpine image for docker?

Having a docker image that has bakeware compiled into it would be great.
We have the elixir:alpine images but bakeware requires elixir_make and it seems GCC and friends are not installed on alpine.
I'm not a seasoned docker user but it would be nice to have a docker image that already has bakeware built ontop of alpine.

Maybe someone is working on that already?

How to specify bakeware as a Mix dependency?

Hello! This project looks really awesome!

But what is the supposed way to use this project? I haven't found it in hex.pm, and mix.exs is not in the root, so one can't specify the project as a git mix dependency.

Are there any plans to publish it on hex.pm?

Thank you!

Is it possible to setup a Windows Bakeware release in GitHub Actions?

Background

I am trying to get a Github Action working with Windows and Bakeware because I am trying to create a release using it.

However, no matter what I do, it seems the environment variables are not being set.

Code

In Bakeware’s setup page it is mentioned that we have to set the MAKE and CC environment variables. In Github Actions terms this means:

env: 
        CC: gcc
        MAKE: make

However, for some reason, this is not working. Here is a Minimal Working Example of the code that replicates the issue:

name: build

env:
  MIX_ENV: test
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:

  build:
    name: Build on Windows
    runs-on: windows-2019

    steps:
    - uses: actions/checkout@v2
    - uses: erlef/setup-beam@v1
      with:
        elixir-version: '1.13.x' # Define the elixir version [required]
        otp-version: '24.2.x' # Define the OTP version [required]
    
    - name: Install choco
      shell: powershell
      run: |
        Set-ExecutionPolicy -ExecutionPolicy Bypass
        Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

    - name: Install bakeware dependencies
      shell: powershell
      run: choco install -y zstandard make mingw

    - name: Install Dependencies
      shell: powershell
      run: mix deps.get
      env: 
        CC: gcc
        MAKE: make

    - name: Run credo code analyser
      shell: powershell
      run: mix credo --strict
      env: 
        CC: gcc
        MAKE: make

I am following Bakeware's official recommendations to install it, I am using choco and powershell.
Nothing I do seems to work.

Questions

  1. Is it possible to have bakeware work for Elixir with a Windows release in Github Actions?
  2. Is there a plugin that already does this and that I am not aware of?

Windows?

Hi there, sorry if this question is answered somewhere ..... but in the main description it says that making Windows exe is not yet available, but may be soon. But then some of the code contains references to windows.
So is this able to be used to build windows exe's yet?

different behavior between with and without bakeware.

Hey guys,
My application doesn't work with bakeware somehow. It calls Systemd.cmd("iptables", blahblah) during genServer initial. However the Systemd.cmd could only work without bakeware just like the following picture figured out.
图片
Any ideas about how to debug it are welcome!

Thank you!

Ability to run detached

I want to create an application that can be invoked on the command line or with a flag be run in the background as a sort of service.

Something like

$ ./myapp
hello world
$ ./myapp --daemon
$ 

Any idea how I can achieve something like this?

Include runtime NPM packages

Is there a way to include specific node modules into the packaged executable? Some elixir libraries depends on these npm modules at runtime and I'd be curious the best way to include them to support a single file executable.

'Quiet mode' for a Bakeware script

It would be great to be able to suppress the extraction / caching messages when using Bakeware to build CLIs.

I was not able to find an option for this, but it could have missed something.

Thanks!

Running the SimpleScript example fails

20:25:45.781 [error] Task #PID<0.628.0> started from SimpleScript.Supervisor terminating
** (UndefinedFunctionError) function Bakeware.Script._main/1 is undefined (module Bakeware.Script is not available)
    Bakeware.Script._main(#Function<0.13039694/1 in SimpleScript."-fun.main/1-">)
    (simple_script 0.1.0) lib/bakeware/script.ex:36: SimpleScript._main/0
    (elixir 1.11.1) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: &SimpleScript._main/0
    Args: []

Run the binary as PID 1

When starting the application with the binary in a container, the application does not run as PID 1, instead PID 1 is bin/sh:

Running ps ax in the container gives something like this:

    1 root      0:00  /bin/sh /root/.cache/bakeware/EDFA78004B57A028C6C7719538C380A8B3999ED9/start
   11 root      0:07 /root/.cache/bakeware/EDFA78004B57A028C6C7719538C380A8B3999ED9/erts-11.1.3/bin/beam.smp -- -root /root/.cache/bakeware/

Which means that SIGTERM never gets forwarded to the application, but dies with sh. That is bad for graceful shutdown. Would it be possible to use exec instead?

Compilation error in CentOS 7.9

Hi,

First of all, thank you very much for this great product!

We are writing a CLI for CentOS 7.9. When compiling bakeware, I get this:

src/main.c:52:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for (int i = 1; i < argc; i++) {
     ^

...

could not compile dependency :bakeware, "mix compile" failed. You can recompile this dependency with "mix deps.compile bakeware", update it with "mix deps.update bakeware" or clean it with "mix deps.clean bakeware"

Could you please help?

Thanks a lot!

remove bakeware messages

When running a packed bin I get

./xelnagatemple 
bakeware: starting '/home/user/project/xelnagatemple/xelnagatemple' (cachedir=/home/user/.cache/bakeware)...
bakeware: Running /home/user/.cache/bakeware/7a4000baaf2321b7c6d4ce572697e2fdf3179bd199f04d69fa4c154693073cb4/start...

Is it possible to remove the msg?

bakeware messes up ssl library?

So I am using ssl module to make a connection, and the version compiled with newest bakeware gives a :socket, :closed error for some reason on every launch. While the non-bakeware version works just fine.

Im drum up a more pinpointed test case, but it seems like something went wrong in the latest bake-bake-bake bakeware as my app worked fine before.

Only allow 1 app to run | Reuse the same .cache if appname is the same

If you push many releases of your application each time it will extract into a new folder under the .cache/bakeware path, this quickly adds up consuming disk space. Allowing only 1 version of the application to run might be out of scope (due to differences between OSes) but perhaps having an override to make the path be the appname instead of a hash would be good.

arch linux x86_64 example cpio not listed as a dep

trying the examples directory causing issues:

bakeware: Cache invalid. Extracting...
bakeware: CPIO read error? read=0 (wanted 110): File exists
bakeware: CPIO extraction failed.: File exists
bakeware: Unrecoverable validation error

downloading the release works fine:

bakeware: Cache invalid. Extracting...
bakeware: Running /home/ebond/.cache/bakeware/5fbc93ec264f1a527cefc22b8848ffeb422b09e88939e514249a5e493c4cd37a/start...
/home/ebond/.cache/bakeware/5fbc93ec264f1a527cefc22b8848ffeb422b09e88939e514249a5e493c4cd37a/erts-11.0.3/bin/beam.smp: /usr/lib/libtinfo.so.6: no version information available (required by /home/ebond/.cache/bakeware/5fbc93ec264f1a527cefc22b8848ffeb422b09e88939e514249a5e493c4cd37a/erts-11.0.3/bin/beam.smp)
hello

Might want to add section for required host installation dependencies?

I had to install cpio to get it working.

Support setting the zstd compression level

Currently the compression level is hardcoded. This results in reasonably good compression, but some people may want to set it even higher for their releases. Also, for general development and unit testing, it would be great to set it really low so that building the binaries is fast.

Cache directory is not properly created automatically on first run.

In the situation of someone running a bakeware compiled binary on an extremely fresh install of some UNIX/Linux installs, when a ~/.cache/bakeware directory is not present already on the system the .cache directory will be created, but NOT the backware sub-directory. Resulting in the following message:

bakeware: Error creating directory ~/.cache/bakeware/.tmp/2mVpqM??: No such file or directory
bakeware: Unrecoverable validation error

UPDATE: After digging a bit more, I see the actual issue here. In utils.c it's expected that the env variable HOME will be an absolute path to the user's home directory when in-fact (in some cases of WSL) it might contain a non-absolute or un-resolved path (like ~). Because we don't expand ~ it tries to create that directory exactly, and it cannot.

Crash in simple_script example

On latest main commit:

$ cd bakeware/examples/simple_script
$ mix deps.get
$ MIX_ENV=prod mix release
...
==> simple_script
Compiling 1 file (.ex)
Generated simple_script app
* assembling simple_script-0.1.0 on MIX_ENV=prod
* skipping runtime configuration (config/releases.exs not found)
* skipping elixir.bat for windows (bin/elixir.bat not found in the Elixir installation)
* skipping iex.bat for windows (bin/iex.bat not found in the Elixir installation)
* assembling bakeware simple_script

* warning [Bakeware] zstd not installed. Skipping compression...

Bakeware successfully assembled executable at _build/prod/rel/bakeware/simple_script

Release created at _build/prod/rel/simple_script!

    # To start your system
    _build/prod/rel/simple_script/bin/simple_script start

Once the release is running:

    # To connect to it remotely
    _build/prod/rel/simple_script/bin/simple_script remote

    # To stop it gracefully (you may also send SIGINT/SIGTERM)
    _build/prod/rel/simple_script/bin/simple_script stop

To list all commands:

    _build/prod/rel/simple_script/bin/simple_script
$ _build/prod/rel/simple_script/bin/simple_script start Hi   
warning: Caught exception in main/1: :error => :function_clause
  (elixir 1.10.4) lib/integer.ex:232: Integer.parse(nil, 10)
  (simple_script 0.1.0) lib/bakeware/script.ex:35: SimpleScript._main/0
  (elixir 1.10.4) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
  (stdlib 3.13) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal
$ elixir -v              
Erlang/OTP 23 [erts-11.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.10.4 (compiled with Erlang/OTP 22)

Running on 32-bit linux systems

Is it possible to run a bakeware executable on a 32-bit linux system?

Currently I get

reMarkable: ~/ ./demo
-sh: ./demo: cannot execute binary file: Exec format error

Here is the file output of a working executable:

reMarkable: ~/ file /opt/bin/wget-ssl
/opt/bin/wget-ssl: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /opt/lib/ld-linux.so.3, for GNU/Linux 3.2.0, stripped

The hardware in question is the remarkable 2 e-ink tablet: https://remarkable.com/store/remarkable-2

Windows executable is an empty file

I ran into another issue with Windows releases: the mix release seems to work fine, but the output executable is an empty file. I can see in the logs that the executable is being build and then shrinked from 56 to 20 MB but the output is empty.

I've tried many times, with clean _build folder as well.

My environment: Windows 10, Erlang R24, Elixir 1.11.4.

Any ideas? Happy to provide more details.

Harden CPIO extractor

Put some seatbelts on the CPIO extractor to prevent mischief and accidents:

  1. No use of .. in paths
  2. No symlinks (verify that this isn't too harsh of a constraint)
  3. Verify permissions

Research whether there are other best practices.

Implement cpio in Elixir to remove dependency

The use of cpio in bakeware is pretty simplistic and shelling out was done for expediency during the competition. Several people have reported issues with shelling out and it seems simpler just to avoid the issue.

Here's how we use cpio:

For each file and directory in the release do the following:
  Run stat to get the file/directory's type, permissions, etc.
  Write the CPIO header
  If a file, write its contents
When done, write the CPIO trailer

The CPIO header is a fixed length text string. You can see it at https://github.com/bake-bake-bake/bakeware/blob/main/src/cpio.c#L74. The hardest part, I think, is getting the padding correct. Many of the fields are ignored. Forcing those to 0 seems better than trying to get them right for deterministic builds and better compression.

Error during `mix deps.compile` under Windows 10

Hey all,

Sorry if that's a noob question, but what's the environment I should run Windows builds under?
Is it cmd.exe, Powershell, or a linux shell under WSL?

I have tried the first two, and what I get (under Windows 10) is:

mkdir -p c:\Users\kubap\Desktop\wxtest\_build\dev\lib\bakeware\obj
The syntax of the command is incorrect

I set everything up as described in https://github.com/bake-bake-bake/bakeware#building-on-windows and looked at GH Actions for clues, but no luck so far under Windows.

Can't get the project to work with any of the examples on Arch Linux

jakob@devtank~/p/p/b/e/s/_/p/r/bakeware (main)> ./simple_app 
bakeware: starting '/home/jakob/projects/personal/bakeware/examples/simple_app/_build/prod/rel/bakeware/simple_app' (cachedir=/home/jakob/.cache/bakeware)...
bakeware: Cache invalid. Extracting...
bakeware: CPIO read error? read=0 (wanted 110): File exists
bakeware: CPIO extraction failed.: File exists
bakeware: Unrecoverable validation error
jakob@devtank~/p/p/b/e/s/_/p/r/bakeware (main)> elixir --version
Erlang/OTP 23 [erts-11.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.10.4 (compiled with Erlang/OTP 23)

Using bakeware master.

Linux devtank 5.8.9-arch2-1 #1 SMP PREEMPT Sun, 13 Sep 2020 23:44:55 +0000 x86_64 GNU/Linux```

[Knowledge share] Cross-compiling to Windows from Linux

Hi,

EDIT:

Ah I saw in another issue you are pointing people to https://github.com/burrito-elixir/burrito which seems to support this out of the box

After looking at Burrito for a bit, I can confirm it is taking the same approach, plus using zig instead of C, which allows it to have an easier time at cross-compiling.

Just sharing my workaround for getting a bakeware executable that's compiled on Linux to run on Windows (for me it has CI benefits, doing it this way). I've also cached the otp_win64_24.3.4.5.exe binary (added to my git repo via LFS). Basically it just replaces the ERTS and other erlang libraries to the Windows one in the release.

Also of course, I have CC ="/path/to/x86_64-w64-mingw32-gcc" to compile the bakeware executable to .exe

I didn't know where best to put it, this is a workaround rather than a full solution, but I think it is a good enough workaround that it's worth sharing.

  defp otp_full_version() do
    otp_major = :erlang.system_info(:otp_release)
    File.read!(Path.join([:code.root_dir(), "releases", otp_major, "OTP_VERSION"]))
    |> String.trim()
  end

  defp extract_cross_erlang() do
    cached_version = "24.3.4.5"
    erts_version = :erlang.system_info(:version)
    otp_version = otp_full_version()
    if otp_version != cached_version do
      raise """
        Wrong erlang version, download the one matching your version:
        OTP: #{otp_version}, ERTS: #{erts_version}
        from e.g. this was from
        https://www.erlang.org/patches/otp-#{cached_version}, so for you it's
        probably https://www.erlang.org/patches/otp-#{otp_version}
      """
    end

    if not File.exists?("cross-erlang") do
      case System.get_env("MIX_TARGET") do
        "win64" -> System.cmd("7z", ["x", "otp_win64_#{cached_version}.exe", "-ocross-erlang"])
      end
    end
  end

  defp patch_for_cross_compile(release) do
    if System.get_env("MIX_TARGET") do
      extract_cross_erlang()

      cross_release = %{release |
        erts_source: './cross-erlang/erts-12.3.2.5',
        applications:
          for {app, cfg} <- release.applications, into: %{} do
            path = cfg[:path] |> to_string
            root_dir = :code.root_dir() |> to_string()

            if String.starts_with?(path, root_dir) do
              {app,
                put_in(
                  cfg[:path],
                  String.replace(path, root_dir, "./cross-erlang")
                  |> to_charlist)}
            else
              {app, cfg}
            end
          end}

      if System.get_env("MIX_RELEASE_DEBUG") do
        File.write!("release", inspect(release, pretty: true, limit: :infinity))
        File.write!("cross_release", inspect(cross_release, pretty: true, limit: :infinity))
      end

      cross_release
    else
      release
    end
  end

  defp release do
    [
      overwrite: true,
      cookie: "#{@app}_cookie",
      quiet: true,
      steps: [
        &patch_for_cross_compile/1,
        :assemble,
        &Bakeware.assemble/1
      ],
      strip_beams: Mix.env() == :prod
    ]
  end

And a small patch on top of Elixir I use as a workaround to not having got a matching Elixir 1.12.3 that works with OTP 24 (Elixir doesn't have any DLLs anyway, just BEAM files, it was just missing the Windows .bat files)

diff --git a/Makefile b/Makefile
index 8f5d093..058f81f 100644
--- a/Makefile
+++ b/Makefile
@@ -122,7 +122,7 @@ install: compile
 		$(INSTALL_DATA) $$dir/ebin/* "$(DESTDIR)$(PREFIX)/$(LIBDIR)/elixir/$$dir/ebin"; \
 	done
 	$(Q) $(INSTALL_DIR) "$(DESTDIR)$(PREFIX)/$(LIBDIR)/elixir/bin"
-	$(Q) $(INSTALL_PROGRAM) $(filter-out %.ps1, $(filter-out %.bat, $(wildcard bin/*))) "$(DESTDIR)$(PREFIX)/$(LIBDIR)/elixir/bin"
+	$(Q) $(INSTALL_PROGRAM) $(wildcard bin/*) "$(DESTDIR)$(PREFIX)/$(LIBDIR)/elixir/bin"
 	$(Q) $(INSTALL_DIR) "$(DESTDIR)$(PREFIX)/$(BINDIR)"
 	$(Q) for file in "$(DESTDIR)$(PREFIX)"/$(LIBDIR)/elixir/bin/*; do \
 		ln -sf "../$(LIBDIR)/elixir/bin/$${file##*/}" "$(DESTDIR)$(PREFIX)/$(BINDIR)/"; \

Windows Support

Hey this looks really exciting! The reason I use Nim is because I need to have small easy to distribute binaries for my apps.

If I can do this with Elixir, I'll just use Elixir!

How far away do you think you guys are from Windows support? If you don't even know that answer is helpful to.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.