Skip to content

Commit

Permalink
fix: implement FromLua for Cha instead of AnyUserData
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Nov 14, 2024
1 parent 0048652 commit 309ce00
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 60 deletions.
13 changes: 13 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[env]
MACOSX_DEPLOYMENT_TARGET = "10.11"
JEMALLOC_SYS_WITH_LG_PAGE = "16"

# environment variable for tikv-jemalloc-sys
#
# https://jemalloc.net/jemalloc.3.html#opt.narenas
Expand All @@ -8,3 +11,13 @@
#
# Improve memory efficiency by reducing fragmentation and ensuring all threads allocate from the same pool
JEMALLOC_SYS_WITH_MALLOC_CONF = "narenas:1"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

[target.x86_64-pc-windows-msvc]
linker = "lld-link.exe"

[target.aarch64-pc-windows-msvc]
linker = "lld-link.exe"

16 changes: 2 additions & 14 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ jobs:
rustup toolchain install stable --profile minimal
rustup component add clippy
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ubuntu-latest@debug

- name: Run sccache-cache
- name: Setup sccache
uses: mozilla-actions/[email protected]

- name: Clippy
Expand All @@ -44,13 +38,7 @@ jobs:
rustup toolchain install nightly --profile minimal
rustup component add rustfmt --toolchain nightly
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ubuntu-latest@debug

- name: Run sccache-cache
- name: Setup sccache
uses: mozilla-actions/[email protected]

- name: Rustfmt
Expand Down
46 changes: 11 additions & 35 deletions .github/workflows/draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,20 @@ jobs:
- os: macos-latest
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
steps:
- uses: actions/checkout@v4

- name: Install gcc-aarch64-linux-gnu
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update && sudo apt-get install -yq gcc-aarch64-linux-gnu
echo "JEMALLOC_SYS_WITH_LG_PAGE=16" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Setup Rust toolchain
run: rustup toolchain install stable --profile minimal --target ${{ matrix.target }}

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Run sccache-cache
- name: Setup sccache
uses: mozilla-actions/[email protected]

- name: Build
Expand All @@ -66,27 +60,21 @@ jobs:
- os: windows-latest
target: aarch64-pc-windows-msvc
runs-on: ${{ matrix.os }}
env:
YAZI_GEN_COMPLETIONS: true
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: lld-link.exe
CARGO_TARGET_AARCH64_PC_WINDOWS_MSVC_LINKER: lld-link.exe
steps:
- uses: actions/checkout@v4

- name: Setup Rust toolchain
run: rustup toolchain install stable --profile minimal --target ${{ matrix.target }}

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Run sccache-cache
- name: Setup sccache
uses: mozilla-actions/[email protected]

- name: Build
env:
YAZI_GEN_COMPLETIONS: true
run: |
cargo build -p yazi-cli --release --locked --target ${{ matrix.target }}
cargo build -p yazi-fm --release --locked --target ${{ matrix.target }}
run: cargo build --release --locked --target ${{ matrix.target }}

- name: Pack artifact
if: matrix.os == 'windows-latest'
Expand Down Expand Up @@ -123,13 +111,7 @@ jobs:
- name: Add musl target
run: rustup target add ${{ matrix.target }}

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Run sccache-cache
- name: Setup sccache
uses: mozilla-actions/[email protected]

- name: Build
Expand All @@ -151,13 +133,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.target }}@release

- name: Run sccache-cache
- name: Setup sccache
uses: mozilla-actions/[email protected]

- name: Build
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ jobs:
- name: Setup Rust toolchain
run: rustup toolchain install stable --profile minimal

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: rust
shared-key: ${{ matrix.os }}@debug

- name: Run sccache-cache
- name: Setup sccache
uses: mozilla-actions/[email protected]

- name: Build
Expand Down
1 change: 0 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set -euo pipefail

export ARTIFACT_NAME="yazi-$1"
export YAZI_GEN_COMPLETIONS=1
export MACOSX_DEPLOYMENT_TARGET="10.11"

# Build for the target
cargo build --release --locked --target "$1"
Expand Down
3 changes: 2 additions & 1 deletion yazi-plugin/src/bindings/cha.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{ops::Deref, time::{Duration, SystemTime, UNIX_EPOCH}};

use mlua::{ExternalError, IntoLua, Lua, Table, UserData, UserDataFields, UserDataMethods};
use mlua::{ExternalError, FromLua, IntoLua, Lua, Table, UserData, UserDataFields, UserDataMethods};
use yazi_shared::fs::ChaKind;

use crate::RtRef;

#[derive(Clone, Copy, FromLua)]
pub struct Cha(yazi_shared::fs::Cha);

impl Deref for Cha {
Expand Down
4 changes: 2 additions & 2 deletions yazi-plugin/src/file/file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use mlua::{AnyUserData, Lua, Table, UserDataRef};

use crate::{bindings::Cast, impl_file_fields, impl_file_methods};
use crate::{bindings::{Cast, Cha}, impl_file_fields, impl_file_methods};

pub type FileRef = UserDataRef<yazi_shared::fs::File>;

Expand All @@ -21,7 +21,7 @@ impl File {
lua.create_function(|lua, t: Table| {
Self::cast(lua, yazi_shared::fs::File {
url: t.raw_get::<AnyUserData>("url")?.take()?,
cha: t.raw_get::<AnyUserData>("cha")?.take()?,
cha: *t.raw_get::<Cha>("cha")?,
..Default::default()
})
})?,
Expand Down

0 comments on commit 309ce00

Please sign in to comment.