Skip to content

Commit

Permalink
feat: slim down builtin types
Browse files Browse the repository at this point in the history
  • Loading branch information
axtloss committed May 22, 2024
1 parent e1831a6 commit 60a7d88
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 211 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ jobs:
with:
go-version: 1.21

- name: Build
- name: Build vib
run: |
go get ./...
go build -v -trimpath ./...
make build
- name: Build plugins
run: |
go get ./...
make build-plugins
12 changes: 10 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ jobs:
go-version: 1.21

- name: Build
run: |
Go get ./...
make build
- name: Build plugins
run: |
go get ./...
go build -o vib -trimpath
make build-plugins
tar cvf plugins.tar.xz build/plugins
- name: Upload a Release Asset
if: github.repository == 'Vanilla-OS/Vib'
uses: softprops/action-gh-release@v2
with:
files: vib
files: |
build/vib
plugins.tar.xz
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
example/downloads/*
example/sources/*
test/*
vib
build
docs/website/dist/*
docs/website/node_modules/*
go.work
*~
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.POSIX:

PREFIX=/usr/
DESTDIR=/
BINARY_NAME=vib

all: build # plugins

build:
mkdir -p build
sed 's|$$INSTALLPREFIX$$|${PREFIX}|g' core/plugins.in > core/plugins.go
go build -a -o build/${BINARY_NAME}

plugins: FORCE
mkdir -p build/plugins
$(MAKE) -C plugins/

install:
install -Dm755 -t ${DESTDIR}/${PREFIX}/bin/ ./${BINARY_NAME}

install-plugins:
install -Dm644 -t ${DESTDIR}/${PREFIX}/share/vib/plugins/ ./build/plugins/*.so

clean:
rm -r build
rm core/plugins.go

FORCE:
10 changes: 1 addition & 9 deletions core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,8 @@ func BuildModule(recipe *api.Recipe, moduleInterface interface{}) (string, error
}

moduleBuilders := map[string]func(interface{}, *api.Recipe) (string, error){
"apt": BuildAptModule,
"dnf": BuildDnfModule,
"cmake": BuildCMakeModule,
"dpkg": BuildDpkgModule,
"dpkg-buildpackage": BuildDpkgBuildPkgModule,
"go": BuildGoModule,
"make": BuildMakeModule,
"meson": BuildMesonModule,
"shell": BuildShellModule,
"includes": func(interface{}, *api.Recipe) (string, error) { return "", nil },
"includes": func(interface{}, *api.Recipe) (string, error) { return "", nil },
}

if moduleBuilder, ok := moduleBuilders[module.Type]; ok {
Expand Down
71 changes: 0 additions & 71 deletions core/dnf.go

This file was deleted.

38 changes: 0 additions & 38 deletions core/dpkg.go

This file was deleted.

31 changes: 0 additions & 31 deletions core/make.go

This file was deleted.

22 changes: 19 additions & 3 deletions core/plugins.go → core/plugins.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ebitengine/purego"
"github.com/vanilla-os/vib/api"
)
import "os"

var openedPlugins map[string]Plugin

Expand All @@ -23,10 +24,25 @@ func LoadPlugin(name string, module interface{}, recipe *api.Recipe) (string, er
fmt.Println("Loading new plugin")
buildModule = Plugin{Name: name}

loadedPlugin, err := purego.Dlopen(fmt.Sprintf("%s/%s.so", recipe.PluginPath, name), purego.RTLD_NOW|purego.RTLD_GLOBAL)
if err != nil {
panic(err)
localPluginPath := fmt.Sprintf("%s/%s.so", recipe.PluginPath, name)

globalPluginPath := fmt.Sprintf("$INSTALLPREFIX$/share/vib/plugins/%s.so", name)

// Prefer local plugins before global ones
var loadedPlugin uintptr
_, err := os.Stat(localPluginPath)
if os.IsNotExist(err) {
loadedPlugin, err = purego.Dlopen(globalPluginPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
if err != nil {
panic(err) // yayyy panics <3
}
} else {
loadedPlugin, err = purego.Dlopen(localPluginPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
if err != nil {
panic(err)
}
}

var buildFunction func(*C.char, *C.char) string
purego.RegisterLibFunc(&buildFunction, loadedPlugin, "BuildModule")
buildModule.BuildFunc = buildFunction
Expand Down
3 changes: 2 additions & 1 deletion core/shell.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package core
package main

import (
"errors"
"strings"
"fmt"

"github.com/mitchellh/mapstructure"
"github.com/vanilla-os/vib/api"
Expand Down
10 changes: 10 additions & 0 deletions plugins/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

.PHONY: all

PLUGS := $(wildcard *.go)
OBJS := $(PLUGS:go=so)

all: $(OBJS)

$(OBJS): %.so: %.go
go build -buildmode=c-shared -a -o ../build/plugins/$@ $<
41 changes: 26 additions & 15 deletions core/apt.go → plugins/apt.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package core
package main

import (
"C"
"bufio"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/mitchellh/mapstructure"

"github.com/vanilla-os/vib/api"
)
import "encoding/json"

type AptModule struct {
Name string `json:"name"`
Expand All @@ -28,11 +27,20 @@ type AptOptions struct {

// BuildAptModule builds a module that installs packages
// using the apt package manager
func BuildAptModule(moduleInterface interface{}, recipe *api.Recipe) (string, error) {
var module AptModule
err := mapstructure.Decode(moduleInterface, &module)
//
//export BuildModule
func BuildModule(moduleInterface *C.char, recipeInterface *C.char) *C.char {
var module *AptModule
var recipe *api.Recipe

err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return "", err
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}

err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}

args := ""
Expand All @@ -55,7 +63,7 @@ func BuildAptModule(moduleInterface interface{}, recipe *api.Recipe) (string, er
packages += pkg + " "
}

return fmt.Sprintf("apt-get install -y %s %s && apt-get clean", args, packages), nil

This comment has been minimized.

Copy link
@lambdaclan

lambdaclan Jun 17, 2024

Contributor

I noticed that the command was reverted to apt instead of apt-get is there a specific reason for this? Is #50 not relevant any more or?

This comment has been minimized.

Copy link
@mirkobrombin

mirkobrombin Jun 17, 2024

Member

I think it was an oversight, I don't think there is a specific reason. I think it's better to bring it back to apt-get

This comment has been minimized.

Copy link
@lambdaclan

lambdaclan Jun 17, 2024

Contributor

Hello Mirko. Thank you for clarifying. I am working on a different task, but I can open a small PR to fix it if necessary. Also, Vib in its current state in main branch does not build successfully:

image

I believe is because the shell.go module under core is using package main instead of package core:

image

You cannot have golang files in one directory with different packages.

After changing it to package core and removing unused fmt import:

image

image

This comment has been minimized.

Copy link
@mirkobrombin

mirkobrombin Jun 17, 2024

Member

That is probably a left over by the old maintainer, I did not test the code after their changes. I can take when I have some more time, I am currently focused on critical issues to reach the stable of orchid.

This comment has been minimized.

Copy link
@axtloss

axtloss Jun 17, 2024

Author Member

yes sorry about this, i had this fixed locally but it appears i forgot to push it.
As for the apt thing, it must've been readded when i rebased remote changes, it can (and should) be reverted to apt-get

This comment has been minimized.

Copy link
@lambdaclan

lambdaclan Jun 18, 2024

Contributor

No problem. For your convenience I have opened a small PR to address the issues discussed above. When you get a chance to review it we can merge it. If any changes are needed just comment in the PR.

#55

Thank you both for your input.

return C.CString(fmt.Sprintf("apt install -y %s %s && apt clean", args, packages))
}

if len(module.Source.Paths) > 0 {
Expand All @@ -66,7 +74,7 @@ func BuildAptModule(moduleInterface interface{}, recipe *api.Recipe) (string, er
packages := ""
file, err := os.Open(instPath)
if err != nil {
return "", err
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
defer file.Close()

Expand All @@ -76,20 +84,23 @@ func BuildAptModule(moduleInterface interface{}, recipe *api.Recipe) (string, er
}

if err := scanner.Err(); err != nil {
return "", err
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}

cmd += fmt.Sprintf("apt install -y %s %s", args, packages)
cmd += fmt.Sprintf("apt-get install -y %s %s", args, packages)

if i != len(module.Source.Paths)-1 {
cmd += "&& "
} else {
cmd += "&& apt clean"
cmd += "&& apt-get clean"
}
}

return cmd, nil
return C.CString(cmd)
}

return "", errors.New("no packages or paths specified")
return C.CString("ERROR: no packages or paths specified")
}

func main() {}

Loading

0 comments on commit 60a7d88

Please sign in to comment.