Skip to content
Merged
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
68 changes: 68 additions & 0 deletions .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Build das2C for WebAssembly with buildfiles/emscripten.mak on Ubuntu 24.04
# and run the wasm test programs under node. Regression testing only:
# nothing is uploaded, the wasm archive is not a release file. das2js is
# the downstream that links it into a browser module. release.yml still
# calls this workflow and publishes nothing unless it passes.
#
# The wasm output doesn't depend on the host, so the runner OS only decides
# how the toolchain gets installed. Pinned like ubuntu.yml, so the build
# changes only when this file does.
#
# emsdk is cloned and installed directly rather than through a marketplace
# action, the same steps notes/build_for_emscripten.md gives a developer.
# EMSDK_VER pins emscripten itself; bump it here to move CI to a new
# compiler. emsdk_env.sh sets PATH and EMSDK_NODE for one shell only, so
# every step that needs emcc or node sources it.
#
# Nothing is cached. emscripten.mak downloads and builds expat and FFTW on
# every run, which is what keeps the pinned URLs and SHA-256 sums honest:
# a release that moves or changes upstream fails here first. FFTW is the
# slow part of the run.

name: Emscripten

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
workflow_call:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-24.04

env:
EMSDK_VER: 6.0.13

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v7

- name: Install emsdk
run: |
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$RUNNER_TEMP/emsdk"
cd "$RUNNER_TEMP/emsdk"
./emsdk install "$EMSDK_VER"
./emsdk activate "$EMSDK_VER"

# Separate from the test step, so a failure says whether it was the
# dependency downloads, the compile or the link. -j reaches the expat
# and FFTW builds too, see the expat rule in emscripten.mak.
- name: Build
run: |
source "$RUNNER_TEMP/emsdk/emsdk_env.sh"
emcc --version
make -j"$(nproc)" -f buildfiles/emscripten.mak build_test

- name: Test
run: |
source "$RUNNER_TEMP/emsdk/emsdk_env.sh"
make -f buildfiles/emscripten.mak test
9 changes: 7 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# das2C-<ver>-macos<N>-arm64.tar.gz The same for Apple Silicon
#
# The builds themselves are windows.yml, ubuntu.yml and macos.yml, which
# also run on every push to master.
# also run on every push to master. emscripten.yml runs too, though it
# ships nothing: a release waits on the wasm tests like the others.
# A tag with a '-' in it, such as v3.0-pre8, makes a pre-release. Any other
# tag must match "version-string" in vcpkg.json, so a release can't go out
# with a mismatched version number. Nothing is published unless every build
Expand Down Expand Up @@ -78,8 +79,12 @@ jobs:
with:
version: ${{ needs.check.outputs.version }}

emscripten:
needs: check
uses: ./.github/workflows/emscripten.yml

