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

Fix bug #17

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: go get github.com/keller-mark/esbuild-py

- name: Build wheels
uses: pypa/cibuildwheel@v2.17.0
uses: pypa/cibuildwheel@v2.21.1
env:
CIBW_BEFORE_ALL_LINUX: ./scripts/cibw_linux_before_all.sh
CIBW_ENVIRONMENT_LINUX: PATH=$PATH:/usr/local/go/bin:/go/bin
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on: [push, pull_request]

jobs:
test_python:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
version: ['3.7', '3.11']
version: ['3.8', '3.12']
# macos-13 is an intel runner, macos-14 is apple silicon
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
steps:
- uses: actions/checkout@v3
- name: Set up Go 1.x
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.so
*.dylib
*.wasm
*.wat

# Test binary, built with `go test -c`
*.test
Expand All @@ -22,4 +23,7 @@ __pycache__/
build/
*.egg-info/
dist/
.pytest_cache/
.pytest_cache/
.pyodide-xbuildenv/
.venv-pyodide/
emsdk/
16 changes: 11 additions & 5 deletions esbuild_bindings.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"C"

"github.com/evanw/esbuild/pkg/api"
)
/*
#include <stdlib.h>
*/
import "C"
import "unsafe"
import "github.com/evanw/esbuild/pkg/api"

//export transform
func transform(jsx *C.char) *C.char {
Expand All @@ -16,4 +17,9 @@ func transform(jsx *C.char) *C.char {
return C.CString(resultStr)
}

//export free_mem
func free_mem(ptr *C.char) {
C.free(unsafe.Pointer(ptr))
}

func main() {}
11 changes: 8 additions & 3 deletions src/esbuild_py/esbuild.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ctypes
from distutils.sysconfig import get_config_var
from pathlib import Path
from sys import platform
import os
import site

Expand Down Expand Up @@ -31,14 +32,18 @@ def get_lib_path():
transform_binding = so.transform
transform_binding.argtypes = [ctypes.c_char_p]
transform_binding.restype = ctypes.c_void_p
free = so.free
free.argtypes = [ctypes.c_void_p]
try:
free_mem_binding = so.free_mem
free_mem_binding.argtypes = [ctypes.c_void_p]
except AttributeError:
free_mem_binding = None

# Wrap the bound go function.
def transform(jsx):
res = transform_binding(jsx.encode('utf-8'))
if res is not None:
msg = ctypes.string_at(res).decode('utf-8')
free(res)
if free_mem_binding is not None:
free_mem_binding(res)
return msg

Loading