Skip to content

Commit 9e911d8

Browse files
committed
test
0 parents  commit 9e911d8

File tree

5 files changed

+215
-0
lines changed

5 files changed

+215
-0
lines changed

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: "Test"
2+
on:
3+
pull_request:
4+
push:
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2.3.4
10+
- uses: cachix/install-nix-action@v13
11+
with:
12+
nix_path: nixpkgs=channel:nixos-unstable
13+
- uses: cachix/cachix-action@v9
14+
with:
15+
name: soha
16+
# If you chose API tokens for write access OR if you have a private cache
17+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
18+
- run: nix-build
19+
- run: nix-shell --run "echo OK"

default.nix

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{ nixpkgs ? import <nixpkgs> {} }: with nixpkgs;
2+
let
3+
gcc = (callPackage ./gcc-luogu {}).gcc;
4+
5+
kotlin-native = callPackage ./kotlin-native {};
6+
7+
python3 = python39.withPackages(p: with p; [
8+
numpy
9+
]);
10+
11+
python2 = python27.withPackages(p: with p; [
12+
numpy
13+
]);
14+
15+
pypy2 = pypy;
16+
in {
17+
# C, C++
18+
inherit gcc;
19+
20+
# Rust
21+
inherit rustc;
22+
23+
# Haskell
24+
inherit ghc;
25+
26+
# Pascal
27+
inherit fpc;
28+
29+
# Ruby
30+
inherit ruby;
31+
32+
# PHP
33+
inherit php80;
34+
35+
# Perl
36+
inherit perl;
37+
38+
# Python 3
39+
inherit python3;
40+
inherit pypy3;
41+
42+
# Python 2
43+
inherit python2;
44+
inherit pypy2;
45+
46+
# C#, F#, Visual Basic
47+
inherit mono;
48+
49+
# Java
50+
inherit jdk8;
51+
52+
# OCaml
53+
inherit ocaml;
54+
55+
# # Julia
56+
# inherit julia;
57+
58+
# Lua
59+
inherit lua;
60+
61+
# Scala
62+
inherit scala;
63+
64+
# Golang
65+
inherit go;
66+
67+
# Node.js
68+
inherit nodejs;
69+
70+
# Kotlin/JVM
71+
inherit kotlin;
72+
73+
# Kotlin/Native
74+
inherit kotlin-native;
75+
}

gcc-luogu/default.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{ pkgs ? import <nixpkgs> {} }: with pkgs;
2+
let
3+
pname = "luogu-gcc";
4+
sourceCC = gcc11.cc;
5+
6+
cc = sourceCC.overrideAttrs(a: with a; {
7+
inherit pname;
8+
patches = patches ++ [
9+
./disable-pragma-and-attribute-for-optimize.patch
10+
];
11+
});
12+
gcc = wrapCC(cc);
13+
in {
14+
inherit gcc;
15+
inherit cc;
16+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
From 4f0e2a7a2a1a8a59915ea1d1838ca1a8ac86e01e Mon Sep 17 00:00:00 2001
2+
From: Soha Jin <soha@lohu.info>
3+
Date: Thu, 1 Jul 2021 16:47:12 +0800
4+
Subject: [PATCH] disable optimize pragmas and attributes in ONLINE_JUDGE environment
5+
6+
---
7+
gcc/c-family/c-attribs.c | 6 ++++++
8+
gcc/c-family/c-pragma.c | 6 ++++++
9+
2 files changed, 12 insertions(+)
10+
11+
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
12+
index cdf89d66f..9551c0bcc 100644
13+
--- a/gcc/c-family/c-attribs.c
14+
+++ b/gcc/c-family/c-attribs.c
15+
@@ -5336,6 +5336,12 @@ static tree
16+
handle_optimize_attribute (tree *node, tree name, tree args,
17+
int ARG_UNUSED (flags), bool *no_add_attrs)
18+
{
19+
+ if (getenv("ONLINE_JUDGE"))
20+
+ {
21+
+ error_at (DECL_SOURCE_LOCATION (*node), "%qE attribute is disallowed in online judge mode", name);
22+
+ return NULL_TREE;
23+
+ }
24+
+
25+
/* Ensure we have a function type. */
26+
if (TREE_CODE (*node) != FUNCTION_DECL)
27+
{
28+
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
29+
index 4f8e8e012..4c203726c 100644
30+
--- a/gcc/c-family/c-pragma.c
31+
+++ b/gcc/c-family/c-pragma.c
32+
@@ -930,6 +930,12 @@ handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
33+
bool close_paren_needed_p = false;
34+
tree optimization_previous_node = optimization_current_node;
35+
36+
+ if (getenv("ONLINE_JUDGE"))
37+
+ {
38+
+ error ("%<#pragma GCC optimize%> is not allowed in online judge mode");
39+
+ return;
40+
+ }
41+
+
42+
if (cfun)
43+
{
44+
error ("%<#pragma GCC optimize%> is not allowed inside functions");
45+
--
46+
2.32.0
47+

kotlin-native/default.nix

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{ pkgs ? import <nixpkgs> {} }: with pkgs;
2+
# The compiler Kotlin/Native is just like a piece of shit
3+
# However this nix file just works on Luogu Judge.
4+
let
5+
pname = "kotlin-native";
6+
version = "1.5.20";
7+
sha256 = "9449219ec9465b14adda1b730ac14ef02da93e9f98219f7303bf70c4c875b7db";
8+
9+
unwrapped = stdenv.mkDerivation {
10+
pname = "${pname}-unwrapped";
11+
inherit version;
12+
13+
src = fetchurl {
14+
url = "https://github.com/JetBrains/kotlin/releases/download/v${version}/kotlin-native-linux-${version}.tar.gz";
15+
inherit sha256;
16+
};
17+
propagatedBuildInputs = [ jre ];
18+
19+
buildPhase = ''
20+
export KONAN_DATA_DIR=$PWD/konan-data
21+
export PATH=$PATH:${jre}/bin:$PWD/build-bin
22+
cp -r bin build-bin
23+
patchShebangs --build build-bin
24+
kotlinc-native -Xcheck-dependencies
25+
rm -r build-bin
26+
'';
27+
installPhase = ''
28+
mkdir -p $out
29+
mv * $out
30+
rm $out/bin/kotlinc # kotlinc will be removed in the future
31+
'';
32+
33+
dontFixup = true;
34+
dontStrip = true;
35+
dontPatchELF = true;
36+
37+
outputHashMode = "recursive";
38+
outputHashAlgo = "sha256";
39+
outputHash = "01kxmkd9vcjl0x4g9ylihz6z426zlm7jk2y5q580zs0prncqrk7x";
40+
};
41+
in stdenv.mkDerivation {
42+
inherit pname;
43+
inherit version;
44+
45+
dontUnpack = true;
46+
buildInputs = [ makeWrapper unwrapped ];
47+
propagatedBuildInputs = [ jre ];
48+
49+
installPhase = ''
50+
mkdir -p $out/bin
51+
for p in $(ls ${unwrapped}/bin/); do
52+
makeWrapper ${unwrapped}/bin/$p $out/bin/$p \
53+
--prefix PATH ":" ${jre}/bin \
54+
--set KONAN_DATA_DIR ${unwrapped}/konan-data \
55+
;
56+
done
57+
'';
58+
}

0 commit comments

Comments
 (0)