mirror of
https://github.com/obhq/obliteration.git
synced 2026-10-12 02:20:15 +00:00
Uses Project to build instead of Python (#1425)
This commit is contained in:
@@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
- name: Install system packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
|
||||
@@ -6,8 +6,8 @@ jobs:
|
||||
name: Linux
|
||||
runs-on: ubuntu-22.04 # Lowest version that support Vulkan 1.3.
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v6
|
||||
- name: Install System Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
@@ -16,17 +16,12 @@ jobs:
|
||||
run: rustup update stable
|
||||
- name: Add additional Rust targets
|
||||
run: rustup target add x86_64-unknown-none
|
||||
- name: Install additional tools
|
||||
run: cargo install project
|
||||
- name: Lint Rust sources
|
||||
run: |
|
||||
cargo clippy --package bitflag --no-deps --target x86_64-unknown-none -- -D warnings
|
||||
cargo clippy --package config --no-deps --target x86_64-unknown-none -- -D warnings
|
||||
cargo clippy --package hv --no-deps -- -D warnings
|
||||
cargo clippy --package krt --no-deps --target x86_64-unknown-none -- -D warnings
|
||||
cargo clippy --package macros --no-deps -- -D warnings
|
||||
cargo clippy --package obkrnl --no-deps --target x86_64-unknown-none -- -D warnings
|
||||
cargo clippy --package x86-64 --no-deps --target x86_64-unknown-none -- -D warnings
|
||||
run: project lint
|
||||
- name: Build
|
||||
run: ./build.py -r
|
||||
run: project build -r
|
||||
- name: Run tests
|
||||
run: cargo test
|
||||
- name: Create distribution tarball
|
||||
|
||||
@@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
- name: Generate cache keys
|
||||
run: |
|
||||
echo "target=${{ runner.os }}-${{ runner.arch }}-target-${{ hashFiles('Cargo.lock') }}" >> $GITHUB_OUTPUT
|
||||
@@ -25,15 +25,12 @@ jobs:
|
||||
run: rustup component add rust-src --toolchain nightly
|
||||
- name: Install additional Rust targets
|
||||
run: rustup target add aarch64-unknown-none-softfloat
|
||||
- name: Install additional tools
|
||||
run: cargo install project
|
||||
- name: Lint Rust sources
|
||||
run: |
|
||||
cargo clippy --package aarch64 --no-deps --target aarch64-unknown-none-softfloat -- -D warnings
|
||||
cargo clippy --package bitflag --no-deps --target aarch64-unknown-none-softfloat -- -D warnings
|
||||
cargo clippy --package config --no-deps --target aarch64-unknown-none-softfloat -- -D warnings
|
||||
cargo clippy --package krt --no-deps --target aarch64-unknown-none-softfloat -- -D warnings
|
||||
cargo clippy --package macros --no-deps -- -D warnings
|
||||
run: project lint
|
||||
- name: Build
|
||||
run: ./build.py -r
|
||||
run: project build -r
|
||||
- name: Run tests
|
||||
run: cargo test
|
||||
- name: Create Apple Disk Image
|
||||
|
||||
@@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
- name: Generate cache keys
|
||||
run: |
|
||||
echo "target=${{ runner.os }}-target-${{ hashFiles('Cargo.lock') }}" >> $env:GITHUB_OUTPUT
|
||||
@@ -37,8 +37,10 @@ jobs:
|
||||
run: rustup update stable
|
||||
- name: Add additional Rust targets
|
||||
run: rustup target add x86_64-unknown-none
|
||||
- name: Install additional tools
|
||||
run: cargo install project
|
||||
- name: Build
|
||||
run: python3 build.py -r
|
||||
run: project build -r
|
||||
- name: Run tests
|
||||
run: cargo test
|
||||
- name: Upload artifacts
|
||||
|
||||
@@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
- name: Update Rust
|
||||
run: rustup update stable
|
||||
- name: Check Rust styles
|
||||
|
||||
Vendored
+3
-2
@@ -5,10 +5,11 @@
|
||||
"[jsonl]": {
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"[python]": {
|
||||
"[lua]": {
|
||||
"editor.rulers": [
|
||||
100
|
||||
]
|
||||
],
|
||||
"editor.tabSize": 2,
|
||||
},
|
||||
"[rust]": {
|
||||
"editor.defaultFormatter": "rust-lang.rust-analyzer",
|
||||
|
||||
Vendored
+2
-2
@@ -5,9 +5,9 @@
|
||||
"label": "Build",
|
||||
"detail": "Build Obliteration and create distribution files",
|
||||
"type": "process",
|
||||
"command": "python3",
|
||||
"command": "project",
|
||||
"args": [
|
||||
"build.py"
|
||||
"build"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
commands:
|
||||
build:
|
||||
description: Build Obliteration and create distribution file
|
||||
args:
|
||||
release:
|
||||
description: Enable optimization
|
||||
long: release
|
||||
short: r
|
||||
type: bool
|
||||
root:
|
||||
description: Directory to store build outputs
|
||||
long: root
|
||||
type: string
|
||||
placeholder: PATH
|
||||
debug:
|
||||
description: Immediate launch the VMM in debug mode
|
||||
long: debug
|
||||
type: string
|
||||
placeholder: ADDR
|
||||
default: 127.0.0.1:1234
|
||||
script: scripts/build.lua
|
||||
lint:
|
||||
description: Run Clippy on all projects
|
||||
script: scripts/lint.lua
|
||||
@@ -1,190 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
from argparse import ArgumentParser
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
from subprocess import PIPE, Popen, run
|
||||
import sys
|
||||
from urllib.parse import urlparse
|
||||
|
||||
def cargo(package, toolchain=None, target=None, release=False, args=None):
|
||||
# Get package ID.
|
||||
cmd = ['cargo']
|
||||
|
||||
if toolchain is not None:
|
||||
cmd.append(f'+{toolchain}')
|
||||
|
||||
id = run(cmd + ['pkgid', '-p', package], stdout=PIPE, check=True).stdout.decode('utf-8').strip()
|
||||
|
||||
# Parse package ID.
|
||||
url = urlparse(id)
|
||||
path = url.path
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
path = path[1:] # Remove '/' in front of drive letter.
|
||||
|
||||
# Setup command and its argument.
|
||||
cmd.extend(['build', '-p', package])
|
||||
|
||||
if target is not None:
|
||||
cmd.extend(['--target', target])
|
||||
|
||||
if release:
|
||||
cmd.append('-r')
|
||||
|
||||
if args is not None:
|
||||
cmd.extend(args)
|
||||
|
||||
cmd.extend(['--message-format', 'json-render-diagnostics'])
|
||||
|
||||
# Run.
|
||||
with Popen(cmd, stdout=PIPE, cwd=path) as proc:
|
||||
for line in proc.stdout:
|
||||
line = json.loads(line)
|
||||
reason = line['reason']
|
||||
if reason == 'build-finished':
|
||||
if line['success']:
|
||||
break
|
||||
else:
|
||||
sys.exit(1)
|
||||
elif reason == 'compiler-artifact':
|
||||
if line['package_id'] == id:
|
||||
artifact = line
|
||||
|
||||
return artifact
|
||||
|
||||
def export_darwin(root, kern, gui):
|
||||
# Create directories.
|
||||
bundle = os.path.join(root, 'Obliteration.app')
|
||||
contents = os.path.join(bundle, 'Contents')
|
||||
macos = os.path.join(contents, 'MacOS')
|
||||
resources = os.path.join(contents, 'Resources')
|
||||
|
||||
os.mkdir(bundle)
|
||||
os.mkdir(contents)
|
||||
os.mkdir(macos)
|
||||
os.mkdir(resources)
|
||||
|
||||
# Export files
|
||||
out, gui = os.path.split(gui['executable'])
|
||||
gui = gui.capitalize()
|
||||
|
||||
shutil.copy(kern['executable'], resources)
|
||||
shutil.copy(os.path.join(out, gui), macos)
|
||||
shutil.copyfile('bundle.icns', os.path.join(resources, 'obliteration.icns'))
|
||||
shutil.copy('Info.plist', contents)
|
||||
|
||||
# Sign bundle.
|
||||
run(['codesign', '-s', '-', '--entitlements', 'entitlements.plist', bundle], check=True)
|
||||
|
||||
return os.path.join(macos, gui)
|
||||
|
||||
def export_linux(root, kern, gui):
|
||||
# Create directories.
|
||||
bin = os.path.join(root, 'bin')
|
||||
share = os.path.join(root, 'share')
|
||||
|
||||
os.mkdir(bin)
|
||||
os.mkdir(share)
|
||||
|
||||
# Export files.
|
||||
shutil.copy(kern['executable'], share)
|
||||
shutil.copy(gui['executable'], bin)
|
||||
|
||||
# Get path to GUI.
|
||||
gui = os.path.basename(gui['executable'])
|
||||
|
||||
return os.path.join(bin, gui)
|
||||
|
||||
def export_windows(root, kern, gui):
|
||||
# Create share directory.
|
||||
share = os.path.join(root, 'share')
|
||||
|
||||
os.mkdir(share)
|
||||
|
||||
# Export files.
|
||||
shutil.copy(kern['executable'], share)
|
||||
shutil.copy(gui['executable'], root)
|
||||
|
||||
# Get path to GUI.
|
||||
gui = os.path.basename(gui['executable'])
|
||||
|
||||
return os.path.join(root, gui)
|
||||
|
||||
def main():
|
||||
# Setup argument parser.
|
||||
p = ArgumentParser(
|
||||
description='Script to build Obliteration and create distribution file')
|
||||
|
||||
p.add_argument('-r', '--release', action='store_true', help='enable optimization')
|
||||
p.add_argument(
|
||||
'--root',
|
||||
metavar='PATH',
|
||||
help='directory to store build outputs')
|
||||
p.add_argument(
|
||||
'--debug',
|
||||
metavar='ADDR',
|
||||
help='immediate launch the VMM in debug mode',
|
||||
nargs='?',
|
||||
const='127.0.0.1:1234')
|
||||
|
||||
# Parse arguments.
|
||||
args = p.parse_args()
|
||||
|
||||
# Build kernel.
|
||||
m = platform.machine()
|
||||
|
||||
if m == 'aarch64' or m == 'arm64':
|
||||
kern = cargo(
|
||||
'obkrnl',
|
||||
toolchain='nightly',
|
||||
target='aarch64-unknown-none-softfloat',
|
||||
release=args.release,
|
||||
args=['-Z', 'build-std=core,alloc'])
|
||||
elif m == 'x86_64' or m == 'AMD64':
|
||||
kern = cargo(
|
||||
'obkrnl',
|
||||
target='x86_64-unknown-none',
|
||||
release=args.release)
|
||||
else:
|
||||
print(f'Architecture {m} is not supported.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Build GUI.
|
||||
gui = cargo('gui', release=args.release, args=['--bin', 'obliteration'])
|
||||
|
||||
# Create output directory.
|
||||
dest = args.root
|
||||
|
||||
if dest is None:
|
||||
dest = 'dist'
|
||||
|
||||
if os.path.exists(dest):
|
||||
shutil.rmtree(dest)
|
||||
|
||||
os.mkdir(dest)
|
||||
|
||||
# Export artifacts.
|
||||
s = platform.system()
|
||||
|
||||
if s == 'Darwin':
|
||||
gui = export_darwin(dest, kern, gui)
|
||||
elif s == 'Linux':
|
||||
gui = export_linux(dest, kern, gui)
|
||||
elif s == 'Windows':
|
||||
gui = export_windows(dest, kern, gui)
|
||||
else:
|
||||
print(f'OS {s} is not supported.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Start VMM.
|
||||
addr = args.debug
|
||||
|
||||
if addr is None:
|
||||
return
|
||||
|
||||
run([gui, '--debug', addr], check=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+1
-1
@@ -15,7 +15,7 @@ Replace `URL` with the URL you have copied.
|
||||
Change into the directory you just downloaded with `cd` and run the following command:
|
||||
|
||||
```sh
|
||||
python3 build.py -r
|
||||
project build -r
|
||||
```
|
||||
|
||||
Remove `-r` to disable optimization if you plan to make some contributions so the debugger will work properly. Build outputs will be placed in `dist` directory.
|
||||
|
||||
+2
-4
@@ -12,10 +12,8 @@ In order to build Obliteration from source make sure you have the following prer
|
||||
- Make sure you install using `rustup`
|
||||
- On Linux your distro may provide a package for this
|
||||
- On macOS you can install from Homebrew
|
||||
- [Python 3](https://www.python.org)
|
||||
- On Windows make sure you have `Add Python to PATH` selected when installing
|
||||
- On Linux it is likely your distro already provided a package for this
|
||||
- On macOS you can install latest version from Homebrew
|
||||
- [Project](https://github.com/ultimaweapon/project)
|
||||
- You can install with `cargo install project`
|
||||
|
||||
## Windows
|
||||
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
local function cargo(opts)
|
||||
local pkg = opts[1]
|
||||
|
||||
-- Get toolchain selector.
|
||||
local tc = opts.toolchain
|
||||
|
||||
if tc then
|
||||
tc = string.format('+%s', tc)
|
||||
end
|
||||
|
||||
-- Get package ID.
|
||||
local id = os.capture('cargo', tc, 'pkgid', '-p', pkg)
|
||||
local url = Url:new(id)
|
||||
local path = url.path
|
||||
|
||||
if os.kind == 'windows' then
|
||||
-- Remove '/' in front of drive letter.
|
||||
path = path:sub(2)
|
||||
end
|
||||
|
||||
-- Setup build arguments.
|
||||
local args = {
|
||||
'build',
|
||||
'-p', pkg,
|
||||
'--message-format', 'json-render-diagnostics',
|
||||
table.unpack(opts.args or {})
|
||||
}
|
||||
|
||||
if opts.release then
|
||||
args[#args + 1] = '-r'
|
||||
end
|
||||
|
||||
-- Add target.
|
||||
local val = opts.target
|
||||
|
||||
if val then
|
||||
args[#args + 1] = '--target'
|
||||
args[#args + 1] = val
|
||||
end
|
||||
|
||||
-- Build.
|
||||
local proc <close> = os.spawn({'cargo', cwd = path, stdout = 'pipe'}, tc, table.unpack(args))
|
||||
local artifact = nil
|
||||
|
||||
while true do
|
||||
-- Read JSON message.
|
||||
local line = proc.stdout:read()
|
||||
|
||||
if not line then
|
||||
break
|
||||
end
|
||||
|
||||
line = json.parse(line)
|
||||
|
||||
-- Check type.
|
||||
local reason = line.reason
|
||||
|
||||
if reason == 'build-finished' then
|
||||
if line.success then
|
||||
break
|
||||
else
|
||||
exit(1)
|
||||
end
|
||||
elseif reason == 'compiler-artifact' then
|
||||
if line.package_id == id then
|
||||
artifact = line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return artifact
|
||||
end
|
||||
|
||||
-- Build kernel.
|
||||
local arch = os.arch
|
||||
local kern = nil
|
||||
|
||||
if arch == 'aarch64' then
|
||||
kern = cargo {
|
||||
'obkrnl',
|
||||
toolchain = 'nightly',
|
||||
target = 'aarch64-unknown-none-softfloat',
|
||||
release = args['release'],
|
||||
args = {'-Z', 'build-std=core,alloc'}
|
||||
}
|
||||
elseif arch == 'x86_64' then
|
||||
kern = cargo {
|
||||
'obkrnl',
|
||||
target = 'x86_64-unknown-none',
|
||||
release = args['release']
|
||||
}
|
||||
else
|
||||
error(string.format('architecture %s is not supported', arch))
|
||||
end
|
||||
|
||||
-- Build GUI.
|
||||
local gui = cargo {
|
||||
'gui',
|
||||
release = args['release'],
|
||||
args = {'--bin', 'obliteration'}
|
||||
}
|
||||
|
||||
-- Create output directory.
|
||||
local dest = args['root']
|
||||
|
||||
if not dest then
|
||||
dest = 'dist'
|
||||
|
||||
os.removedir(dest)
|
||||
os.createdir(dest)
|
||||
end
|
||||
|
||||
-- Export artifacts.
|
||||
local kind = os.kind
|
||||
local start = nil
|
||||
|
||||
if kind == 'linux' then
|
||||
-- Create directories.
|
||||
local bin = path.join(dest, 'bin')
|
||||
local share = path.join(dest, 'share')
|
||||
|
||||
os.createdir(bin)
|
||||
os.createdir(share)
|
||||
|
||||
-- Export files.
|
||||
start = path.join(bin, path.basename(gui.executable))
|
||||
|
||||
os.copyfile(kern.executable, share)
|
||||
os.copyfileas(gui.executable, start, 'all')
|
||||
elseif kind == 'macos' then
|
||||
-- Create directories.
|
||||
local bundle = path.join(dest, 'Obliteration.app')
|
||||
local contents = path.join(bundle, 'Contents')
|
||||
local macos = path.join(contents, 'MacOS')
|
||||
local resources = path.join(contents, 'Resources')
|
||||
|
||||
os.createdir(bundle)
|
||||
os.createdir(contents)
|
||||
os.createdir(macos)
|
||||
os.createdir(resources)
|
||||
|
||||
-- Export files.
|
||||
local name = path.basename(gui.executable)
|
||||
|
||||
name = string.capitalize(name)
|
||||
start = path.join(macos, name)
|
||||
|
||||
os.copyfile(kern.executable, resources)
|
||||
os.copyfileas(gui.executable, start, 'all')
|
||||
os.copyfileas('bundle.icns', path.join(resources, 'obliteration.icns'))
|
||||
os.copyfile('Info.plist', contents)
|
||||
|
||||
-- Sign bundle.
|
||||
os.run('codesign', '-s', '-', '--entitlements', 'entitlements.plist', bundle)
|
||||
elseif kind == 'windows' then
|
||||
-- Create share directory.
|
||||
local share = path.join(dest, 'share')
|
||||
|
||||
os.createdir(share)
|
||||
|
||||
-- Export files.
|
||||
start = path.join(dest, path.basename(gui.executable))
|
||||
|
||||
os.copyfile(kern.executable, share)
|
||||
os.copyfileas(gui.executable, start)
|
||||
else
|
||||
error(string.format('%s is not supported', kind))
|
||||
end
|
||||
|
||||
-- Start VMM.
|
||||
local addr = args['debug']
|
||||
|
||||
if addr then
|
||||
os.run(start, '--debug', addr)
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
-- Get kernel target.
|
||||
local arch = os.arch
|
||||
local kt = nil
|
||||
|
||||
if arch == 'aarch64' then
|
||||
kt = 'aarch64-unknown-none-softfloat'
|
||||
elseif arch == 'x86_64' then
|
||||
kt = 'x86_64-unknown-none'
|
||||
else
|
||||
error(string.format('architecture %s is not supported', arch))
|
||||
end
|
||||
|
||||
-- Setup list of packages to lint.
|
||||
local pkgs = {
|
||||
{name = 'bitflag', target = kt},
|
||||
{name = 'config', target = kt},
|
||||
{name = 'krt', target = kt},
|
||||
{name = 'macros'}
|
||||
}
|
||||
|
||||
if arch == 'aarch64' then
|
||||
pkgs[#pkgs + 1] = {name = 'aarch64', target = 'aarch64-unknown-none-softfloat'}
|
||||
elseif arch == 'x86_64' then
|
||||
pkgs[#pkgs + 1] = {name = 'hv'}
|
||||
pkgs[#pkgs + 1] = {name = 'obkrnl', target = 'x86_64-unknown-none'}
|
||||
pkgs[#pkgs + 1] = {name = 'x86-64', target = 'x86_64-unknown-none'}
|
||||
end
|
||||
|
||||
for i = 1, #pkgs do
|
||||
-- Build arguments.
|
||||
local pkg = pkgs[i]
|
||||
local args = {'clippy', '--package', pkg.name, '--no-deps'}
|
||||
local val = pkg.target
|
||||
|
||||
if val then
|
||||
args[#args + 1] = '--target'
|
||||
args[#args + 1] = val
|
||||
end
|
||||
|
||||
args[#args + 1] = '--'
|
||||
args[#args + 1] = '-D'
|
||||
args[#args + 1] = 'warnings'
|
||||
|
||||
-- Run clippy.
|
||||
os.run('cargo', table.unpack(args))
|
||||
end
|
||||
Reference in New Issue
Block a user