Skip to content

[pr] Drift inception #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Google
# This defaults to 'Auto'. Explicitly set it for a while, so that
# 'vector<vector<int> >' in existing files gets formatted to
# 'vector<vector<int>>'. ('Auto' means that clang-format will only use
# 'int>>' if the file already contains at least one such instance.)
Standard: Cpp11
SortIncludes: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BreakStringLiterals: false
DerivePointerAlignment: true
PointerAlignment: Left
ColumnLimit: 100
ForEachMacros: ['list_for_every_entry','list_for_every_entry_safe']
IncludeBlocks: Regroup
IncludeCategories:
# This specific header must come last in kernel source files. Its
# matching rule must come first so the lower-priority rules don't match.
- Regex: '^<ktl/enforce\.h>'
Priority: 1000
# C Header: <foo.h>, <net/foo.h>, etc
- Regex: '^(<((zircon/|lib/|fuchsia/|arpa/|net/|netinet/|sys/|fidl/)[a-zA-Z0-9_/\.-]+\.h|[a-zA-Z0-9_-]+\.h)>)'
Priority: 1
# Cpp Header: <foo> and <experimental/foo>
- Regex: '^(<(experimental/)*[a-zA-Z0-9_-]+>)'
Priority: 2
# Libraries: <foo/bar.h>
- Regex: '^(<[a-zA-Z0-9_/-]+\.h>)'
Priority: 3
# Local headers: "foo/bar.h"
- Regex: '^("[.a-zA-Z0-9_/-]+\.h")'
Priority: 4
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file defines indentation style for the Drift tree in a format usable by many editors.
# For more information on the format and supported editors, see https://editorconfig.org.

[*]
indent_style = space
indent_size = 2

[*.{py}]
indent_size = 4
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Auto detect text files and perform LF normalization.
* text=auto

# Always perform LF normalization on these files.
*.c text
*.cc text
*.cpp text
*.h text
*.md text
*.zig text

# Don't treat SVG as text.
*.svg -diff

41 changes: 41 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI
on:
push:
paths-ignore:
- "README.md"
- "**.md"
- "LICENSE**"
pull_request:
paths-ignore:
- "README.md"
- "**.md"
- "LICENSE**"
jobs:
x86_64-linux:
runs-on: ubuntu-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
sudo apt install xz-utils
sudo sh -c 'wget -c https://pkg.machengine.org/zig/zig-x86_64-linux-0.14.1.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: build
run: zig build
x86_64-macos:
runs-on: macos-13
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
brew install xz
sudo sh -c 'wget -c https://pkg.machengine.org/zig/zig-x86_64-macos-0.14.1.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: build
run: zig build
143 changes: 143 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
### General file patterns
*~
.*.sw?
.build_lock
.cargo
.clangd
**/.cache/clangd
.checkstyle
.classpath
.config
.ccls-cache
.envrc
.flutter_tool_state
.cproject
.DS_Store
.gdb_history
.gdbinit
.jiri_manifest
.landmines
.local
.packages
.project
.pydevproject
.ssh
.vscode
.zig-cache
*_BACKUP_*
*_REMOTE_*
*_LOCAL_*
*_BASE_*
*.dSYM
*.fxt
*.iml
*.orig
*.pyc
*.code-workspace
!drift.code-workspace
*.sublime-project
*.sublime-workspace
*.swp
*.swo
Cargo.lock
!/third_party/rust_crates/**/Cargo.lock
Cargo.toml
!/third_party/rust_crates/**/Cargo.toml
CMakeLists.txt
compile_commands.json
cmake-build-debug/
cscope.*
default.profraw
rls*.log
Session.vim
fidl-tags
tags
TAGS
Thumbs.db
tmp/
!/third_party/rust_crates/vendor/**/tmp/
json_generator_tests_*.txt
tables_generator_tests_*.txt

### fx configuration and cache files.
# NOTE: For any new files, please write files under the top-level .fx/ directory
# instead of adding new top-level files, to avoid cluttering this .gitignore
# file and the top level of local checkouts.
/.fx/
!/.fx/config/README.md
.fx-build-dir
.fx-metrics-config
.fx-multi-list
.fx-remote-config
.fx-ssh-path
.fx-sync-from-stem.cache

### Checkout generated files
/build/cipd.gni

### Infra files
# These files may exist in a checkout on an Infra VM but not locally
/.GUARD_FILE

### Directories to be ignored across the tree
.cipd/
.idea/

