Skip to content

Commit

Permalink
added make file and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit committed Nov 14, 2023
1 parent aa8e43d commit ecdf9e3
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.so
*.h
out.js
.idea
.idea
/build
102 changes: 102 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
## Platform Makefile
##

VERSION=0.19.5

platform-all:
@$(MAKE) --no-print-directory -j4 \
platform-darwin-arm64 \
platform-darwin-x64 \
platform-freebsd-arm64 \
platform-freebsd-x64 \
platform-linux-arm \
platform-linux-arm64 \
platform-linux-ia32 \
platform-linux-loong64 \
platform-linux-mips64el \
platform-linux-ppc64 \
platform-linux-riscv64 \
platform-linux-s390x \
platform-linux-x64 \
platform-netbsd-x64 \
platform-openbsd-x64 \
platform-sunos-x64 \
platform-wasm \
platform-win32-arm64 \
platform-win32-ia32 \
platform-win32-x64

build-win32:
CGO_ENABLED=0 GOOS="$(GOOS)" GOARCH="$(GOARCH)" go build $(GO_FLAGS) -o "$(BUILDDIR)/package/esbuild.exe" ./esbuild_scss.go
tar -czf "build/$(GOOS)-$(GOARCH)-$(VERSION).tgz" --directory $(BUILDDIR) package

platform-win32-x64:
@$(MAKE) --no-print-directory GOOS=windows GOARCH=amd64 BUILDDIR=build/win32-x64 build-win32

platform-win32-ia32:
@$(MAKE) --no-print-directory GOOS=windows GOARCH=386 BUILDDIR=build/win32-ia32 build-win32

platform-win32-arm64:
@$(MAKE) --no-print-directory GOOS=windows GOARCH=arm64 BUILDDIR=build/win32-arm64 build-win32

build-platform:
@test -n "$(GOOS)" || (echo "The environment variable GOOS must be provided" && false)
@test -n "$(GOARCH)" || (echo "The environment variable GOARCH must be provided" && false)
@test -n "$(BUILDDIR)" || (echo "The environment variable BUILDDIR must be provided" && false)
CGO_ENABLED=0 GOOS="$(GOOS)" GOARCH="$(GOARCH)" go build $(GO_FLAGS) -o "$(BUILDDIR)/package/bin/esbuild" ./esbuild_scss.go
tar -czf "build/$(GOOS)-$(GOARCH)-$(VERSION).tgz" --directory $(BUILDDIR) package

## Define the build targets for each platform.
platform-darwin-x64:
@$(MAKE) --no-print-directory GOOS=darwin GOARCH=amd64 BUILDDIR=build/darwin-x64 build-platform

platform-darwin-arm64:
@$(MAKE) --no-print-directory GOOS=darwin GOARCH=arm64 BUILDDIR=build/darwin-arm64 build-platform

platform-freebsd-x64:
@$(MAKE) --no-print-directory GOOS=freebsd GOARCH=amd64 BUILDDIR=build/freebsd-x64 build-platform

platform-freebsd-arm64:
@$(MAKE) --no-print-directory GOOS=freebsd GOARCH=arm64 BUILDDIR=build/freebsd-arm64 build-platform

platform-netbsd-x64:
@$(MAKE) --no-print-directory GOOS=netbsd GOARCH=amd64 BUILDDIR=build/netbsd-x64 build-platform

platform-openbsd-x64:
@$(MAKE) --no-print-directory GOOS=openbsd GOARCH=amd64 BUILDDIR=build/openbsd-x64 build-platform

platform-linux-x64:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=amd64 BUILDDIR=build/linux-x64 build-platform

platform-linux-ia32:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=386 BUILDDIR=build/linux-ia32 build-platform

platform-linux-arm:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=arm BUILDDIR=build/linux-arm build-platform

platform-linux-arm64:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=arm64 BUILDDIR=build/linux-arm64 build-platform

platform-linux-loong64:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=loong64 BUILDDIR=build/linux-loong64 build-platform

platform-linux-mips64el:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=mips64le BUILDDIR=build/linux-mips64el build-platform

platform-linux-ppc64:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=ppc64le BUILDDIR=build/linux-ppc64 build-platform

platform-linux-riscv64:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=riscv64 BUILDDIR=build/linux-riscv64 build-platform

platform-linux-s390x:
@$(MAKE) --no-print-directory GOOS=linux GOARCH=s390x BUILDDIR=build/linux-s390x build-platform

platform-sunos-x64:
@$(MAKE) --no-print-directory GOOS=illumos GOARCH=amd64 BUILDDIR=build/sunos-x64 build-platform

platform-wasm:
@$(MAKE) --no-print-directory GOOS=js GOARCH=wasm BUILDDIR=build/esbuild-wasm build-platform

clean:
rm -rf build
19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@

## POC to use esbuild with java and plugins
## Scss enabled version of esbuild

This is a poc to see if we can use esbuild in java, but more integrated.
Maybe we can even use esbuild and extend it with Java based plugins.
This project extends esbuild with a scss plugin.
The normal cli still works, but it has a scss plugin added.

### To build

```cmd
go build -o libhello.so -buildmode=c-shared hello.go
chmod -x libhello.so
mvn package
export LD_LIBRARY_PATH=<full path to this folder>
java -jar target/go-helloworld-1.0.0-SNAPSHOT-jar-with-dependencies.jar
make platform-all
```

### TODO
* rename this project to not be called helloworld
* make the go code call java
* create an interface for the java and go communication
This is used by esbuild-java for the quarkus web bundler
36 changes: 36 additions & 0 deletions scss_plugin.go → esbuild_scss.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"time"

"github.com/bep/godartsass/v2"
"github.com/evanw/esbuild/pkg/api"
Expand Down Expand Up @@ -93,5 +96,38 @@ var scssPlugin = api.Plugin{

func main() {
osArgs := os.Args[1:]
for _, arg := range osArgs {
switch {
case arg == "--version":
fmt.Printf("%s\n", "0.19.5")
os.Exit(0)
case arg == "--watch":
go func() {
// This just discards information from stdin because we don't use
// it and we can avoid unnecessarily allocating space for it
buffer := make([]byte, 512)
for {
_, err := os.Stdin.Read(buffer)
if err != nil {

// Only exit cleanly if stdin was closed cleanly
if err == io.EOF {
os.Exit(0)
} else {
os.Exit(1)
}
}

// Some people attempt to keep esbuild's watch mode open by piping
// an infinite stream of data to stdin such as with "< /dev/zero".
// This will make esbuild spin at 100% CPU. To avoid this, put a
// small delay after we read some data from stdin.
time.Sleep(4 * time.Millisecond)
}
}()
osArgs = osArgs[1:]
}

}
os.Exit(cli.RunWithPlugins(osArgs, []api.Plugin{scssPlugin}))
}

0 comments on commit ecdf9e3

Please sign in to comment.