Skip to content
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

Building lua-tiktoken on Windows #397

Open
pidgeon777 opened this issue Aug 21, 2024 · 7 comments
Open

Building lua-tiktoken on Windows #397

pidgeon777 opened this issue Aug 21, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@pidgeon777
Copy link

This script may be useful, and also implementable on CopilotChat.nvim:

yetone/avante.nvim@83d0676

@gptlang
Copy link
Member

gptlang commented Aug 22, 2024

I will add Windows as a target to the release task in https://github.com/gptlang/lua-tiktoken

@gptlang
Copy link
Member

gptlang commented Aug 22, 2024

We should steal their whole makefile: https://github.com/yetone/avante.nvim/blob/main/Makefile

@gptlang
Copy link
Member

gptlang commented Aug 22, 2024

@deathbeam did you know we can do

build = "make",

in Lazy.nvimto build stuff?

@gptlang
Copy link
Member

gptlang commented Aug 22, 2024

https://github.com/gptlang/lua-tiktoken/releases (got windows down)

@gptlang
Copy link
Member

gptlang commented Aug 22, 2024

I got it working with make 83bce52

Not quite sure what the equivalent is in Windows

@jellydn jellydn added the enhancement New feature or request label Aug 23, 2024
@pidgeon777
Copy link
Author

This file was used by avante.nvim plugin to build the lua-tiktoken on Windows:

Build-LuaTiktoken.ps1:

param (
    [string]$Version = "luajit"
)

$BuildDir = "build"
$BuildFromSource = $true

function Build-FromSource($feature) {
    if (-not (Test-Path $BuildDir)) {
        New-Item -ItemType Directory -Path $BuildDir | Out-Null
    }

    $tempDir = Join-Path $BuildDir "lua-tiktoken-temp"
    git clone --branch v0.2.2 --depth 1 https://github.com/gptlang/lua-tiktoken.git $tempDir

    Push-Location $tempDir
    cargo build --features=$feature
    Pop-Location

    $targetFile = "tiktoken_core.dll"
    Copy-Item (Join-Path $tempDir "target\debug\tiktoken_core.dll") (Join-Path $BuildDir $targetFile)

    Remove-Item -Recurse -Force $tempDir
}

function Main {
    Write-Host "Building for $Version..."
    Build-FromSource $Version
}

# Run the main function
Main

@pidgeon777
Copy link
Author

I tested the build on Windows 11 with this plugin config:

...
build = vim.fn.has("win32") == 1 and "powershell -ExecutionPolicy Bypass -File Build-LuaTiktoken.ps1" or "make"
...

and it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants