Issue
My host is Ubuntu 20.04(x86_64) and my PC is Windows 10 Home (64-bit operating system, x64-based processor). I want to build a dart server to a single file. So, I used this command
dart compile exe dart_server/bin/dart_server.dart -o dart_server-linux-x64
to build the dart_server-linux-x64
file and move it to the host.
and run this file by
./dart_server-linux-x64
Then I got the error:
-bash: ./dart_server-linux-x64: cannot execute binary file: Exec format error
How to solve that? I tried uploading the folder project(dart_server). Then run this dart server from this folder and it works successfully. But I want to use a single file, not the whole folder project. How to fix that?
Solution
Answer here.
We can build dart project into .exe
file by using git action.
I have the dart_server
and dart_share
(using in flutter and dart_server projects) projects.
This is my the directory structure
root
- .github
- workflows
- github-actions-demo.yml
- dart_server
- bin
- dart_server.dart
- pubspec.yaml
- dart_share
- pubspec.yaml
The github-actions-demo.yml
is
# This is a basic workflow to help you get started with Actions
name: CI Building native server
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
include:
- os: ubuntu-latest
output-name: server-linux
- os: macOS-latest
output-name: server-mac
- os: windows-latest
output-name: server-windows.exe
steps:
- uses: actions/checkout@v2
- uses: dart-lang/[email protected]
- name: Install dependencies for share project
working-directory: ./share_dart
run: dart pub get
- name: Install dependencies for server project
working-directory: ./server
run: dart pub get
- run: mkdir build
- name: Install Dependencies for share project
working-directory: ./share_dart
run: dart pub get
- name: Install Dependencies for server project
working-directory: ./server
run: dart pub get
- run: dart compile exe ./server/bin/server.dart -v -o build/${{ matrix.output-name }}
- uses: actions/upload-artifact@v1
with:
name: native-executables
path: build
Answered By - Sittiphan Sittisak Answer Checked By - David Marino (WPSolving Volunteer)