### Top-level directories
/.jiri/
/.jiri_root/
/integration/
# For storing local scripts and data files in a source tree.
/local/
/out/
/prebuilt/
/test_data/
/zig-out/

# Third party repos.
/third_party/*

/tmp/
/vendor/
/build/secondary/third_party/ffmpeg
/build/secondary/third_party/protobuf
# Checkouts for some release operations include the infra recipes repository.
/infra/recipes/

# rust-analyzer
/rust-project.json

# Generated config for Python analysis
/pyrightconfig.base.json

# Symlinks related to the Bazel workspace
/bazel-bin
/bazel-out
/bazel-repos
/bazel-workspace

# Symlinks created by `fx setup-go`.
/go.mod
/go.sum

# Running `fx check-licenses` will generate a NOTICE file at the root of the fuchsia repository. The
# file represents the license state of the entire repository.
# We automatically run this command during some user/userdebug builds, so it can be included in the
# Fuchsia images.
/NOTICE.html
/NOTICE.html.gz

# Remote build logs
compiler_info_cache*
reproxy-gomaip.cache*

# Local test coverage file.
lcov.info
.coverage

# Mypy Type Checker extension
/.mypy_cache

# Nix shell
/shell.nix
/default.nix
8 changes: 8 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is the list of Drift Authors.

# Names should be added to this file as one of
# Organization's name
# Individual's name <submission email address>
# Individual's name <submission email address> <email2> <emailN>

Mist Tecnologia LTDA.
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright 2025 The Drift Authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# drift

## Introduction

Drift is a 64-bit kernel written in Zig.
19 changes: 19 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Copyright 2025 The Drift Authors. All rights reserved.
//! Use of this source code is governed by a BSD-style license that can be
//! found in the LICENSE file.

const std = @import("std");
const Build = std.Build;

const cfg = @import("drift/build_config");

pub fn build(b: *Build) void {
const arch = b.option(
cfg.BuildConfig.TargetArch,
"target_cpu",
"Target CPU architecture",
) orelse .x64;

const slipstream = b.dependency("slipstream", .{ .target_cpu = arch });
b.installArtifact(slipstream.artifact("slipstream.elf"));
}
14 changes: 14 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.{
.name = .drift,
.fingerprint = 0x486fc72cc284405b,
.version = "0.0.1",
.paths = .{""},
.dependencies = .{
.slipstream = .{
.path = "slipstream",
},
.@"drift/build_config" = .{
.path = "build",
},
},
}
14 changes: 14 additions & 0 deletions build/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Copyright 2025 The Drift Authors. All rights reserved.
//! Use of this source code is governed by a BSD-style license that can be
//! found in the LICENSE file.

const std = @import("std");
const Build = std.Build;

pub const BuildConfig = @import("config/BuildConfig.zig");

pub fn build(b: *Build) void {
_ = b.addModule("build_config", .{
.root_source_file = b.path("build.zig"),
});
}
60 changes: 60 additions & 0 deletions build/config/BuildConfig.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Copyright 2025 The Drift Authors. All rights reserved.
//! Use of this source code is governed by a BSD-style license that can be
//! found in the LICENSE file.

const std = @import("std");
const Build = std.Build;
const BuildConfig = @This();
const CompilationMode = @import("CompilationMode.zig");

/// Shared state among all BuildConfig instances.
build: *Build,
target_cpu: TargetArch,
compilation_mode: *CompilationMode,

pub const TargetArch = enum {
x64,
arm64,
riscv64,

pub fn fromStd(arch: std.Target.Cpu.Arch) @This() {
return switch (arch) {
.x86_64 => .x64,
.aarch64 => .arm64,
.riscv64 => .riscv64,
};
}

pub fn toStd(self: @This()) std.Target.Cpu.Arch {
return switch (self) {
.x64 => .x86_64,
.arm64 => .aarch64,
.riscv64 => .riscv64,
};
}

pub fn toStr(self: @This()) []const u8 {
return switch (self) {
.x64 => "x64",
.arm64 => "arm64",
.riscv64 => "riscv64",
};
}
};

pub fn init(b: *std.Build) error{OutOfMemory}!*BuildConfig {
const arena = b.allocator;
const bc = try arena.create(BuildConfig);

bc.* = .{
.target_cpu = b.option(
TargetArch,
"target_cpu",
"Target CPU architecture",
) orelse .x64,
.build = b,
.compilation_mode = try CompilationMode.init(b),
};

return bc;
}
Loading
Loading