Skip to content

Commit

Permalink
Windows support (#33)
Browse files Browse the repository at this point in the history
Add a dll for Windows to the release. I've run the testsuite in
Windows to verify.

Bumped some versions.

Resolves #31
  • Loading branch information
Erikvv authored Jul 19, 2022
1 parent 951e9a0 commit b5346b5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
32 changes: 30 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pipeline {
stage('Go build x64') {
agent {
docker {
image 'golang:1.17.2'
image 'golang:1.18.3-buster'
args "--volume /tmp/gomod:/go/pkg/mod --user root:root"
}
}
Expand Down Expand Up @@ -81,6 +81,33 @@ pipeline {
}
}
}
stage('Go build windows') {
agent {
dockerfile {
dir 'docker/go-docker'
args '--volume /var/run/docker.sock:/var/run/docker.sock --user root:root'
}
}
steps {
script {
// get owner UID of working directory to run commands as that user
def dockerGroupId = sh(script: "stat -c '%g' /var/run/docker.sock", returnStdout: true).trim()
def userId = sh(script: "stat -c '%u' .", returnStdout: true).trim()
// set group id of docker group to that of the host so we may access /var/run/docker.sock
sh "groupmod --gid ${dockerGroupId} docker"
sh "useradd --create-home --gid ${dockerGroupId} --uid ${userId} jenkins"
sh "newgrp docker"

sh 'su jenkins -c "make build-windows"'
stash(name: "build-windows", includes: "build/libuplink-amd64-windows_nt.dll")
}
}
post {
always {
cleanWs()
}
}
}
stage('Release') {
agent {
dockerfile {
Expand All @@ -90,6 +117,7 @@ pipeline {
steps {
unstash "build-x64"
unstash "build-arm64"
unstash "build-windows"
sh "make release.zip"
archiveArtifacts "release.zip"
}
Expand All @@ -102,7 +130,7 @@ pipeline {
stage('Composer') {
agent {
docker {
image 'composer:2.0.11'
image 'composer:2.3.8'
args '--mount type=volume,source=composer-cache2,destination=/root/.composer/cache '
}
}
Expand Down
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ build/libuplink-aarch64-linux.so: tmp/uplink-c
-v $(PWD)/tmp:$(PWD)/tmp \
--workdir $(PWD)/tmp/uplink-c \
-e CGO_ENABLED=1 \
docker.elastic.co/beats-dev/golang-crossbuild:1.17.3-arm \
docker.elastic.co/beats-dev/golang-crossbuild:1.18.3-arm \
--build-cmd "useradd --create-home --uid $(UID) jenkins && chown -R jenkins /go/pkg/mod && su jenkins -c 'PATH=\$$PATH:/go/bin:/usr/local/go/bin make build'" \
-p "linux/arm64"
mkdir -p build
cat ./tmp/uplink-c/.build/libuplink.so > build/libuplink-aarch64-linux.so

build/libuplink-amd64-windows_nt.dll: tmp/uplink-c
docker run --rm \
-v /tmp/gomod:/go/pkg/mod \
-v $(PWD)/tmp:$(PWD)/tmp \
--workdir $(PWD)/tmp/uplink-c \
-e CGO_ENABLED=1 \
docker.elastic.co/beats-dev/golang-crossbuild:1.18.3-main-debian10 \
--build-cmd "useradd --create-home --uid $(UID) jenkins && chown -R jenkins /go/pkg/mod && su jenkins -c 'PATH=\$$PATH:/go/bin:/usr/local/go/bin make build'" \
-p "windows/amd64"
mkdir -p build
cat ./tmp/uplink-c/.build/libuplink.so > build/libuplink-amd64-windows_nt.dll

build/uplink-php.h: tmp/uplink-c/.build/uplink/uplink.h tmp/uplink-c/.build/uplink/uplink_definitions.h
## create C header file
cat ./tmp/uplink-c/.build/uplink/uplink_definitions.h \
Expand All @@ -47,14 +59,17 @@ build/uplink-php.h: tmp/uplink-c/.build/uplink/uplink.h tmp/uplink-c/.build/upli
sed -zi 's/}\n//g' build/uplink-php.h

.PHONY: build
build: build-x64 build-arm64
build: build-x64 build-arm64 build-windows

.PHONY: build-x64
build-x64: build/libuplink-x86_64-linux.so build/uplink-php.h

.PHONY: build-arm64
build-arm64: build/libuplink-aarch64-linux.so build/uplink-php.h

.PHONY: build-windows
build-windows: build/libuplink-amd64-windows_nt.dll build/uplink-php.h

## declared without prerequites just to run it
release.zip:
zip release.zip \
Expand All @@ -63,6 +78,7 @@ release.zip:
Makefile \
README.md \
build/*.so \
build/*.dll \
build/uplink-php.h \
composer.json \
src/**/*.php \
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ Requirements

- Storj API key or Access Grant. Obtain one from the dashboard ([eu1](https://eu1.storj.io/access-grants), [us1](https://us1.storj.io/access-grants), [ap1](https://ap1.storj.io/access-grants))
- PHP >= 7.4
- Linux
- x86-64 or ARM64
- Any of:
- Linux x86-64 with GLIBC >=2.28
- Linux ARM64 with GLIBC >=2.28
- Windows x86-64

Other platforms or older GLIBC versions are possible. You will need to compile [Uplink-C](https://github.com/storj/uplink-c) for the platform and place the shared library in the "build" folder.

Installation
---------
Expand All @@ -38,10 +42,10 @@ composer config repositories.storj/uplink '{
"type": "package",
"package": {
"name": "storj/uplink",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT/Expat",
"dist": {
"url": "https://link.us1.storjshare.io/raw/jxmgbsqc4k2bbhuv27556pcoh7ra/uplink-php-releases/uplink-php-v1.1.0.zip",
"url": "https://link.us1.storjshare.io/raw/jxmgbsqc4k2bbhuv27556pcoh7ra/uplink-php-releases/uplink-php-v1.2.0.zip",
"type": "zip"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion docker/go-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17.2
FROM golang:1.18.3-buster

RUN apt update
RUN apt install -y docker.io
7 changes: 4 additions & 3 deletions src/Uplink.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public static function create(): self
{
$root = realpath(__DIR__ . '/..');

$arch = php_uname('m');
$os = strtolower(php_uname('s'));
$arch = strtolower(php_uname('m'));
$os = str_replace(' ', '_', strtolower(php_uname('s')));
$extension = strpos($os, 'windows') !== false ? 'dll' : 'so';

$ffi = FFI::cdef(
file_get_contents($root . '/build/uplink-php.h'),
"{$root}/build/libuplink-{$arch}-{$os}.so"
"{$root}/build/libuplink-{$arch}-{$os}.{$extension}"
);

return new self($ffi);
Expand Down

0 comments on commit b5346b5

Please sign in to comment.