burrito-elixir / burrito

Wrap your application in a BEAM Burrito!
MIT License
918 stars 34 forks source link

Cannot launch hello_burrito app in windows properly #118

Closed Fl4m3Ph03n1x closed 9 months ago

Fl4m3Ph03n1x commented 10 months ago

Host

Tell us about your Host OS (the machine you're building burrito apps on)

Processor   12th Gen Intel(R) Core(TM) i7-1260P   2.50 GHz
System type 64-bit operating system, x64-based processor
Edition Windows 11 Home
Version 22H2
OS build    22621.2283
Experience  Windows Feature Experience Pack 1000.22662.1000.0

Dependencies:

❯ zig version
0.11.0

❯ xz --version
xz (XZ Utils) 5.2.9
liblzma 5.2.9

❯ 7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20

Please run elixir -v in your Burrito project directory and write the version here:

❯ elixir -v
Erlang/OTP 25 [erts-13.2.2.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit:ns]

Elixir 1.15.4 (compiled with Erlang/OTP 24)

  1. Create project:
 mix phx.new hello_burrito --no-ecto --no-gettext --no-mailer --no-dashboard
  1. Change files:

runtime.ex

import Config

config :hello_burrito, HelloBurritoWeb.Endpoint, server: true

if config_env() == :prod do
  secret_key_base = "DBI4uJGXN7WFbR3ksjUd4Ir1NgdmGe/l1dGyJ0iGY0ycNYRKbyXNSPHqriZzal75"

  host = System.get_env("PHX_HOST") || "example.com"
  port = String.to_integer(System.get_env("PORT") || "4000")

  config :hello_burrito, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")

  config :hello_burrito, HelloBurritoWeb.Endpoint,
    url: [host: host, port: 443, scheme: "https"],
    http: [
      ip: {0, 0, 0, 0, 0, 0, 0, 0},
      port: port
    ],
    secret_key_base: secret_key_base
end

mix.exs

defmodule HelloBurrito.MixProject do
  use Mix.Project

  def project do
    [
      app: :hello_burrito,
      version: "0.1.0",
      elixir: "~> 1.14",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps(),
      releases: releases()
    ]
  end

  def application do
    [
      mod: {HelloBurrito.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  defp deps do
    [
      {:phoenix, "~> 1.7.8"},
      {:phoenix_html, "~> 3.3"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.20.1"},
      {:floki, ">= 0.30.0", only: :test},
      {:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
      {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:jason, "~> 1.2"},
      {:dns_cluster, "~> 0.1.1"},
      {:plug_cowboy, "~> 2.5"},
      {:burrito, github: "burrito-elixir/burrito"}
    ]
  end

  defp aliases do
    [
      setup: ["deps.get", "assets.setup", "assets.build"],
      "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
      "assets.build": ["tailwind default", "esbuild default"],
      "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"]
    ]
  end

  def releases do
    [
      demo: [
        steps: [:assemble, &Burrito.wrap/1],
        burrito: [
          targets: [
            windows: [os: :windows, cpu: :x86_64]
          ]
        ]
      ]
    ]
  end
end
  1. Run the commands:
set MIX_ENV=prod
mix deps.get
mix release

Running command with:

~\Documents\hello_burrito is 📦 v0.1.0 via 💧 v1.15.6 (OTP 26) took 1m26s
❯ start "demo app" /D "C:\Users\user\Documents\hello_burrito\burrito_out" /B demo_windows.exe

~\Documents\hello_burrito is 📦 v0.1.0 via 💧 v1.15.6 (OTP 26)
❯ error: FileNotFound

The application launches and closes immediately. This is all the output I could recover.

278623020-caddc153-239a-4a87-96ca-4742c04631f6 1

I wonder if I am either missing a dependency, or running the command improperly.

doawoo commented 10 months ago

Please try running the exe by:

  1. Changing directory into the dir of the exe using cd
  2. Running the exe by typing just the name without using start etc.

I want to see the full output of the command to see if we can figure out what's crashing.

rupurt commented 9 months ago

I can confirm burrito works fine on windows with OTP 26/Elixir 1.15 on a non-phoenix app FWIW

doawoo commented 9 months ago

I'll leave this issue open for another week or so, but unless I can see the console output it's hard to me to diagnose this issue, I can't seem to reproduce it on my end.

doawoo commented 9 months ago

Closing due to inactivity, feel free to re-open if you're still not able to get this to work, and have some of the console output for the application on startup

linusdm commented 6 months ago

I'd like to reopen. I'm seeing a similar situation, not being able to start up on Windows. I'm compiling on Windows (so no cross-compilation at all). I've tried with Elixir 1.15.7 and 1.16.1. Both with OTP 26.2.2.

I'm trying out without any dependencies (only burrito v1.0.4). Just printing out a message, so dependencies cannot be the problem here.

The output is quite short, it's just printing that FileNotFound message:

C:\Users\user\example_cli_app\burrito_out>example_cli_app_windows.exe
error: FileNotFound

cd'ing into the burrito_out folder or not makes no difference. If I can give any more details, I'd gladly do so.

linusdm commented 6 months ago

I just gave the debug option a try, and this yields some more context:

C:\Users\user\win_test\burrito_out>example_cli_app_windows.exe
debug: Size of embedded payload is: 16665344
debug: Install Directory: C:\Users\user\AppData\Local\.burrito\example_cli_app_erts-14.2.2_0.1.0
debug: Metadata path: C:\Users\user\AppData\Local\.burrito\example_cli_app_erts-14.2.2_0.1.0\_metadata.json
debug: Passing args string: {  }
debug: Unpacked File: C:\Users\user\AppData\Local\.burrito\example_cli_app_erts-14.2.2_0.1.0\bin\example_cli_app
debug: Unpacked File: C:\Users\user\AppData\Local\.burrito\example_cli_app_erts-14.2.2_0.1.0\bin\example_cli_app.bat
debug: Unpacked File: C:\Users\user\AppData\Local\.burrito\example_cli_app_erts-14.2.2_0.1.0\erts-14.2.2\bin\beam.debug.smp.dll
error: FileNotFound
C:\Users\user\scoop\apps\zig\current\lib\std\os\windows.zig:133:39: 0x7ff63ab33a18 in OpenFile (example_cli_app.exe.obj)
            .OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
                                      ^
C:\Users\user\scoop\apps\zig\current\lib\std\fs.zig:1403:23: 0x7ff63ab37215 in createFileW (example_cli_app.exe.obj)
            .handle = try os.windows.OpenFile(sub_path_w, .{
                      ^
C:\Users\user\scoop\apps\zig\current\lib\std\fs.zig:1286:13: 0x7ff63ab20079 in createFile (example_cli_app.exe.obj)
            return self.createFileW(path_w.span(), flags);
            ^
C:\Users\user\scoop\apps\zig\current\lib\std\fs.zig:2806:5: 0x7ff63aadbe95 in createFileAbsolute (example_cli_app.exe.obj)
    return cwd().createFile(absolute_path, flags);
    ^
C:\Users\user\win_test\deps\burrito\src\archiver.zig:207:26: 0x7ff63aadb8ff in unpack_files (example_cli_app.exe.obj)
            const file = try fs.createFileAbsolute(full_file_path, .{ .truncate = true });
                         ^
C:\Users\user\win_test\deps\burrito\src\wrapper.zig:150:5: 0x7ff63aadc17e in do_payload_install (example_cli_app.exe.obj)
    try foilz.unpack_files(FOILZ_PAYLOAD, install_dir, build_options.UNCOMPRESSED_SIZE);
    ^
C:\Users\user\win_test\deps\burrito\src\wrapper.zig:124:9: 0x7ff63aacf724 in main (example_cli_app.exe.obj)
        try do_payload_install(install_dir, metadata_path);
        ^
doawoo commented 6 months ago

@linusdm Thanks for the report!

Unfortunately we do not support building on Windows as a host machine directly right now (see the readme for the supported host systems). I recommend you use the "Windows Subsystem for Linux" to setup a Linux environment on your Windows machine to build your app in for now.

It may seem a bit backwards but Windows build support is extra tricky due to how differently file paths are handled on Windows and the many odd quirks of its kernel. I'm not sure when I can find some time to set up a Windows dev machine, but it is on the list and any contributions in helping to debug support of Windows-host builds is appreciated.

linusdm commented 6 months ago

Omg, I totally read that in the readme, but managed to screw that up anyway 🙈 I'm surprised it got so far. At least the mystery is solved now :)

I was trying to build on Windows, to include Torchx (and other Nx related libs) in a burrito build for Windows. I'll have to scratch my head some more about how (and if) to make that happen.

Thx for clearing that up for me!