publish:
needs: [ check, windows, ubuntu, macos ]
needs: [ check, windows, ubuntu, macos, emscripten ]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build.*/
deps.*/
build/
*.obj
buildfiles/nbproject/private
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# cmake --install build.cmake/default --prefix C:\opt
# cmake --build --preset default --target uninstall
#
# On Windows the programs run on das3.dll, as with Windows.mak. Elsewhere
# On Windows the programs run on das3.dll, as with windows.mak. Elsewhere
# they link the static library, use the "dll" preset to add libdas3.so.
# Without presets, pass
# -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%/scripts/buildsystems/vcpkg.cmake, or
Expand Down Expand Up @@ -74,7 +74,7 @@ if(CMAKE_HOST_WIN32 AND CMAKE_GENERATOR MATCHES "Ninja" AND NOT DEFINED CMAKE_C_
endif()

# Static vcpkg dependencies built for the DLL C runtime (/MD) by default on
# Windows, the same as Windows.mak, so they all land in das3.dll. Must be set
# Windows, the same as windows.mak, so they all land in das3.dll. Must be set
# before project(). The C runtime is CMake's default, /MD, except with a
# fully static triplet such as x64-windows-static, see below. Without vcpkg,
# as under conda, /MD matches the dependency DLLs.
Expand All @@ -94,7 +94,7 @@ include(CMakePackageConfigHelpers)

option(DAS_WITH_SPICE "Build the SPICE programs" ON)
option(DAS_WITH_CDF "Build the CDF programs" ON)
# On Windows the programs run on das3.dll, as with Windows.mak, so that the
# On Windows the programs run on das3.dll, as with windows.mak, so that the
# dependencies are in the DLL once instead of in every program. Elsewhere
# they link the static library, as with Linux.mak.
if(WIN32)
Expand Down Expand Up @@ -179,7 +179,7 @@ endif()

# The makefiles keep assert() active in optimized builds and so do we. For
# MSVC also put debug info in the objects (/Z7) so libdas3.lib carries it,
# leave inlining at the /O2 level as Windows.mak does, and skip incremental
# leave inlining at the /O2 level as windows.mak does, and skip incremental
# linking, which leaves 20 MB+ .ilk files. Linking with /debug turns off
# removal of unused code, so optimized builds ask for it back (/OPT).
foreach(_cfg RELEASE RELWITHDEBINFO MINSIZEREL)
Expand Down
28 changes: 15 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ ifeq ($(INST_DOC),)
INST_DOC=$(INST_SHARE)/doc
endif

# Cross compiling to WebAssembly: objects land in build.wasm32 and the
# emscripten rules below replace the host platform's
ifeq ($(EMSCRIPTEN),yes)
N_ARCH=wasm32
endif

ifeq ($(N_ARCH),)
N_ARCH=/
#N_ARCH=$(shell uname).$(shell uname -m)
Expand All @@ -46,10 +40,8 @@ endif

# SPICE and CDF programs are part of the standard build, SPICE=no or CDF=no
# leaves them out (so does any value but "yes").
ifneq ($(EMSCRIPTEN),yes)
SPICE?=yes
CDF?=yes
endif

BLD_CSPICE=0
ifeq ($(SPICE),yes)
Expand Down Expand Up @@ -79,6 +71,11 @@ C_HDR_DIR:=$(CURDIR)
BUILD_DIR:=build.$(N_ARCH)
C_BUILD_DIR:=$(CURDIR)/$(BUILD_DIR)

# Downloaded sources and the dependency builds made from them (CDF, CSPICE).
# Beside the build directory rather than in it, so clean can remove all of
# $(BUILD_DIR) and only distclean costs a re-download.
DEPS_DIR:=deps.$(N_ARCH)

##############################################################################
# Native Platform specific include

Expand All @@ -100,9 +97,14 @@ export INST_NAT_LIB
export C_BUILD_DIR
export C_HDR_DIR

ifeq ($(EMSCRIPTEN),yes)
$(info Cross compiling for wasm32 with emscripten)
include buildfiles/Emscripten.mak
else
# The WebAssembly build is not selected here, use:
#
# make -f buildfiles/emscripten.mak
#
# The windows build is not selected here either, use:
#
# nmake /f buildfiles\windows.mak
# -or-
# cmake --preset default

include buildfiles/$(UNAME).mak
endif
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,16 @@ For a WebAssembly build of the library alone (no utilities), with emscripten's
emsdk activated in the shell:

```bash
$ make EMSCRIPTEN=yes EXPAT_INC=/path/to/expat/lib build
$ make EMSCRIPTEN=yes EXPAT_INC=/path/to/expat/lib EXPAT_LIB=/path/to/libexpat.a test
$ make -f buildfiles/emscripten.mak
$ make -f buildfiles/emscripten.mak test

# To rebuild
$ make -f buildfiles/emscripten.mak clean # Removes only das2C output
$ make -f buildfiles/emscripten.mak distclean # Removes expat and FFTW as well
```

Output lands in `build.wasm32/`. Emscripten provides zlib but not expat, so a
libexpat built for wasm32 has to be supplied. See
[notes/build_for_emscripten.md](notes/build_for_emscripten.md) for the
toolchain setup, what is left out of the archive and why, and how to link
the result into a program of your own.
Output lands in `build.wasm32/`. The build expat and fftw and builds them
for wasm32 under `deps.wasm32/`. See [notes/build_for_emscripten.md](notes/build_for_emscripten.md) for the toolchain setup.

For Windows systems issue the following commands in a command shell to build
and test the software. Dependencies are installed by [vcpkg](https://vcpkg.io)
Expand All @@ -117,8 +118,8 @@ See [notes/build_for_windows.md](notes/build_for_windows.md) for details.
> vcvars64.bat ::puts nmake.exe, cl.exe, link.exe, etc. on your path
> set VCPKG_ROOT= ::location of your vcpkg clone

> nmake /f buildfiles\Windows.mak SPICE=yes CDF=yes
> nmake /f buildfiles\Windows.mak SPICE=yes CDF=yes test
> nmake /f buildfiles\windows.mak
> nmake /f buildfiles\windows.mak test
```

On Windows you can also build with [CMake](https://cmake.org), which Visual
Expand All @@ -128,9 +129,8 @@ tested on Windows so far.

```batchfile
> vcvars64.bat
> set VCPKG_ROOT= ::location of your vcpkg clone

> cmake --preset default ::configure, vcpkg builds the dependencies
> set VCPKG_ROOT= ::location of your vcpkg clone
> cmake --preset default ::configure step, vcpkg builds the dependencies
> cmake --build --preset default
> ctest --preset default
```
Expand All @@ -149,10 +149,10 @@ $ make PREFIX=/usr/local install # adjust destination to taste
```
or on Windows:
```batch
nmake /f buildfiles\Windows.mak PREFIX=C:\local install
nmake /f buildfiles\windows.mak PREFIX=C:\opt install
```
```batch
cmake --install build.cmake\default --prefix C:\local
cmake --install build.cmake\default --prefix C:\opt
```

> **Side note:** a CMake install can be undone with
Expand Down
6 changes: 6 additions & 0 deletions buildfiles/Android.mak
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ TEST_PROGS=TestUnits TestArray TestDs TestBuilder \
TestV3Read TestProp TestIter TestUri TestFilter TestValue TestRaggedEncode \
TestGen TestForm TestCplx TestVar TestVarSubset TestDim TestDatum

# Set by the top level Makefile, which includes this file. Read on its own
# (make -f) every output path would start at /, so refuse.
ifeq ($(BUILD_DIR),)
$(error buildfiles/Android.mak is included by Makefile, run make from the top of the source tree)
endif

BD=$(BUILD_DIR)

##############################################################################
Expand Down
56 changes: 34 additions & 22 deletions buildfiles/Darwin.mak
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
# tools.
#
# CSPICE: From CSPICE_INC and CSPICE_LIB when set, otherwise the NAIF
# toolkit for this machine's architecture is downloaded to $(BD)/cspice
# toolkit for this machine's architecture is downloaded to
# $(DEPS_DIR)/cspice
#
# CDF: From CDF_INC and CDF_LIB when set, otherwise the SPDF source
# distribution is downloaded and built under $(BD)
# distribution is downloaded and built under $(DEPS_DIR)
#
# Only distclean removes $(DEPS_DIR), clean leaves the downloads alone.
#
# Apple's clang honors MACOSX_DEPLOYMENT_TARGET from the environment, set it
# to build for older MacOS versions than the one running the build. Static
Expand All @@ -32,6 +35,12 @@
MD5SUM=md5 -r
export MD5SUM

# Set by the top level Makefile, which includes this file. Read on its own
# (make -f) every output path would start at /, so refuse.
ifeq ($(BUILD_DIR),)
$(error buildfiles/Darwin.mak is included by Makefile, run make from the top of the source tree)
endif

BD=$(BUILD_DIR)

##############################################################################
Expand All @@ -52,8 +61,8 @@ LOC_CDF_ENV:=x86_64
endif

ifeq ($(BLD_CDF),1)
CDF_INC:=$(BD)/$(LOC_CDF_DIST)/src/include
CDF_LIB:=$(BD)/$(LOC_CDF_DIST)/src/lib/libcdf.a
CDF_INC:=$(DEPS_DIR)/$(LOC_CDF_DIST)/src/include
CDF_LIB:=$(DEPS_DIR)/$(LOC_CDF_DIST)/src/lib/libcdf.a
endif

# Downstream packages (das2py) take libcdf.dylib from $(BD) so that they run
Expand All @@ -66,8 +75,8 @@ CDF_SO_REDIST:=$(BD)/libcdf.dylib
endif

ifeq ($(BLD_CSPICE),1)
CSPICE_INC:=./$(BD)/cspice/include
CSPICE_LIB:=./$(BD)/cspice/lib/cspice.a
CSPICE_INC:=./$(DEPS_DIR)/cspice/include
CSPICE_LIB:=./$(DEPS_DIR)/cspice/lib/cspice.a
endif


Expand All @@ -76,7 +85,7 @@ endif

TARG=libdas3

# File lists are shared with Linux.mak and Windows.mak, add new sources there
# File lists are shared with Linux.mak and windows.mak, add new sources there
include buildfiles/sources.mak

SRCS:=$(notdir $(LIB_SRCS))
Expand Down Expand Up @@ -239,6 +248,10 @@ $(BD):
@if [ ! -e "$(BD)" ]; then echo mkdir $(BD); \
mkdir $(BD); chmod g+w $(BD); fi

$(DEPS_DIR):
@if [ ! -e "$(DEPS_DIR)" ]; then echo mkdir $(DEPS_DIR); \
mkdir $(DEPS_DIR); chmod g+w $(DEPS_DIR); fi

# Records which objects make up the library. A source dropped from the list
# changes that set without making any object newer than the archive, so make
# alone would keep a stale one. The file is rewritten only when the set
Expand Down Expand Up @@ -301,8 +314,8 @@ endif

build_dep:$(_DEPS)

$(CSPICE_LIB): $(BD)/cspice.tar
cd $(BD) && tar -mxf cspice.tar
$(CSPICE_LIB): $(DEPS_DIR)/cspice.tar
cd $(DEPS_DIR) && tar -mxf cspice.tar

# Checked on every build, see the same rule in Linux.mak for why
ifeq ($(BLD_CDF),1)
Expand All @@ -321,20 +334,20 @@ $(CDF_SO_REDIST): FORCE | $(BD)
echo "cp $(CDF_SO) $@"; cp "$(CDF_SO)" $@; \
fi

$(BD)/cspice.tar: | $(BD)
curl -f -L $(LOC_CSPICE_URL) > $(BD)/cspice.tar.Z
uncompress $(BD)/cspice.tar.Z
$(DEPS_DIR)/cspice.tar: | $(DEPS_DIR)
curl -f -L $(LOC_CSPICE_URL) > $(DEPS_DIR)/cspice.tar.Z
uncompress $(DEPS_DIR)/cspice.tar.Z

# CDF's own tools need curses, the library does not. Without a full Xcode
# install the CDF makefile prints xcodebuild errors while probing for an Xcode
# version, these are harmless.
$(CDF_LIB): $(BD)/$(LOC_CDF_DIST)
cd $(BUILD_DIR)/$(LOC_CDF_DIST) && $(MAKE) OS=macosx ENV=$(LOC_CDF_ENV) \
$(CDF_LIB): $(DEPS_DIR)/$(LOC_CDF_DIST)
cd $(DEPS_DIR)/$(LOC_CDF_DIST) && $(MAKE) OS=macosx ENV=$(LOC_CDF_ENV) \
CURSES=no FORTRAN=no all

$(BD)/$(LOC_CDF_DIST): | $(BD)
curl -f -L $(LOC_CDF_URL) > $(BD)/$(LOC_CDF_DIST)-cdf.tar.gz
cd $(BD) && tar -xf $(LOC_CDF_DIST)-cdf.tar.gz
$(DEPS_DIR)/$(LOC_CDF_DIST): | $(DEPS_DIR)
curl -f -L $(LOC_CDF_URL) > $(DEPS_DIR)/$(LOC_CDF_DIST)-cdf.tar.gz
cd $(DEPS_DIR) && tar -xf $(LOC_CDF_DIST)-cdf.tar.gz

# Run tests

Expand Down Expand Up @@ -529,13 +542,12 @@ $(INST_DOC)/das2C:$(BD)/html


# Cleanup ####################################################################
distclean:
# Same split as Linux.mak: all of $(BD) is ours, $(DEPS_DIR) costs a re-fetch
clean:
if [ -d "$(BD)" ] ; then rm -r $(BD) ; fi

clean:
-rm $(BD)/das* $(BD)/Test* $(BD)/libdas*
-rm $(BD)/*.o $(BD)/*.d $(BD)/ex*
-rm $(BD)/cred_test*
distclean: clean
if [ -d "$(DEPS_DIR)" ] ; then rm -r $(DEPS_DIR) ; fi


## Automatic dependency tree generation for C code ###########################
Expand Down
Loading
Loading