From c77773a8436f29fb2283da5aed279a59ff11af18 Mon Sep 17 00:00:00 2001 From: Werner Kroneman Date: Wed, 11 Sep 2024 16:37:20 +0200 Subject: [PATCH] Minimal example. --- CMakeLists.txt | 17 +++++++++++++++++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 44 ++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 13 +++++++++++++ module.cppm | 20 ++++++++++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 main.cpp create mode 100644 module.cppm diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b7f8858 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.8) +project(test_project) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_SCAN_FOR_MODULES ON) + +add_executable(modules_test) +target_sources(modules_test + PRIVATE main.cpp + PUBLIC FILE_SET CXX_MODULES FILES module.cppm +) + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..994aa04 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1725930920, + "narHash": "sha256-RVhD9hnlTT2nJzPHlAqrWqCkA7T6CYrP41IoVRkciZM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "44a71ff39c182edaf25a7ace5c9454e7cba2c658", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c2f8f33 --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + + nixConfig.bash-prompt = "[shell $(pwd)]$ "; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; + }; + + outputs = { self, nixpkgs, ... }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + in + { + + formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt; + + packages.x86_64-linux.default = pkgs.llvmPackages_17.libcxxStdenv.mkDerivation { + name = "modules_test"; + src = ./.; + nativeBuildInputs = with pkgs; [ + cmake + llvmPackages_17.clang-tools + ninja + ]; + buildInputs = with pkgs; [ + llvmPackages_17.clang-tools + ]; + configurePhase = '' + cmake . -GNinja + ''; + + buildPhase = '' + ninja modules_test + ''; + + installPhase = '' + ls + mkdir -p $out/bin + cp modules_test $out/bin + ''; + }; + }; +} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..68a920b --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +// Copyright (c) 2024 University College Roosevelt +// +// All rights reserved. + +// +// Created by werner on 9/11/24. +// + +import Foomod; + +int main() { + return add(1,2); +} \ No newline at end of file diff --git a/module.cppm b/module.cppm new file mode 100644 index 0000000..88788ca --- /dev/null +++ b/module.cppm @@ -0,0 +1,20 @@ +// Copyright (c) 2024 University College Roosevelt +// +// All rights reserved. + +// +// Created by werner on 9/11/24. +// + +module; + +#include + +export module Foomod; + +export int add(int a, int b) { + + std::cout << "Look at me using iostream!" << std::endl; + + return a + b; +}