c0: init at unstable-2022-10-25

This commit is contained in:
Mario Rodas 2023-04-15 04:20:00 +00:00
parent 30f7e63115
commit 5068ff7d86
3 changed files with 137 additions and 0 deletions

View file

@ -0,0 +1,80 @@
{ lib
, stdenv
, fetchFromBitbucket
, mlton
, pkg-config
, getopt
, boehmgc
, darwin
, libbacktrace
, libpng
, ncurses
, readline
}:
stdenv.mkDerivation rec {
pname = "c0";
version = "unstable-2022-10-25";
src = fetchFromBitbucket {
owner = "c0-lang";
repo = "c0";
rev = "7ef3bc9ca232ec41936e93ec8957051e48cacfba";
sha256 = "sha256-uahF8fOp2ZJE8EhZke46sbPmN0MNHzsLkU4EXkV710U=";
};
patches = [
./use-system-libraries.patch
];
postPatch = ''
substituteInPlace cc0/Makefile \
--replace '$(shell ./get_version.sh)' '${version}'
substituteInPlace cc0/compiler/bin/buildid \
--replace '`../get_version.sh`' '${version}' \
--replace '`date`' '1970-01-01T00:00:00Z' \
--replace '`hostname`' 'nixpkgs'
'' + lib.optionalString stdenv.isDarwin ''
for f in cc0/compiler/bin/coin-o0-support cc0/compiler/bin/cc0-o0-support; do
substituteInPlace $f --replace '$(brew --prefix gnu-getopt)' '${getopt}'
done
'';
preConfigure = ''
cd cc0/
'';
nativeBuildInputs = [
getopt
mlton
pkg-config
] ++ lib.optionals stdenv.isDarwin [ darwin.sigtool ];
buildInputs = [
boehmgc
libbacktrace
libpng
ncurses
readline
];
strictDeps = true;
installFlags = [ "PREFIX=$(out)" ];
postInstall = ''
mkdir -p $out/share/emacs/site-lisp
mv $out/c0-mode/ $out/share/emacs/site-lisp/
'';
meta = with lib; {
description = "A small safe subset of the C programming language, augmented with contracts";
homepage = "https://c0.cs.cmu.edu/";
license = licenses.mit;
maintainers = [ maintainers.marsam ];
platforms = platforms.unix;
# line 1: ../../bin/wrappergen: cannot execute: required file not found
# make[2]: *** [../../lib.mk:83:
broken = stdenv.isLinux;
};
}

View file

@ -0,0 +1,53 @@
Use system libraries
--- a/cc0/Makefile
+++ b/cc0/Makefile
@@ -22,12 +22,12 @@ MLTON_BASIC = mlton $(MLTON_FLAGS) -verbose $(MLTON_VERB) -output
MLTON_NATIVE := mlton -default-ann "redundantMatch error" -default-ann "sequenceNonUnit error"
MLTON_NATIVE += -link-opt "-lpthread -ldl -rdynamic" -cc-opt "-Iinclude" -default-ann "allowFFI true"
MLTON_NATIVE += -cc-opt "-I../externals/"
-MLTON_NATIVE += -link-opt "../externals/readline/libreadline.a ../externals/readline/libhistory.a"
+MLTON_NATIVE += -link-opt "$(shell pkg-config readline --libs)"
MLTON_NATIVE += -link-opt "$(shell pkg-config libpng --libs)"
# libreadline dependencies
ifeq ($(PLATFORM),osx)
-MLTON_NATIVE += -link-opt "-ltermcap"
+MLTON_NATIVE += -link-opt "-lncurses"
else
# (Assuming Linux)
MLTON_NATIVE += -link-opt "-ltinfo"
@@ -122,9 +122,9 @@ endef
$(foreach rt,$(RUNTIMES),$(eval $(call runtime_template,$(rt))))
-c0rt/$(call dllname,c0rt): gc libbacktrace
+c0rt/$(call dllname,c0rt):
-unsafe/$(call dllname,unsafe): gc
+unsafe/$(call dllname,unsafe):
### cc0 - the C0 compiler
@@ -222,7 +222,6 @@ NATIVE_COIN = $(NATIVE_CYMBOL) $(NATIVE_CALLING)
NATIVE_COIN += coin/c0readline.c
COIN_DEPS = $(CC0_DEPS) $(NATIVE_COIN) cymbol/cymbol*.cm cymbol/*.sml cymbol/*.mlb coin/coin*.cm coin/*.sml coin/*.sml
-COIN_DEPS += readline
.PHONY: coin
coin: bin/coin
--- a/cc0/lib.mk
+++ b/cc0/lib.mk
@@ -15,9 +15,9 @@ TARGET = $(call dllname,$(LIBNAME))
endif
# These libs are handled specially by this file
-NATIVELIBS = gc ncurses backtrace
+NATIVELIBS =
C0LIBS = $(filter-out $(NATIVELIBS),$(REQUIRES))
-LIBS = -L$(abspath $(DEPTH)/lib) $(patsubst %,$(DEPTH)/lib/$(call dllname,%),$(C0LIBS))
+LIBS = -L$(abspath $(DEPTH)/lib)
LDFLAGS =
# -fPIC is not supported on Windows and is not necessary there because we link statically

View file

@ -18984,6 +18984,10 @@ with pkgs;
c2ffi = callPackage ../development/tools/misc/c2ffi { }; c2ffi = callPackage ../development/tools/misc/c2ffi { };
c0 = callPackage ../development/compilers/c0 {
stdenv = if stdenv.isDarwin then gccStdenv else stdenv;
};
c3c = callPackage ../development/compilers/c3c { }; c3c = callPackage ../development/compilers/c3c { };
swfmill = callPackage ../tools/video/swfmill { stdenv = gcc10StdenvCompat; }; swfmill = callPackage ../tools/video/swfmill { stdenv = gcc10StdenvCompat; };