Skip to content

Commit

Permalink
Fixed issues with building Sloth
Browse files Browse the repository at this point in the history
- Made Sloth build with Rust stable again
- Made a rust-toolchain file so everyone uses the same version of Rust
- Fixed the GitHub Actions to have LLVM so it can actually build
- Fixed the Nix package to have LLVM so it can actually build
  • Loading branch information
cody-quinn committed Jul 28, 2023
1 parent 60ed283 commit 1555738
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 18 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: rm rust-toolchain.toml
- uses: EmbarkStudios/cargo-deny-action@v1
with:
arguments: --all-features
Expand All @@ -16,18 +24,34 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: rm rust-toolchain.toml
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
toolchain: nightly-2023-06-19
components: clippy, rust-src
- run: cargo clippy --all-features -- --deny warnings
code-format:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: rm rust-toolchain.toml
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
toolchain: nightly-2023-06-19
components: rustfmt, rust-src
- run: cargo fmt -- --check
13 changes: 12 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ jobs:
- macos
rust:
- stable
- nightly
- nightly-2023-06-19
name: Test Rust ${{ matrix.rust }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: rm rust-toolchain.toml
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
- uses: KyleMayes/install-llvm-action@v1
with:
version: "15.0"
- run: cargo test --all-features --no-fail-fast
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [ "sloth" ]

[workspace.package]
Expand Down
27 changes: 18 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@
rustc = rustStable;
};
in
let
baseNativeBuildInputs = with pkgs; [ pkg-config ];
baseBuildInputs = with pkgs; [
llvmPackages_15.libllvm
libffi
libxml2
];
in
with pkgs;
{
packages.default = rustPlatform.buildRustPackage rec {
packages.default = rustPlatform.buildRustPackage {
pname = "sloth";
version = "0.1.0";
src = ./.;
Expand All @@ -40,14 +48,20 @@
lockFile = ./Cargo.lock;
};

nativeBuildInputs = baseNativeBuildInputs;
buildInputs = baseBuildInputs;

meta = with lib; {
description = "The Sloth programming language";
homepage = "https://slothlang.tech";
license = with licenses; [ mit asl20 ];
};

LLVM_SYS_150_PREFIX = "${llvmPackages_15.libllvm.dev}";
};
devShells.default = mkShell {
buildInputs = [
nativeBuildInputs = baseNativeBuildInputs;
buildInputs = baseBuildInputs ++ [
(rustNightly.override {
extensions = [ "rust-src" "rust-analyzer" ];
targets = [ "wasm32-unknown-unknown" ];
Expand All @@ -57,16 +71,11 @@
cargo-deny
cargo-release

pkg-config

# Packages required for LLVM
llvmPackages_15.libllvm
libffi
libxml2

# C compiler for debugging
clang
];

RUST_BACKTRACE = 1;
};
}
);
Expand Down
5 changes: 4 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[toolchain]
channel = "nightly-2023-06-15"
channel = "nightly-2023-06-19"
components = [ "rust-src", "rust-analyzer" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "default"
22 changes: 18 additions & 4 deletions sloth/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,26 @@ pub fn analyze(root: &mut Stmt) -> Result<(), AnalysisError> {
}

fn check_usage(node: &AstNode) -> Result<(), AnalysisError> {
if let AstNode::Expr(expr) = node && let ExprKind::Identifier(identifier) = &expr.kind && !expr.symtable.clone().contains(identifier) {
return Err(AnalysisError::UnknownIdentifier(expr.line, identifier.clone()));
if let AstNode::Expr(expr) = node {
if let ExprKind::Identifier(identifier) = &expr.kind {
if !expr.symtable.clone().contains(identifier) {
return Err(AnalysisError::UnknownIdentifier(
expr.line,
identifier.clone(),
));
}
}
}

if let AstNode::Stmt(stmt) = node && let StmtKind::AssignVariable { identifier, .. } = &stmt.kind && !stmt.symtable.clone().contains(identifier) {
return Err(AnalysisError::UnknownIdentifier(stmt.line, identifier.clone()));
if let AstNode::Stmt(stmt) = node {
if let StmtKind::AssignVariable { identifier, .. } = &stmt.kind {
if !stmt.symtable.clone().contains(identifier) {
return Err(AnalysisError::UnknownIdentifier(
stmt.line,
identifier.clone(),
));
}
}
}

for child in node.children() {
Expand Down
1 change: 0 additions & 1 deletion sloth/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(let_chains)]
#![warn(
clippy::wildcard_imports,
clippy::string_add,
Expand Down

0 comments on commit 1555738

Please sign in to comment.