Skip to content

Commit

Permalink
add DLL build workflow #2
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Jan 14, 2022
1 parent e54cc03 commit 8e603c2
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 69 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
matrix:
os:
- ubuntu-latest
- macOS-latest
##- macOS-latest
- windows-latest
raku-version:
- 'latest'
- '2020.05.1'
##- '2021.08'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand All @@ -31,11 +31,18 @@ jobs:
choco install make
choco install mingw
refreshenv
make -f Makefile.mingw dll # build distribution dll
- name: Install Dependencies
run: |
zef install --/test App::Prove6
zef install --/test LibraryMake
zef install --deps-only .
zef build .
- name: Run Tests
run: prove6 -I. t
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Automated Windows DLL save
commit_user_name: David Warring
commit_user_email: [email protected]
file_pattern: resources/libraries/base64.dll
add_options: -f
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
*.gcov
*.gcda
*.gcno
*.obj
Makefile
blib/
51 changes: 14 additions & 37 deletions Build.pm6
Original file line number Diff line number Diff line change
@@ -1,51 +1,28 @@
#! /usr/bin/env perl6
#Note `zef build .` will run this script
use v6;

class Build {
need LibraryMake;
# adapted from deprecated Native::Resources

#| Sets up a C<Makefile> and runs C<make>. C<$folder> should be
#| C<"$folder/resources/libraries"> and C<$libname> should be the name of the library
#| without any prefixes or extensions.
sub make(Str $folder, Str $destfolder, IO() :$libname!) {
my %vars = LibraryMake::get-vars($destfolder);
%vars<LIB_BASE> = $libname;
%vars<LIB_NAME> = ~ $*VM.platform-library-name($libname);
mkdir($destfolder);
LibraryMake::process-makefile($folder, %vars);
my $proc = shell(%vars<MAKE>);
if $proc.exitcode && Rakudo::Internals.IS-WIN {
#issue #1
%vars<MAKE> = 'make';
%vars<CC> = 'gcc';
%vars<CCFLAGS> = '-fPIC -O3 -DNDEBUG --std=gnu99 -Wextra -Wall';
%vars<LD> = 'gcc';
%vars<LDSHARED> = '-shared';
%vars<LDFLAGS> = '-fPIC -O3';
%vars<CCOUT> = '-o ';
%vars<LDOUT> = '-o ';
for <make gmake> -> $maker {
note "retrying build with gcc/{$maker}...";
%vars<MAKE> = $maker;
LibraryMake::process-makefile($folder, %vars);
$proc = shell(%vars<MAKE>);
last unless $proc.exitcode;
}
}
}
use Native::Compile;

method build($workdir) {
method build($dir, Bool :$make = ! $*DISTRO.is-win) {
my $destdir = 'resources/libraries';
mkdir 'resources';
mkdir $destdir;
make($workdir, $destdir, :libname<base64>);
my $libname = 'base64';
my $path = ($destdir ~ '/' ~ $libname).IO;
my $target = $*VM.platform-library-name($path);
if !$make && $target.IO.e {
# to allow distribution of precompiled binaries
note "using prebuilt library: $target";
}
else {
build :$dir, :lib<base64>, :src<src/base64.c>;
}
True;
}
}

# Build.pm can also be run standalone
sub MAIN(Str $working-directory = '.' ) {
Build.new.build($working-directory);
sub MAIN(Str $working-directory = '.', Bool :$make = ! $*DISTRO.is-win ) {
Build.new.build($working-directory, :$make);
}
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Revision history for Base64-Native

{{$NEXT}}
- Switch from Library::Make to Native::Compile. Avoid compilation
on Windows; use prebuilt DLL binary.

0.0.6 2022-01-12T11:12:14+13:00
- Further refined build fallback to try make, then gmake
Expand Down
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build-depends": [
],
"depends": [
"LibraryMake"
"Native::Compile"
],
"description": "Fast Base 64 encoding and decoding (eager)",
"license": "Artistic-2.0",
Expand Down
27 changes: 0 additions & 27 deletions Makefile.in

This file was deleted.

13 changes: 13 additions & 0 deletions Makefile.mingw
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# used on github actions to build a DLL for distribution
DIR=src
SRC=$(DIR)/base64
TGT=resources/libraries/base64.dll

dll : $(TGT)

$(TGT) : $(SRC).obj
gcc -shared -fPIC -O3 -DNDEBUG -Wl,-rpath,"//home/david/git/rakudo/install/lib" -o $(TGT) $(SRC).obj

$(SRC).obj : $(SRC).c $(SRC).h
gcc -I $(DIR) -c -fPIC -std=gnu99 -Wextra -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Werror=pointer-arith -Werror=vla -O3 -DNDEBUG -D_REENTRANT -D_FILE_OFFSET_BITS=64 -fPIC -DWSL_BASH_ON_WIN -DMVM_HEAPSNAPSHOT_FORMAT=2 -D_GNU_SOURCE -o $(SRC).obj $(SRC).c

Binary file added resources/libraries/base64.dll
Binary file not shown.
Binary file added resources/libraries/libbase64.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion src/base64.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ** Base64 encoding / decoding
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -72,7 +73,7 @@ base64_encode_tail (const char *b64_enc_table,
uint8_t out_tail[4];
uint8_t i;

base64_encode_blocks (b64_enc_std, in_tail, 1, out_tail);
base64_encode_blocks (b64_enc_table, in_tail, 1, out_tail);
/* Pad */
if (inlen < 2) {
out_tail[2] = PADDING;
Expand Down

0 comments on commit 8e603c2

Please sign in to comment.